Deploy Nginx + Mysql + Spawn-Fcgi On Debian/ubuntu

來源:互聯網
上載者:User

標籤:style   http   io   ar   color   os   sp   for   檔案   

Install Required Packages

apt-get update & upgradeapt-get install mysql-server nginx php5-cli php5-cgi spawn-fcgi nginx php5-cli php5-cgi                 spawn-fcgi php5-gd php5-mysql

2 Create Directories For Your Site

mkdir -p /srv/www/yourdomain/public_htmlmkdir /srv/www/yourdomain/logschown -R www-data:www-data /srv/www/yourdomain

3 Configuration

I will use UNIX Sockets to run php.

vi /etc/nginx/sites-enabled/yourdomain

server {         server_name www.yourdomain.com yourdomain.com;         access_log /srv/www/yourdomain/logs/access.log;         error_log /srv/www/yourdomain/logs/error.log;         root /srv/www/yourdomain/public_html;         location / {                  index index.html index.htm;    }          location ~ \.php$ {                 include /etc/nginx/fastcgi_params;                 fastcgi_pass unix:/var/run/php-fastcgi/php-fastcgi.socket;                 fastcgi_index index.php;                 fastcgi_param SCRIPT_FILENAME /srv/www/yourdomain/public_html$fastcgi_script_name;    }}  # rewrite  server {         server_name yourdomain.com; rewrite ^/(.*) http://www.$host/$1 permanent;}
4 Create a file named /usr/bin/php-fastcgi with the following contents:

vi /usr/bin/php-fastcgi

注意:FASTCGI_USER=www-data, 在nginx的設定檔中user  www-data;

#!/bin/bash FASTCGI_USER=www-dataFASTCGI_GROUP=www-dataSOCKET=/var/run/php-fastcgi/php-fastcgi.socketPIDFILE=/var/run/php-fastcgi/php-fastcgi.pidCHILDREN=4PHP5=/usr/bin/php5-cgi/usr/bin/spawn-fcgi -s $SOCKET -P $PIDFILE -C $CHILDREN -u $FASTCGI_USER -g $FASTCGI_GROUP -f $PHP5

5 Make it executable by issuing the following command:

chmod +x /usr/bin/php-fastcgi
6 Create a file named /etc/init.d/php-fastcgi with the following contents:

vi /etc/init.d/php-fastcgi

#!/bin/bash PHP_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  ;;esac exit $RET_VAL

7 Start php-fastcgi and nginx by issuing the following commands:

chmod +x /etc/init.d/php-fastcgi update-rc.d php-fastcgi defaults/etc/init.d/php-fastcgi start /etc/init.d/nginx start

8 Test PHP With FastCGI

vi /srv/www/yourdomain/public_html/info.php <?php phpinfo(); ?>

Deploy Nginx + Mysql + Spawn-Fcgi On Debian/ubuntu

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.