How to setup a web server with Nginx/PHP on ALARM

A lot of e-mails I’ve gotten about the Pogoplug have been about running a PHP web server or running some sort of PHP CMS (Drupal, Joomla) on the device. Although I don’t recommend running the latter, PHP is actually pretty easy to get up and running alongside Nginx on Arch Linux ARM.

First thing go ahead and get the packages that we’ll need installed.

pacman -S nginx php php-fpm

At this point we have PHP all ready to go so let’s fire it up.

rc.d start php-fpm

This configuration is different than the traditional Apache setup you may see often. Rather than having the web server handle script execution, we decouple that processing and pass it to a FastCGI handler for PHP (PHP-FPM). This manager handles the starting of PHP processes and will spawn child processes when needed. If you want to control the number of child processes that PHP-FPM is allowed to spawn or set it to a static value, the settings are contained in /etc/php/php-fpm.ini.

Now that the PHP handler is running we just need to configure Nginx to pass the requests to it. Open /etc/nginx/conf/nginx.conf and set it up so that it looks like the following.

#user http;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/;

events {
        worker_connections  1024;

http {
        include       mime.types;
        default_type  application/octet-stream;

        #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
        #                  '$status $body_bytes_sent "$http_referer" '
        #                  '"$http_user_agent" "$http_x_forwarded_for"';

        #access_log  logs/access.log  main;

        sendfile        on;

        keepalive_timeout  15;

        gzip  on;
        gzip_comp_level 1;

        server {

                listen       80;
                server_name  localhost;

                location ~ \.php {
                        root /srv/http;
                        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
                        fastcgi_index index.php;
                        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                        include fastcgi_params;

                location / {
                        root /srv/http;
                        index index.php;

The two gzip lines aren’t really necessary but they’ll reduce the amount of data the server needs to transmit so I enable whenever possible. Now go ahead and start Nginx.

rc.d start nginx

Next in /srv/http create an index.php with following code inside it. Also make sure it has the proper permissions (owner: http/group: http)

After that point your browser to the web server’s IP address and it should load the PHP Info page. Now you’ve got PHP/Nginx running on Arch Linux ARM.