VestaCP,  Linux

Upgrading to PHP 7.1 on VestaCP (Ubuntu)

Lately I had to upgrade my VPS to meet dependency of a new app. Unfortunately unlike other times, I could not find a guide which would work. After struggling for a while breaking the VPS multiple times and going through few different tutorials here is what worked for me. If you follow the simple steps, you shall be able to properly update your PHP of VestaCP on Ubuntu to 7.1. You will need SSH or any other way to access command line of the machine. I assume you already have VESTA

For the record, I am still using Ubuntu 14.04 LTS, previous version of php was 5.5 and version of Vesta is 0.9.8. However, I think this should work with newer version of ubuntu and php as well. I am using the package nginx+apache, which this tutorial will only work on.

Step 1 — Backup

Yes, starting with the boring backup. There are many things that can possibly go wrong with an upgrade like this. If you don’t want to loose existing applications and configuration don’t forget to take a backup. If it is a VPS, taking a snapshot would do.

Step 2 — Check Current Version

Check what the current version of php you already have by:

The output shall be something like:

PHP 5.5.9-1ubuntu4.19 (cli) (built: Jul 28 2016 19:31:33)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies

Step 3 — Add Third Party Repository

PHP’s new versions are not on the default repository of Ubuntu 14.04. If you are running that, you need to install it from third party repository. For that first you need to install python-software-properties. So, let’s update our package list and install it.

sudo apt-get update
sudo apt-get install python-software-properties

If that was successful, now you can add the third party repository

Let us update the package list one last time as a new repository was added.

sudo apt-get update

Step 4 — Install New Version of PHP

You should now be able to install the new php version.

During the installation, it may ask to configure database for Roundcube, if you are already using it. If you have already configured it, you can choose not to configure and keep the local existing configuration.

If everything went well so far, the new version of php should be visible from command line.
If everything went well so far, the new version of php should be visible from command line.

Now let’s create a php file with with the content:

And load it up on the server. What does it show if you try to access it?

Didn’t quite work, did it? We both php5 and php7.1 on our system now. command line is using the new version but apache is still using the old one. So, follow along!
 

Step 5 — Telling Apache to Use New PHP

Let’s disable old php version from apache and enable the new one. Use the following commands:

Step 6 — Installing Extensions

Though we now have php7.1 enabled and installed, it doesn’t have some common extensions that already were present on vesta. You can use the below command to install some necessary ones that I needed for WordPress and Laravel. You may need few more depending on your needs.

 

If you want to enable php-fpm on apache:

Now we will restart apache2 to make the changes to take effect.

Conclusion

With that, now you should have a functioning php7.1 installed with your Vesta on Ubuntu. If you think something was missed or want to suggest improvements, feel free to comment below.

Credits

https://kampunghosting.com/2015/12/upgrade-vestacp-to-php-7-ubuntu/
https://www.digitalocean.com/community/questions/php-v-is-7-0-11-and-phpinfo-is-5-5-9?answer=31029

Tui là jamesblackvn!

Gửi phản hồi

Website này sử dụng Akismet để hạn chế spam. Tìm hiểu bình luận của bạn được duyệt như thế nào.