Ahoy! If you’re anything like me — aka, a get it done kind of person — and work in web development, you’ve probably gotten once or twice frustrated by not having a server sitting around that you have full access to, by some corporate nonsense turning a 2 hour job into a 10 month process of paper-pushing and confirmation emails of being yet another step closer to getting that holy grail of a server, only to realise it’s nothing but a simple Apache2 setup with no PHP, no FTP, no nothing. Yet the paperwork says that’s a web server. True story…
Let’s change all that and make the World a better place for all of us with something as simple and cheap as a Raspberry Pi!
Now, the first few things you want to make sure you have handy are the following:
A Raspberry Pi 3 or Raspberry Pi 2. Either would work just fine.
A network cable.
A micro SD card of at least 8GB and of fairly high speed
A 2.5 Amp or higher micro USB charger
Note: the reason why no keyboard, mouse or monitor is required is because we are going to SSH into the Pi3 via the command line. It’s a web server we’re setting up so we don’t quite care about GUI anyway. If for some reason you do, the above mentioned peripherals would be necessary, alongside a HDMI cable.
Now, there are a number of ways, some official, some not so official of how to set up the Operating System on a Pi. I’ve tested a few approaches, and what follows is the one I believe is the most simple and least error-prone method.
OS Setup: Raspbian Jessie (note: not NOOBS version)
1. Go to https://www.raspberrypi.org/downloads/raspbian/ and download the zip file of Raspbian Jessie and unzip once downloaded. It will contain an .img file of the OS.
2. Go to http://ivanx.com/raspberrypi/ and download PiFiller. Ignore the notes about it possibly not working on Yosemite, it works just fine on El Capitan.
3. Install PiFiller and start the app. Follow its instructions. All very simple and it dramatically reduces the installation time and effort. On a fairly low-end microSD card it took about 14 minutes to flash the OS image file onto the card. Note that the result is a fully working OS that you can pop into the Raspberry Pi and it will boot. No extra setup necessary. Pretty nifty if you ask me, especially compared to the official guide which drags you through the dozens of terminal commands, one more cryptic than the other.
4. Pop your card out (safe removal has been taken care by PiFiller) when the app prompts you to and pop in into the RPi.
5. Plug network cable in, and finally plug the charger in as well.
6. Give it a couple minutes to boot up.
Connecting to the Pi via SSH
- Open your terminal and type:
which will effectively return you the IP address of your raspberry. After a couple of pings, hit Ctrl + C to end the ping loop.
2. In your terminal type
If for any reason you get a warning saying “remote host identification has changed” and not allowing you to connect, you need to run this command:
ssh-keygen –R the_ip_address_you_got_from_the_ping
This simply ensures your Mac generates a new SSH key for the Pi and forgets the old one from a possible previous installation.
3. Your password is: raspberry
That is all about connecting to your Pi. Now we can commence setting up the actual server. A PHP7 powered server to be more exact. But first a note. At the writing of this documentation there is still no official repo for PHP7 so alternative sources will have to be used, hence the first four of steps are extra to a usual PHP5 setup.
- Open the sources.list file with nano to add the repo source:
sudo nano /etc/apt/sources.list
2. Append the following lines to the file
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
3. Save the file with Ctrl + X, hit Y, hit Enter.
4. Get your certificates in order to be able to do download the repo.
sudo gpg — keyserver pgpkeys.mit.edu — recv-key CCD91D6111A06851
sudo gpg — armor — export CCD91D6111A06851 | sudo apt-key add –
sudo apt-get update
5. Install apache2 and PHP7 by running the following line in the terminal:
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 will install everything. In fact, if we would have installed things from an official repo, this is the only step we would have needed to do. This step will take a good while, possibly 20+ minutes so be patient.
6. Test the installation went as planned by checking the version of the PHP:
7. Test the Apache installation by going to the_ip_address_you_got_from_the_ping in your web browser.
Now, that’s all nice and dandy, but what is the use of a web server you cannot upload your site/app to, right? So let’s set up the FTP connection.
- Download and install vsftpd by running this in the terminal:
sudo apt-get install vsftpd
2. While theoretically this sorts out what we need, in practice vsftpd is a bit paranoid and what’s probably most important is unset in its configuration file, therefore you’ll need to edit that file:
sudo nano /etc/vsftpd.conf
3. Uncomment the following line:
by removing the #
4. Save the file with Ctrl + X, hit Y, hit Enter.
5. Restart your FTP by running this in the terminal:
sudo service vsftpd restart
6. Upload web accessible content to /var/www/html via any FTP client like Cyberduck or FileZilla. Your username is “pi”, password is “raspberry”, domain is the_ip_address_you_got_from_the_ping
That’s practically it! However, I do like to make one final change to my setup, and that’s changing the name of the Pi from raspberrypi to something else, something more relevant to the project or the location the server is running at. You will have to edit two files; the hostname and the hosts file.
- Open the hostname file by running this in the terminal:
sudo nano /etc/hostname
2. Where you see raspberrypi, write another name that you feel is more relevant and save the file the usual way.
3. Open the hosts file by running this in the terminal
sudo nano /etc/hosts
4. Where you see raspberrypi, write another name that you feel is more relevant and save the file the usual way.
in your terminal to restart the Pi. You should now be able to SSH into it by
That’s it. Done and dusted! In about 2 hours. While this may still seem like a long and difficult setup to some, it’s one of the simplest ways of doing it without resorting to NOOBS, which in my experience is a terrible choice and messes up things uncontrollably. Enjoy your server!