1. install necessary software sudoapt-getinstallnginxphp5-cliphp5-cgispawn-fcgipsmiscmysql-servermysql-clientphp5-mysqlmemcachedphp5-memcachephp5-curlphp5-gd2. Open the browser access: 127.0.0.1. The page indicating successful nginx installation is displayed. But access the PHP File
1. install necessary software sudo apt-get install nginx php5-cli php5-cgi spawn-fcgi psmisc mysql-server \ mysql-client php5-mysql memcached php5-memcache php5-curl php5-gd 2. open browser access: 127.0.0.1. The page indicating successful nginx installation is displayed. But access the PHP File
1. install necessary software
sudo apt-get install nginx php5-cli php5-cgi spawn-fcgi psmisc mysql-server \mysql-client php5-mysql memcached php5-memcache php5-curl php5-gd
2. Open your browser to access 127.0.0.1. The page indicating successful nginx installation is displayed. However, accessing the PHP file page does not work. (Note: The ngnix configuration file directory is/etc/ngnix/, and the default website root directory is/usr/share/ngnix/www /; php configuration file directory:/etc/php5 /)
3. Edit the/etc/ngnix/sites-available/default file. The content is as follows (you can back up the original file first ):
server { #listen 80; ## listen for ipv4; this line is default and implied #listen [::]:80 default ipv6only=on; ## listen for ipv6 root /usr/share/nginx/www; server_name localhost; location / { index index.html index.htm; } location ~ \.php$ { fastcgi_pass localhost:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; try_files $uri $uri/ /index.html; } error_page 404 /404.html;}
4. Modify the/etc/php5/cgi/php. ini file. Remove
#cgi.fix_pathinfo=1
Before a row#
. For more information, see the related notes of php. ini.
5. Create a file/usr/bin/php-fastcgi:
#!/bin/bashFASTCGI_USER=www-dataFASTCGI_GROUP=www-dataADDRESS=127.0.0.1PORT=9000PIDFILE=/var/run/php-fastcgi/php-fastcgi.pidCHILDREN=6PHP5=/usr/bin/php5-cgi/usr/bin/spawn-fcgi -a $ADDRESS -p $PORT -P $PIDFILE -C $CHILDREN -u $FASTCGI_USER -g $FASTCGI_GROUP -f $PHP5
6. Set/usr/bin/php-fastcgi to execute:
sudo chmod +x /usr/bin/php-fastcgi
7. Create the file/etc/init. d/php-fastcgi:
#!/bin/bashPHP_SCRIPT=/usr/bin/php-fastcgiFASTCGI_USER=www-dataFASTCGI_GROUP=www-dataPID_DIR=/var/run/php-fastcgiPID_FILE=/var/run/php-fastcgi/php-fastcgi.pidRET_VAL=0case "$1" in start) if [[ ! -d $PID_DIR ]] then mkdir $PID_DIR chown $FASTCGI_USER:$FASTCGI_GROUP $PID_DIR chmod 0770 $PID_DIR fi if [[ -r $PID_FILE ]] then echo "php-fastcgi already running with PID `cat $PID_FILE`" RET_VAL=1 else $PHP_SCRIPT RET_VAL=$? fi ;; stop) if [[ -r $PID_FILE ]] then kill `cat $PID_FILE` rm $PID_FILE RET_VAL=$? else echo "Could not find PID file $PID_FILE" RET_VAL=1 fi ;; restart) if [[ -r $PID_FILE ]] then kill `cat $PID_FILE` rm $PID_FILE RET_VAL=$? else echo "Could not find PID file $PID_FILE" fi $PHP_SCRIPT RET_VAL=$? ;; status) if [[ -r $PID_FILE ]] then echo "php-fastcgi running with PID `cat $PID_FILE`" RET_VAL=$? else echo "Could not find PID file $PID_FILE, php-fastcgi does not appear to be running" fi ;; *) echo "Usage: php-fastcgi {start|stop|restart|status}" RET_VAL=1 ;;esacexit $RET_VAL
8. Add the executable permission and set it to start upon startup.
sudo chmod +x /etc/init.d/php-fastcgisudo update-rc.d php-fastcgi defaultssudo /etc/init.d/php-fastcgi startsudo /etc/init.d/nginx start
9. Create a file/usr/share/nginx/www/test. php with the following content:
10. Open your browser and access 127.0.0.1/test. php to view the php information table page.
References
- Nginx and PHP-FastCGI on Ubuntu 10.04 LTS (Lucid)
Original article address: ubuntu12.04 + ngnix + php-fastcgi + mysql + memcached website development test. Thank you for sharing it with me.