Raspberry Pi : install Nginx with PHP support, CGI and TIMS

It is now time to install a Web server for various services such as monitoring, Download, Owncloud or a music Server. This is what we will see with the implementation of NGinx.

Raspberry Pi Home Server – Etape 11 : installer Nginx avec support PHP, CGI et SCGI

For our Web server, the goal is to have a support of different technologies to not be limited. In addition to Nginx, Let's install php - fpm, fcgiwrap and SCGI support (for the web interface for rtorrent). Since version 0.8.42, the SCGI module is included so not need to recompile everything (Phew !)

For those who want a comparison of different web servers, You can watch article here.

  1. Install additional packages
    apt - get install php5-fpm libgd2-xpm libpcrecpp0 libxpm4
  2. Install Nginx
    apt-get install nginx
  3. Create the directory /var/www
    mkdir /var/www
    
    chown -R www-data:www-data /var/www
  4. Create a file index.php in /var/www with the following content :
    <?PHP phpinfo();
    
    ?>
  5. Edit the/etc/nginx/sites-available/default file by replacing the old values by your configuration. Here for example :

    root /var/www;

    index index.php index.html index.htm;

    location ~ .php$ {

    fastcgi_pass unix:/var/run/PHP5-fpm.sock;

    fastcgi_index index.php;

    include fastcgi_params;

    }

  6. Restart the server
    service nginx restart
  7. A ride from your browser to the IP of your server, and you'll get the following result

    Viewing PHP file with Nginx

    View a file PHP with Nginx

  8. Install the CGI wrapper if you need to run CGI scripts on your server
    apt - get install fcgiwrap
  9. Reduce the number of PHP and CGI processes to free up memory
    1. Edit the file /etc/php5/fpm/php-fpm.conf
      process.Max = 2
    2. Modify the maximum number of processes. In my case I won't have dozens of connections therefore file /etc/nginx/nginx.conf :
      worker_processes 1
  10. Relaunch the different service
    service nginx restart
    
    service php5-fpm restart

    If you have installed the CGI wrapper :

    Service fcgiwrap restart

This is for the web server in basic configuration.

Like this article ? Bear with me on patreon!

You may also like...