Skip to content

Instantly share code, notes, and snippets.

@deletosh
Forked from Alymosul/README.md
Last active March 8, 2018 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deletosh/b9bce6aa1be48264bbd474cf80a3fe23 to your computer and use it in GitHub Desktop.
Save deletosh/b9bce6aa1be48264bbd474cf80a3fe23 to your computer and use it in GitHub Desktop.
Downgrade PHP 7.1 to 7.0 on Laravel Forge

Install php7.0 related stuff..

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

Switch to php7.0

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

Set some PHP CLI settings

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

Restart Nginx

service nginx restart

Setup some PHP-FPM options

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

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

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

printf "[curl]\n" | tee -a /etc/php/7.0/fpm/php.ini
printf "curl.cainfo = /etc/ssl/certs/ca-certificates.crt\n" | tee -a /etc/php/7.0/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.0-fpm restart

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

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.1-fpm.sock;
4. Change it to: fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
5. Restart the whole server from forge.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment