The fundamental services required to turn your Raspberry Pi into a web server consist of Apache (the web server itself), PHP (scripting language) MySQL (database server) and PHPMyAdmin (DB web administrator interface). When installed on a Linux based system, the collective term for these is LAMP.
First of all
You may have to install Raspbian (Debian for Raspberry Pi) on a micro SD card. You can download this SO for free from here.
Step 1 – Update your Linux 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
Step 4 – Install 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.
We´ll create a teting page to check if everything is propperly installed:
sudo nano /var/www/
And then we write:
<?php phpinfo(); ?>
Step 5 – Install PHPMyAdmin
Now we need to install the PhpMyAdmin package using:
apt-get install phpmyadmin
The package will begin installing. You will be asked which web server is installed, choose apache2.
Step 6 – configure for dbconfig-common
Next we’ll need to configure PhpMyAdmin’s database. You’ll see the following prompt:
When prompted, choose Yes. Next you’ll be asked for an administrative password, this is the root password that was set during the MySQL installation in the previous tutorial.
You’ll be asked to set a password for PhpMySQL. I’ve used the same password as the MySQL root password, but its up to you what you set here. Make a note of it somewhere.
That’s PhpMyAdmin installed. Next we need to change the apache configuration to allow us to use http://your.raspberrypi.domain/phpmyadmin to access it.
Step 7 – Configure Apache to work with PhpMyAdmin
We need to alter the Apache configuration in order to access PhpMyAdmin. To do this, enter the following command to alter the configuration:
The configuration file will load in Nano. Navigate to the bottom of the file (keep pressing CTRL + V to jump page by page until you’re at the bottom of the file) and add the following new line to the file:
Save the file (CTRL + X and enter Y when prompted to save) and restart Apache2. To restart Apache, enter the following command:
That’s it! You’re all installed and ready to go. Give accessing it a try by going to your Raspberry Pi’s IP address or domain name and add ‘/phpmyadmin’ to the end in your web browser, ie http://your.raspberrypi.domain/phpmyadmin.
Step 8 – Install FTP Server
As last step, we´ll install VSFTPD, an FTP server to upload all the files to our web server. First we need to install the vsftpdpackage.
sudo apt-get install vsftpd
By default vsftpd is configured for anonymous access with read-only permissions. We’re going to change things so that it requires you to authenticate with a local user. Let’s open the configuration file.
sudo nano /etc/vsftpd.conf
We want to change or uncomment the following values.
anonymous_enable=NO local_enable=YES write_enable=YES local_umask=022 chroot_local_user=YES user_sub_token=$USER local_root=/home/$USER/ftp
After that restart the vsftpd service. Now we need to create a couple folders in your local user’s home folder. The ftp folder will be the root when you connect. The way vsftpd works, the root is not allowed to have write permissions on it, so we’ll create a sub-folder inside the root called files which our local user will be allowed to write to. This is where you’d upload/download files from with an FTP client.
mkdir /home/<user>/ftp mkdir /home/<user>/ftp/files chmod a-w /home/<user>/ftp
Now you should be able to connect to your web server from any FTP client and start uploading/downloading files.
That’s pretty much it! Reboot your device, you’re ready to start hosting from your Raspberry Pi!