How do I install PHP 7 (PHP next generation) on Ubuntu?
I wanted to install PHP 7 on a clean install of Ubuntu to see what issues I would face.
Here’s the of
Installing PHP7(Nightly Build - latest build) on Ubuntu using the terminal
i will assume that you have apache2 already installed, if not then install it with the following command:
apt-get install apache2
check if apache is running:
service apache2 status
You would be able to see something like:
apache2.service - LSB: Apache2 web server
Loaded: loaded (/etc/init.d/apache2)
Active: ACTIVE (RUNNING)
if apache is running then procced with the PHP 7 installation process:
First add the PHP7 repo to your sources list, /etc/apt/sources.list, using your preferred text editor:
deb http://repos.zend.com/zend-server/early-access/php7/repos ubuntu/
After adding the PHP 7 repo, update your system with the following command:
apt-get update
now if everything went ok you should be able to install PHP7 Nightly Build with the following command:
apt-get install php7-nightly
During the install a warning may appear, “Do you want to continue?, if it does press enter. After pressing enter, you will also get a warning similar to below
WARNING: The following packages cannot be authenticated!
php7-nightly
Install these packages without verification? [y/N]
Type Y and then press Enter to continue.
The installation is finished! Now you need to get PHP7 to work with Apache, in order to do that, copy/move the libraries and modules of PHP7 to the Apache directories with the following commands:
cp /usr/local/php7/libphp7.so /usr/lib/apache2/modules/
cp /usr/local/php7/php7.load /etc/apache2/mods-available/
After moving the files, you need to edit /etc/apache2/apache2.conf and add the following lines to the bottom of the file. which will tell apache to serve php files
SetHandler application/x-httpd-php
Now that you fixed the apache2.conf run the following command to enable the PHP mpm module and switch to mpm_prefork.
a2dismod mpm_event && a2enmod mpm_prefork && a2enmod php7
Restart Apache so that the changes you made take effect:
service apache2 restart
Now its time to test PHP 7
To test out PHP7, you are going to create a PHP file a called info.php in /var/www/html/ by using your favorite editor and inserting the following lines of code.
Now you can go to your favorite browser and try the following URL
http://localhost/info.php
At the top of the page, check that the PHP version is 7.0 or higher.
PHP7 version example
Now that You verified that it's working, you should remove your info.php as it's a security risk. Remove it with the following command:
rm /var/www/html/info.php
Source:https://www.atlantic.net/community/howto/try-php7-debian-8-2-lamp-stack/