Try PHP7 in a LAMP Stack on Ubuntu 14.04

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 install a LAMP Stack on an Ubuntu 14.04 Cloud Server with PHP7. PHP7  should be released sometime in November 2015 and if you plan on adopting the new version, now is a great time to test your code. This guide will give you the option to install the Beta1 build or the newest nightly build of PHP7.

NOTE: PHP7 is still in development and should not be used in production environments until it is fully released.

Prerequisites

A server with Ubuntu 14.04  installed is required, which will take care of the Linux portion of the LAMP stack install. Why not spin up a super fast Atlantic.Net cloud server in under 30 seconds.

Installing LAMP on Ubuntu 14.04 with PHP7

To get PHP7 working we need to add the early access repo with the following command:

sudo echo "deb http://repos.zend.com/zend-server/early-access/php7/repos ubuntu/" >> /etc/apt/sources.list

Once added we should make sure our system is up to date with the following command:

sudo apt-get update

Installing Apache on Ubuntu 14.04

Install Apache by running the following command:

sudo apt-get install apache2

Hit enter to when it asks “Do you want to continue?” during the install.

After installing, check to see if Apache is running by running the command:

sudo service apache2 status

 You can also verify if Apache is  working by opening your browser and going to http://youripaddress

If you do not know your IP address,  run the following command:

ifconfig
An example of ifconfig showing the IP address 172.20.6.154

An example of ifconfig showing the IP address of 172.20.6.154

In our case, we would put http://172.20.6.154 in our browser’s address bar and get the following page:

The default page for Apache on Ubuntu 14.04

The default page for Apache on Ubuntu 14.04

Installing MariaDB on Ubuntu 14.04

Install MariaDB with the following command:

sudo apt-get install mariadb-server

Hit enter when it asks “Do you want to continue?” during the install.

During the install, it will prompt you to enter a MariaDB root password. Set any password that you would like. It should be a strong password.

Enter a strong password of your choice

Enter a strong password of your choice

After you enter your MariaDB root password, you will need to re-enter it.

Re-enter the password you set before

Re-enter the password you set before

Continue with the MariaDB Security installation with the following command:

sudo mysql_secure_installation

Note: You will be prompted with a series of questions. Just type N for the change root password question and Y for yes on all of the rest, see the screen shot below:

An example of what mysql_secure_installation looks like

An example of what mysql_secure_installation looks like

Verify that MariaDB is running with the following command:

sudo service mysql status

Installing PHP7 on Ubuntu 14.04

We can now go ahead and install either the beta or the nightly release for PHP7. I would suggest the nightly release as it has fixed more bugs than the beta.

To install the PHP7 Nightly Build:

sudo apt-get install php7-nightly

To install the PHP7 Beta 1:

sudo apt-get install php7-beta1

Hit Enter when it asks “Do you want to continue?” during the install.

You will also get a warning similar to the following

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 modules and libraries of PHP7 into the appropriate Apache directories with the following commands:

sudo cp /usr/local/php7/libphp7.so /usr/lib/apache2/modules/
sudo cp /usr/local/php7/php7.load /etc/apache2/mods-available/

We now 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>

Once added run the following command to enable the PHP mpm module and switch to mpm_prefork.

sudo a2dismod mpm_event && a2enmod mpm_prefork && a2enmod php7

Since we made changes, we need to restart Apache so that the changes take effect:

sudo service apache2 restart

Testing PHP 7 on Ubuntu 14.04

To test out PHP7, we need to create a PHP file a named info.php in /var/www/html/  using your favorite editor and insert the following lines of code.

<?php
phpinfo();
?>

Test out this  page in your browser with 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

Check the PHP version at the top of the page it should be 7.0 or higher.

It’s a good idea to remove your info.php as hackers can set up attacks as they know more information about your server. Remove it with the following command:

sudo rm /var/www/html/info.php

Congratulations! You have just installed PHP7 with LAMP on your Ubuntu 14.04 Server. Thank you for following this How-To, and please check back for more updates.

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.
  • Of course, just like every other tutorial on the web, this does not work after following everything EXACTLY as written.

    • Brendan Bonner

      Are you getting any kind of error message?

      • The error occurred with “sudo a2dismod mpm_event && a2enmod mpm_prefork && a2enmod php7”, Apache would no longer reboot.

        Regardless, I’ve switched to Arch Linux and haven’t looked back.

        • Brendan Bonner

          Sorry to here that, but I am glad you are able to get it working. Once Ubuntu 16.04 comes out php7 should be a more viable option.

  • Sophia

    Works pretty good up till the point when it’s time to install PHP7 — and it’s downhill from there. It is asking me to install a package that supposedly doesn’t exist.

    • Brendan Bonner

      Hi Sophia! http://repos.zend.com/zend-server/early-access/php7/repos ubuntu/ No longer exsists. Originally this article was intended when PHP7 was in beta. To install on PHP7 on Ubuntu 14.04 you need to either install PHP7 by compiling it or using a personal package archive. I will be modifying this article soon to make adjustments.

  • Sophia

    E: unable to locate package php7-nightly

Stay Connected With Us