Raspberry Pi – Install Apache, PHP & MySQL

December 26, 2014 by Pat - Comments - 2 min read

O'Brien LabsI always install Apache and PHP on my Raspberry Pi’s so that I can write and deploy small web applications. Once they’re setup, they’re good to go. There are times where I’ll get a new Raspberry Pi and/or have to reformat mine (typically because of boredom). This usually involves me having to remember how to install Apache, PHP, MySQL and phpMyAdmin from scratch. So I’m throwing together this small tutorial so that I can remember how to do this in the future. Hopefully it helps you out, too.

First we want to make sure our hostname is correct on the Raspberry Pi.

cat /etc/hostname

If it matches what you want it to match, then you’re good to go. If not, you’ll need to update it.

sudo nano /etc/hostname

Then reboot by running

sudo reboot

Once it’s back up, log back in and we’ll begin to install our packages. First step is to update the package list.

sudo apt-get update

When it’s done, install Apache first:

sudo apt-get install apache2 apache2-utils

Once that’s finished, install PHP:

sudo apt-get install libapache2-mod-php5 php5

And when it’s complete, install MySQL Server and Client

sudo apt-get install mysql-server mysql-client php5-mysql

Finally, phpMyAdmin which is a web front-end for MySQL

sudo apt-get install phpmyadmin

Lastly, phpMyAdmin is known to be a hotspot for attackers, so what I like to do is rename it to something random so it’s not easily found by attackers on the internet. I do this even if the Raspberry Pi is behind a firewall and not directly connected to the internet. Why? Because why not.

To hide phpMyAdmin we just need to make 1 change to the Apache config file for phpMyAdmin, then restart Apache. For safe measure you could even restart your Raspberry Pi.

sudo nano /etc/apache2/conf.d/phpmyadmin.conf

Where it says Alias /phpmyadmin /usr/share/phpmyadmin, we’ll want to change the /phpmyadmin portion to something random and something you’ll remember.

Alias /supersecretphpadmin012014 /usr/share/phpmyadmin

Last but not least, we need to restart Apache so it picks up the new config settings.

sudo service apache2 restart

That should do it! To verify everything is working, just browse to http://yourpi.ip.address/supersecretphpadmin012014 and you should see phpMyAdmin’s login prompt.

Share this post:

About Pat

I'm a I.T. systems engineer by day and in my spare time I code. I've made WordPress websites and plugins, weewx extensions and static html sites using Jekyll. I'm a technologist at heart and I enjoy tinkering on many different technology projects. Here on my site you will find some of the projects I've worked on, and other random bits of knowledge that I hope help someone along the way.

mentions