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. If you’d like to learn more about PHP7, read our articles What is PHP7 – Breaking Changes from PHP5 and What is PHP7 – Performance Improvement.
A server with Ubuntu 14.04 installed is required, which will take care of the Linux portion of the LAMP stack install.
To get PHP7 working we need to add the early access repo with the following command:
Once added we should make sure our system is up to date with the following command:
Install Apache by running the following command:
sudo apt-get install apache2
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:
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:
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
Installing MariaDB on Ubuntu 14.04
Install MariaDB with the following command:
sudo apt-get install mariadb-server
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
After you enter your MariaDB root password, you will need to re-enter it.
Re-enter the password you set before
Continue with the MariaDB Security installation with the following command:
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
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
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!
Install these packages without verification? [y/N]
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.
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.
Test out this page in your browser with the following hyperlink with your IP address:
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 or learn more about our reliable dedicated servers and dedicated server hosting solutions.