Laravel Forge is a lovely service for not having to worry about your server deployment process. It really saves me a lot of time. However, I wish that the creators would support upgrading PHP versions for existing servers.
In the past, I destroyed my server and deployed a new one to benefit from the new PHP version. Since then, I have more websites and setting everything up again sounded like a lot of work. So, I decided to try and update the PHP version myself.
Instructions
First, SSH into your Laravel Forge server and make sure that you have your sudo password; you will need it.
We will add Ondřej Surý list of PHP packages for Debian so that we can download the new version of PHP.
sudo add-apt-repository ppa:ondrej/php
We will now delete our local cache of packages forcing new packages to show up.
sudo apt-get update
Download PHP 7.1 and install it.
sudo apt-get install php7.1
Since Laravel Forge runs on Nginx, we will download the PHP-FPM package and its dependencies.
sudo apt-get install php7.1-fpm
Next up, we will update our Nginx configuration. Let’s open the config with your editor. For this tutorial, I am using VI.
sudo vi /etc/nginx/sites-enabled/default
You should now see a file that looks like this:
# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/default/before/*;
server {
listen 80 default_server;
server_name default;
root /home/forge/default/public;
# FORGE SSL (DO NOT REMOVE!)
# ssl_certificate;
# ssl_certificate_key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
index index.html index.htm index.php;
charset utf-8;
# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/default/server/*;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/default-error.log error;
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php5.6-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/default/after/*;
Do not worry about all of the scary looking configuration parameters.
We want to change one line only. If you are using VI, you can hit “i” on your keyboard to enter insert mode. This will allow you to type.
Change the following line:
fastcgi_pass unix:/var/run/php/php5.6-fpm.sock;
Replace it with:
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
If you are using VI, you can hit “ESC” and then “:”. This will bring up a “:” at the bottom. Write wq to save your changes and exit.
The hard part is out of the way.
Restart your server.
sudo service nginx restart
Your websites should now all be running on PHP 7.1. Congratulations!
You can check your PHP version with the following command:
php -v
You should see something like:
PHP 7.1.1-1+deb.sury.org~trusty+1 (cli) (built: Jan 20 2017 09:43:29) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.1.1-1+deb.sury.org~trusty+1, Copyright (c) 1999-2017, by Zend Technologies
Good job and enjoy!