- Normal setup:
- Install and setup:
- sudo apt-get install nginx
- sudo apt-get install php5-fpm
- Test:
- In your server config, add the following:
server { # listen 80 default_server; # listen [::]:80 default_server ipv6only=on; set $root_path '/home/web/mydomain/public'; root $root_path; index index.php; #access_log /var/log/nginx/$host-access.log combined; #error_log /var/log/nginx/$host-error.log error; #Auto load image autoindex on; #Load rewrite rules module location / { gzip on; try_files $uri $uri/ /index.php; } #Alias folder location /uploads { alias /home/web/data/uploads; } 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:9000; # With php5-fpm: fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; include fastcgi_params; fastcgi_param APPLICATION_ENV "development"; } }
- Restart nginx:
- sudo /etc/init.d/nginx restart
- Create /var/www/test.php:
- phpinfo();
- while connecting to upstream:
- Install and setup:
- sudo aptitude install php5-cgi
- sudo aptitude install nginx
- sudo vim /etc/init.d/php-fastcgi
#!/bin/bash BIND=127.0.0.1:9000 USER=www-data PHP_FCGI_CHILDREN=15 PHP_FCGI_MAX_REQUESTS=1000 PHP_CGI=/usr/bin/php-cgi PHP_CGI_NAME=`basename $PHP_CGI` PHP_CGI_ARGS="- USER=$USER PATH=/usr/bin PHP_FCGI_CHILDREN=$PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS=$PHP_FCGI_MAX_REQUESTS $PHP_CGI -b $BIND" RETVAL=0 start() { echo -n "Starting PHP FastCGI: " start-stop-daemon --quiet --start --background --chuid "$USER" --exec /usr/bin/env -- $PHP_CGI_ARGS RETVAL=$? echo "$PHP_CGI_NAME." } stop() { echo -n "Stopping PHP FastCGI: " killall -q -w -u $USER $PHP_CGI RETVAL=$? echo "$PHP_CGI_NAME." } case "$1" in start) start ;; stop) stop ;; restart) stop start ;; *) echo "Usage: php-fastcgi {start|stop|restart}" exit 1 ;; esac exit $RETVAL
- sudo chmod +x /etc/init.d/php-fastcgi
- sudo /etc/init.d/php-fastcgi start
- sudo update-rc.d php-fastcgi defaults
- Test:
- In your server config, add the following:
server { # listen 80 default_server; # listen [::]:80 default_server ipv6only=on; set $root_path '/home/web/mydomain/public'; root $root_path; index index.php; #access_log /var/log/nginx/$host-access.log combined; #error_log /var/log/nginx/$host-error.log error; #Auto load image autoindex on; #Load rewrite rules module location / { gzip on; try_files $uri $uri/ /index.php; } #Alias folder location /uploads { alias /home/web/data/uploads; } 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:9000; # With php5-fpm: #fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; include fastcgi_params; fastcgi_param APPLICATION_ENV "development"; } }
- http://davidwinter.me/articles/2009/06/13/php-and-nginx-the-easy-way/
Good luck!
No comments:
Post a Comment