Note: This “guide” was meant for Ubuntu 14.04, I haven’t tested it on 16.04 and it most probably will not work, so please do not attempt to use it at all. I doubt that it would even work on 14.04 fallowing this guide.
You can refer to this guide for php7 with apache2 – Ubuntu 16.04 – Install Apache2 and php7
If you want to try the new php7 which GA release (General availability) is about to be finished in mid October, you can fallow these instructions.
I have done this little experiment on a virtual machine, and I strongly advice for you to do the same. But if you have balls go and do it on a production server.
Usually you will need to download and compile the packages on your system, but since I am lazy I searched for a ppa, and seems Ondřej Surý was kind enough to compile them, put them on ppa, and update them regularly.
This is the ppa – https://launchpad.net/~ondrej/+archive/ubuntu/php
I actually had php5 and apache running on this virtual instance, so even before adding the ppa, you need to remove everything php5 related, otherwise you might have conflicts and problems like me:
sudo apt-get remove php5*
Then add the php7 ppa:
sudo add-apt-repository ppa:ondrej/php
run update:
sudo apt-get update
and install php7:
sudo apt-get install php7.0
For apache you will need to enable php7 mod with:
sudo a2enmod php7.0
disable php5 mod (if you had php5 in the first place):
sudo a2dismod php5
Restart apache:
sudo service apache2 restart
and you are good to go.
You can put a file with
<!--?php phpinfo(); ?-->
and take a look at your brand new php7 install.
After that I decided to run a simple test to see if php7 is really that much faster than php5, and run on two identical VM’s the script from http://www.php-benchmark-script.com/.
PHP 5
-------------------------------------- | PHP BENCHMARK SCRIPT | -------------------------------------- Start : 2015-09-20 01:24:52 Server : localhost@192.168.1.139 PHP version : 5.5.9-1ubuntu4.11 Platform : Linux -------------------------------------- test_math : 0.856 sec. test_stringmanipulation : 0.923 sec. test_loops : 0.540 sec. test_ifelse : 0.427 sec. -------------------------------------- Total time: : 2.746 sec.
PHP 7
-------------------------------------- | PHP BENCHMARK SCRIPT | -------------------------------------- Start : 2015-09-20 01:24:55 Server : ubuntu-server@192.168.1.109 PHP version : 7.0.0RC3 Platform : Linux -------------------------------------- test_math : 0.225 sec. test_stringmanipulation : 0.338 sec. test_loops : 0.224 sec. test_ifelse : 0.267 sec. -------------------------------------- Total time: : 1.054 sec.