In the previous post, we discussed about setting up nginx on a Raspberry Pi. To serve dynamic content, a server side language like PHP and a database server like MySQL is essential. To execute the PHP scripts we will use PHP-FPM, which is a FastCGI implementation. To accelerate performance we will install Alternative PHP Cache(APC) also.

Edit the default site’s configuration as below to include the location block:

Restart nginx server, and create a php page to test everything looks OK.

 

Now access your php page http://<your_raspberry_address>/info.php. If you see the php configuration, FPM is setup correctly.

Now we will install MySQL and the very popular administration tool phpMyAdmin.

During the installation of MySQL, you will be prompted to enter the password for the root user of MySQL. You will also be asked to choose between Apache or lighthttpd to be used as the web server. You dont need to select anything here since we use nginx.

During phpMyAdmin installation, you will be asked to configure database for phpMyAdmin. Answer Yes here.  Enter the root user password that you created in the previous step when you are asked for it.

Also, create a link to phpMyAdmin directory in the www directory.

Now access http://<your_raspberry_address>/phpmyadmin, and login as root user with the previously set password. If you get a 403 Forbidden error, that probably because index.php is not included in the default document list. Edit /etc/nginx/sites-available/default and make sure that index.php is included in the default document list under server block as below.

You are now all set to use PHP/MySQL in nginx!