Turn your Raspberry Pi 3 into a PHP 7 powered web server
Learn the steps to install Apache2 and PHP 7.0 on your Raspberry Pi 3, to create the ultimate low-powered, super quick web server in this tutorial.
Important: This tutorial needs updating. As the comments show, lots of people having the same issue. I will update the tutorial this week.
In this tutorial I’m going to go through the steps to install Apache2 and PHP 7.0 on your Raspberry Pi 3, to create the ultimate low-powered, super quick web server.
Prerequisites
I’m going to assume that you have Raspbian installed on your Raspberry Pi 3. For the best results, I recommend running Raspbian from a USB Flash drive rather than a MicroSD card. See my tutorial on how to do this.
Update
These instructions should work fine on the Raspberry Pi 2 as well. Let me know if anyone tries this.
Step 1 – Add new repository sources
At the time of writing, PHP 7.0 hasn’t yet made the official repository sources, so we need to add one which provides us with the PHP 7.0 packages. Edit your sources file with this command:
sudo nano /etc/apt/sources.list
Below the existing entries in the file on a blank line, add the following two lines:
deb http://repozytorium.mati75.eu/raspbian jessie-backports main contrib non-free #deb-src http://repozytorium.mati75.eu/raspbian jessie-backports main contrib non-free
Your file should look a little like this:
Next we need to add a couple of certificates in order to allow us to use the sources with apt-get. Run the following two commands:
sudo gpg --keyserver pgpkeys.mit.edu --recv-key CCD91D6111A06851
sudo gpg --armor --export CCD91D6111A06851 | sudo apt-key add -
And finally we need to update the package list by running:
sudo apt-get update
Step 2 – Install the core Apache2 and PHP 7 packages
We're ready to install Apache2 and PHP7, along with some common packages that we may need for most web applications such as Symfony2, WordPress, Drupal etc. Run the following command to install these packages:
apt-get install apache2 php7.0 php7.0-curl php7.0-gd php7.0-imap php7.0-json php7.0-mcrypt php7.0-mysql php7.0-opcache php7.0-xmlrpc libapache2-mod-php7.0
This may take a little time, but as soon as we’re done, we are essentially finished.
Step 3 – Test Apache2 and PHP 7
Assuming all went well, we’re ready to test to see if everything went OK with the installation. First we’ll test the version of PHP that CLI is using:
php -v
You should see something like this:
Next we’ll test two things; Apache2 and PHP 7. In your web browser, visit the IP address of your Raspberry Pi. If you haven’t used ssh and have followed these steps on your Raspberry Pi 3 itself, just visit http://127.0.0.1, otherwise change 127.0.0.1 for the IP address of your Raspberry Pi.
You should see the default Debian holding page:
Next we’ll test PHP. Run the following command to create a test file:
echo "<?php phpinfo();" >> /var/www/html/phpinfo.php
Yet again, visit the IP address of your Raspberry Pi, this time adding /phpinfo.php to the URL. You should see the PHP Information as shown below:
Conclusion
The Raspberry Pi 3 is a very capable, low power consuming little piece of kit. Combine that with the awesome power and speed of PHP 7.0 and you have a low energy web server that’s lightning quick and ideal for blogging from. As mentioned in the prerequisites, I do recommend using a decent USB Flash drive instead of an MicroSD card to run the operating system.
My first experiments with WordPress on PHP 7 on a Raspberry Pi 3 were very promising. I’m probably going to switch back to hosting this site from one again, now that the equipment and software can keep up with the traffic to the site.
Any questions or feedback, feel free to add below. Let me know about your own projects too and I’ll share them.