Skip to content

Instantly share code, notes, and snippets.

@Alymosul
Last active May 25, 2020 04:08
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save Alymosul/da31c2e1b377b23780db29f21368761d to your computer and use it in GitHub Desktop.
Save Alymosul/da31c2e1b377b23780db29f21368761d to your computer and use it in GitHub Desktop.
Downgrade PHP 7.2 to 7.1 on Laravel Forge

Install php7.1 related stuff..

apt-get install -y --allow-downgrades --allow-remove-essential --allow-change-held-packages \
php7.1-cli php7.1-dev \
php7.1-pgsql php7.1-sqlite3 php7.1-gd \
php7.1-curl php7.1-memcached \
php7.1-imap php7.1-mysql php7.1-mbstring \
php7.1-xml php7.1-zip php7.1-bcmath php7.1-soap \
php7.1-intl php7.1-readline php-xdebug php-pear php7.1-fpm

Switch to php7.1

update-alternatives --set php /usr/bin/php7.2

Set some PHP CLI settings

sudo sed -i "s/error_reporting = .*/error_reporting = E_ALL/" /etc/php/7.1/cli/php.ini
sudo sed -i "s/display_errors = .*/display_errors = On/" /etc/php/7.1/cli/php.ini
sudo sed -i "s/memory_limit = .*/memory_limit = 512M/" /etc/php/7.1/cli/php.ini
sudo sed -i "s/;date.timezone.*/date.timezone = UTC/" /etc/php/7.1/cli/php.ini

Restart Nginx

service nginx restart

Setup some PHP-FPM options

echo "xdebug.remote_enable = 1" >> /etc/php/7.1/mods-available/xdebug.ini
echo "xdebug.remote_connect_back = 1" >> /etc/php/7.1/mods-available/xdebug.ini
echo "xdebug.remote_port = 9000" >> /etc/php/7.1/mods-available/xdebug.ini
echo "xdebug.max_nesting_level = 512" >> /etc/php/7.1/mods-available/xdebug.ini
echo "opcache.revalidate_freq = 0" >> /etc/php/7.1/mods-available/opcache.ini

sed -i "s/error_reporting = .*/error_reporting = E_ALL/" /etc/php/7.1/fpm/php.ini
sed -i "s/display_errors = .*/display_errors = On/" /etc/php/7.1/fpm/php.ini
sed -i "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/" /etc/php/7.1/fpm/php.ini
sed -i "s/memory_limit = .*/memory_limit = 512M/" /etc/php/7.1/fpm/php.ini
sed -i "s/upload_max_filesize = .*/upload_max_filesize = 100M/" /etc/php/7.1/fpm/php.ini
sed -i "s/post_max_size = .*/post_max_size = 100M/" /etc/php/7.1/fpm/php.ini
sed -i "s/;date.timezone.*/date.timezone = UTC/" /etc/php/7.1/fpm/php.ini

printf "[openssl]\n" | tee -a /etc/php/7.1/fpm/php.ini
printf "openssl.cainfo = /etc/ssl/certs/ca-certificates.crt\n" | tee -a /etc/php/7.1/fpm/php.ini

printf "[curl]\n" | tee -a /etc/php/7.1/fpm/php.ini
printf "curl.cainfo = /etc/ssl/certs/ca-certificates.crt\n" | tee -a /etc/php/7.1/fpm/php.ini

Disable XDebug On The CLI

sudo phpdismod -s cli xdebug

Set the PHP-FPM user

sed -i "s/user = www-data/user = forge/" /etc/php/7.1/fpm/pool.d/www.conf
sed -i "s/group = www-data/group = forge/" /etc/php/7.1/fpm/pool.d/www.conf

sed -i "s/listen\.owner.*/listen.owner = forge/" /etc/php/7.1/fpm/pool.d/www.conf
sed -i "s/listen\.group.*/listen.group = forge/" /etc/php/7.1/fpm/pool.d/www.conf
sed -i "s/;listen\.mode.*/listen.mode = 0666/" /etc/php/7.1/fpm/pool.d/www.conf

Restart Nginx & PHP-FPM

service nginx restart
service php7.1-fpm restart

Guide the existing sites to use php7.1 instead of php7.2

1. Navigate to the (php) site through laravel forge [Server--->Sites-->choose a site]
2. Click on the Edit Files at the bottom of the page and choose [Edit Nginx Configuration]
3. Find the following line: fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
4. Change it to: fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
5. Restart the whole server from forge.
@EdnaldoNeimeg
Copy link

EdnaldoNeimeg commented Feb 26, 2018

Switch to php7.1
update-alternatives --set php /usr/bin/php7.2

Don't you mean update-alternatives --set php /usr/bin/php7.1

@ditsbroefs
Copy link

Thanks for this, saved me a ton of hassle!

Copy link

ghost commented Sep 5, 2018

This works like charm with what @EdnaldoNeimeg has pointed out. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment