Use Different PHP version During Composer Install or Update

Leave a Comment
Use following command to specify PHP version.
php7.2 /usr/bin/composer install
OR
php7.2 /usr/bin/composer update
/usr/bin/php7.2 /usr/bin/composer install
OR
/usr/bin/php7.2 /usr/bin/composer update
If you get any error like Could not open input file: composer, then composer excitable location is incorrect. To find exact location use the following command 
which composer
To know php7.2 location use the follwing command
which php7.2

PHP missing extension ext-mbstring during Composer Install or update

Leave a Comment
When you do
composer install
or
composer update
, you may get following error 
phpunit/phpunit 7.5.9 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
Your PHP version missing php-mbstring extension, so please go head and install php-mbstring extension using following command.
sudo apt install php-mbstring

For PHP 7.0

sudo apt install php7.0-mbstring

For PHP 7.1

sudo apt install php7.1-mbstring

For PHP 7.2

sudo apt install php7.2-mbstring

For PHP 7.3

sudo apt install php7.3-mbstring

For PHP 7.4

sudo apt install php7.4-mbstring

PHP missing extension ext-dom during Composer Install

Leave a Comment
When you do
composer install
or
composer update
, you may get following error 
phpunit/phpunit 7.5.9 requires ext-dom * -> the requested PHP extension dom is missing from your system
Your PHP version missing php-xml extension, so please go head and install php-xml extension using following command.
sudo apt install php-xml

For PHP 7.0

sudo apt install php7.0-xml

For PHP 7.1

sudo apt install php7.1-xml

For PHP 7.2

sudo apt install php7.2-xml

For PHP 7.3

sudo apt install php7.3-xml

For PHP 7.4

sudo apt install php7.4-xml

Wordpress Update Failed - Inconsistent file permissions.: wp-admin/includes/update-core.php

Leave a Comment
This is usually because of the user that excuting PHP doesn't have proper execution permission. Please change the owner and the group to the www-data of all the files and folders appearing in the errors during wordpress upgrade.
sudo chown -R www-data:www-data /var/www/html

Get GIT remote url

Leave a Comment
Please use the following command to get remote URL

git config --get remote.origin.url

Step 2:

Open config file in the .git folder in your project folder.
[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
	ignorecase = true
	precomposeunicode = true
[remote "origin"]
	url = ssh://git@github.com:7999/sample.git
	fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
	remote = origin
	merge = refs/heads/master
Where URL is the remote origin url.

Force PHP Guzzle to use IPV4

Leave a Comment
You may be connection timeout error, while making API request via Guzzle. It may caused by following issues. 1. Check your internet connectivity. 2. It may be misconfiguration of IPV6 in your server. So you may need disable IPV6 or set the priority to IPV4. Just follow below tutorial to set priority to IPV4 over IPV6. https://forum.smarttutorials.net/2020/06/checking-http-connectivity-to-packagist-fail-composer-Linux.html Provide following option to Guzzle while making HTTP request.

'force_ip_resolve' => 'v4',

GET Request


<?php
use GuzzleHttp\Client as Guzzle;

$guzzle = new Guzzle();

$res = $guzzle->get($api_url, [
    'http_errors' => false,
    'verify' => false,
    'force_ip_resolve' => 'v4',
    'query' => [
        'user' => 'muni'
    ]
]);

POST Request


<?php
use GuzzleHttp\Client as Guzzle;

$guzzle = new Guzzle();

$guzzle->request('post', $api_url, [
    'http_errors' => false,
    'verify' => false,
    'force_ip_resolve' => 'v4',
    'form_params' => [
        'request_url'  => $url,
        'name' => 'muni'
    ]
]);

The "https://packagist.org/packages.json" file could not be downloaded: failed to open stream: Connection timed out

Leave a Comment
You may face this issue because following issue. 1. Check your internet connectivity 2. If your system is not IPV6 configured properly, then you may get this Connection timed out error.

Linux - Workaround

Here we are setting more prority to IPV4 than IPv6.
sudo sh -c "echo 'precedence ::ffff:0:0/96 100' >> /etc/gai.conf"