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.
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.
- Install additional packages
apt - get install php5-fpm libgd2-xpm libpcrecpp0 libxpm4
- Install Nginx
apt-get install nginx
- Create the directory /var/www
mkdir/var/www chown-R www-data:www-data /var/www
- Create a file index.php in /var/www with the following content :
<?php phpinfo(); ?>
- 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;
}
- Restart the server
service nginx restart
- A ride from your browser to the IP of your server, and you'll get the following result
View a file PHP with Nginx
- Install the CGI wrapper if you need to run CGI scripts on your server
apt - get install fcgiwrap
- Reduce the number of PHP and CGI processes to free up memory
- Edit the file /etc/php5/fpm/php-fpm.conf
process.Max = 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
- Edit the file /etc/php5/fpm/php-fpm.conf
- 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.