Try PHP7 on a Debian 8.2 LAMP Stack

PHP7 Elephant created by Walker Cahall http://www.waltronic.net/

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.

NOTE: Since PHP7 is in development do not use this in production, this guide is only meant to get you ready for the actual release.

Prerequisites

A server with Debian 8.2 installed is required, which will take care of the Linux portion of the LAMP stack install. If you do not have a server, why not consider firing up an Atlantic.Net Cloud server.

Installing LAMP on Debian 8.2 with PHP7

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 on Debian 8.2

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
An example of ifconfig showing the IP address of 172.20.6.154

An example of ifconfig showing the IP address of 172.20.6.154

Using the above example we would put  http://172.20.6.154 in the address bar of our browser:

The default page for Apache on Debian 8.2

The default page for Apache on Debian 8.2

Installing MariaDB on Debian 8.2

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.

Enter a strong password of your choice

Enter a strong password of your choice

After hitting enter, it will prompt you to reenter the password, do so and then hit enter to continue.

Re-enter the password you set before

Re-enter the password you set before

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:

An example of what mysql_secure_installation looks likeAn example of what mysql_secure_installation looks like

An example of what mysql_secure_installation looks like using MariaDB

You can check that MariaDB is running with the following command:

service mysql status

Installing PHP7 on Debian 8.2

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 on Debian 8.2

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

The result of the php.info file you made, using PHP7

The result of the php.info file you made, using PHP7

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 start up an affordable and reliable cloud server.

Try it out on our SSD Cloud Servers

Fast Cloud VPS Hosting – Up in 30 Seconds.

100% SSD – Easy to use and pay as you go!

Already have an account? Login
Avatar for Brendan Bonner

About Brendan Bonner

Brendan is currently a Senior Account Executive at Atlantic.Net while serving as the Community and Social Media Manger. He is also involved with special projects, including international Cloud deployments. Brendan's interests are Cloud, VPS, Linux, Windows and full stack development. He is also a Microsoft Certified Professional.

Stay Connected With Us