The environment of this article is Ubuntu 12. For other systems, you can check it yourself or communicate with me.
1. Install nginx
This step is relatively simple. Just sudo apt-get install nginx and you can install it. After installation, you need to set the nginx service port. Its default port is 80.
2. Set the nginx service port
The configuration file is in /etc/nginx/nginx.conf. The configuration file refers to sites-enabled/default. It can be configured as follows:
listen 8081 default_server; listen [::]:8081 default_server ipv6only=on; root /usr/share/nginx/html; index index.html index.htm;
In addition, configure the port of the php parser (php-cgi):
location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; # # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini # # # With php5-cgi alone: fastcgi_pass 127.0.0.1:3344; # # With php5-fpm: # fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; include fastcgi_params; }
Then restart nginx,
service nginx restart
3, install spawn-fcgi,
apt-get install spawn-fcgi
4, install php
apt-get install php5 php5-dev php5-cgi
5, start php-cgi, bind port 3344
sudo spawn-fcgi -a 0.0.0.0 -p 3344 -C 10 -u root -f /usr/bin/php-cgi
I forgot to add sudo before, It keeps getting errors when starting up, which is weird.
6. Test the php environment
Add the test.php file in /usr/share/nginx/html/. If the website directory is not this, add test.php in the corresponding directory. The content is as follows:
<?php phpinfo(); ?>
The above introduces Ubuntu + Nginx + php + swpan-fcgi to build a PHP network service, including various aspects. I hope it will be helpful to friends who are interested in PHP tutorials.