PHP7 Elephant created by Walker Cahall
Verified and Tested 10/8/15
Introduction
In this How-To, we will be installing PHP7 on a Debian 8.2 LAMP stack. PHP7’s expected release date is sometime in November 2015. If you plan on upgrading to the new version of PHP, you can use this guide to install PHP7 so that you can test your code. This guide will be show you how to install the PHP7 Beta or Nightly Build from repo.
Installing LAMP
We need to add the PHP7 early access repo to your sources list with the following command:
echo "deb http://repos.zend.com/zend-server/early-access/php7/repos ubuntu/" >> /etc/apt/sources.list
After adding the PHP7 early access repo, we should now update the system with the following command:
apt-get update
Installing Apache
The next thing we need is to install Apache; you can do so with the following command:
apt-get install apache2
During the install, hit enter
when it asks “Do you want to continue?”
Now that Apache is installed, we can check to see if it running with the following command:
service apache2 status
Another way to check to see if Apache is working is by opening your web browser and then go to http://youripaddress
To get your IP address you can run the following command:
ifconfig
Using the above example we would put http://172.20.6.154 in the address bar of our browser:
Installing MariaDB
We are now going to add a database management system, however, if your code does not require a database, you can skip this section. Install MariaDB with the following command:
apt-get install mariadb-server
During the install, hit enter
when it asks “Do you want to continue?”
It will also prompt you to enter a MariaDB root password. Set a strong password of your choosing. After entering your password, hit enter
to continue.
After hitting enter, it will prompt you to reenter the password, do so and then hit enter
to continue.
After the install completes, we need to run the MariaDB Security installation with the following command:
mysql_secure_installation
Note: During the MariaDB Security installation, you will be prompted with a series of questions. For standard setups, type N for the change root password question (since you just set it) and Y for yes on all of the rest, see the screen shot below:
You can check that MariaDB is running with the following command:
service mysql status
Installing PHP7
We can now install PHP7. Below you can find the two choices of the Nightly or the Beta builds. As the nightly build is more up to date, it has more fixed bugs than the Beta version, so I would suggest the nightly.
PHP7 Nightly Build Install:
apt-get install php7-nightly
PHP7 Beta 1 Install:
apt-get install php7-beta1
During the install, hit enter
when it asks “Do you want to continue?”
After hitting 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 hit Enter
to continue.
Getting PHP7 to work with Apache
We need to 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, we need to edit /etc/apache2/apache2.conf
and add the following lines to the bottom of the file.
<FilesMatch \.php$> SetHandler application/x-httpd-php </FilesMatch>
Now that we 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 we made take effect:
service apache2 restart
Testing PHP 7
To test out PHP7, we 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.
<?php phpinfo(); ?>
Now we can go back to your browser and update the following hyperlink with your IP address.
http://youripaddress/info.php
At the top of the page, check that the PHP version is 7.0 or higher.
Now that we verified that it is working, we should remove your info.php as hackers could use this information to set up attacks directed at the specific version of PHP you are running. Remove it with the following command:
rm /var/www/html/info.php
Congratulations on installing PHP7 with LAMP on your Debian 8.2 Server! Thank you for following this How-To, and please check back for more updates and to learn more about our reliable dedicated server hosting solutions.