The fundamental services required to turn your Raspberry Pi into a web server consist of Apache (the web server itself), PHP (scripting language) and MySQL (database server). When installed on a Linux based system, the collective term for these is LAMP.
There are other secondary services which aren’t quite as important at this stage to provide FTP and outbound mail, but that’ll be covered in a separate tutorial.
First things first, I’m assuming you’ve got Raspbian installed and followed my previous tutorial – Prepare your Raspberry Pi to become a web server.
Step 1 – Make sure you’re up-to-date
Ensure you’re running the latest system software. To check for updates and install them enter the following command:
sudo apt-get update
Step 2 – Change your hostname
Just to miminise the chances of any hickups we’re going to change the hostname from the default ‘raspberrypi’. From the terminal, enter:
sudo nano /etc/hostname
Nano editor will launch. Replace ‘raspberrypi’ with the domain from which your Raspberry Pi will run from. It’s not essential to change the hostname, but it is something I have done.
Once you’ve changed the hostname press CTRL + X to exit nano, and save when prompted. Now restart your Raspberry Pi to take to the new hostname:
Once restarted, find out the FQDN to ensure your RPi has the correct hostname. A FQDN is a Fully Qualified Domain Name. To do this enter the following command once your RPi has restarted and you’ve logged back in with SSH:
If the hostname you entered is returned, congratulations! Go stick the kettle on and have a brew before moving onto the next part.
Step 3 – Install Apache
Here’s where the fun begins. We’re going to start by installing Apache and some other packages. To do this its begin with entering:
This means we’re not having to type sudo each time we run a command. When you’ve done this, enter the following:
apt-get install apache2 apache2-doc apache2-utils
This shouldn’t take long. Once we’ve done that we’re going to install a few support packages including PHP. Once complete, enter the following command:
apt-get install libapache2-mod-php5 php5 php-pear php5-xcache
This too shouldn’t take too long. Follow up with installing the support package for database connectivity:
apt-get install php5-mysql
Now we’re going to install MySQL server. Do this by entering the following command:
apt-get install mysql-server mysql-client
As part of the installation, you’ll be asked to set a root password. Enter a password and then confirm it when prompted in the blue screen.
That’s pretty much it! Reboot your device, you’re ready to start hosting from your Raspberry Pi! In the next few tutorials, I’ll guide you through installing PhpMyAdmin, FTP server and Postfix. Feel free to leave your comments below.