(1)首先要安装&更新我们需要的软件,包括nginx、php、php-cli、php-fcgi、spawn-fcgi、psmis apt-getupdateapt-getupgradeapt-geti
(1)首先要安装&更新我们需要的软件,包括nginx、php、php-cli、php-fcgi、spawn-fcgi、psmis
apt-get updateapt-get upgradeapt-get install nginx php php-cli php-cgi spawn-fcgi psmisc
(2)修改ngxin配置文件/etc/nginx/fastcgi.conf
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;fastcgi_param QUERY_STRING $query_string;fastcgi_param REQUEST_METHOD $request_method;fastcgi_param CONTENT_TYPE $content_type;fastcgi_param CONTENT_LENGTH $content_length;fastcgi_param SCRIPT_NAME $fastcgi_script_name;fastcgi_param REQUEST_URI $request_uri;fastcgi_param DOCUMENT_URI $document_uri;fastcgi_param DOCUMENT_ROOT $document_root;fastcgi_param SERVER_PROTOCOL $server_protocol;fastcgi_param REQUEST_SCHEME $scheme;fastcgi_param HTTPS $https if_not_empty;fastcgi_param GATEWAY_INTERFACE CGI/1.1;fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;fastcgi_param REMOTE_ADDR $remote_addr;fastcgi_param REMOTE_PORT $remote_port;fastcgi_param SERVER_ADDR $server_addr;fastcgi_param SERVER_PORT $server_port;fastcgi_param SERVER_NAME $server_name;# PHP only, required if PHP was built with --enable-force-cgi-redirectfastcgi_param REDIRECT_STATUS 200;# fastcgi_param PATH_INFO $fastcgi_path_info;# fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
3.修改nginx配置文件/etc/nginx/sites-available/default :
server { listen 80 default_server; listen [::]:80 default_server; root /var/www/html; index index.php index.html index.htm index.nginx-debian.html; server_name www.example.com; location / { try_files $uri $uri/ =404; } # application: phpldapadmin location /phpldapadmin { alias /usr/share/phpldapadmin/htdocs; index index.php index.html index.htm; } location ~ ^/phpldapadmin/.*/.php$ { root /usr/share; if ($request_filename !~* htdocs) { rewrite ^/phpldapadmin(/.*)?$ /phpldapadmin/htdocs$1; } fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $request_filename; include fastcgi_params; } location ~ /.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.0-fpm.sock; } location ~ //.ht { deny all; }}
4.默认情况下spawn-fcgi需要手动启动,我们希望开机启动fastcig,需要在/etc/init.d/目录下新建fastcgi开机启动脚本,这里我将脚本名为php7.0-fcgi:
sudo touch php7.0-fcgisudo nano php7.0-fcgi
将以下内容粘贴进去:
#!/bin/sh### BEGIN INIT INFO# Provides: php5-fcgi# Required-Start: $remote_fs $syslog# Required-Stop: $remote_fs $syslog# Default-Start: 2 3 4 5# Default-Stop: 0 1 6# Short-Description: PHP5 FastCgi Spawned processes### END INIT INFOCOMMAND=/usr/bin/spawn-fcgiADDRESS=127.0.0.1PORT=9000USER=www-dataGROUP=www-dataPHPCGI=/usr/bin/php-cgiSOCKET=/var/run/php-fastcgi/php-fastcgi.socketPIDFILE=/var/run/php-fastcgi/fastcgi-php.pidRETVAL=0PHP_FCGI_MAX_REQUESTS=500PHP_FCGI_CHILDREN=2start() { export PHP_FCGI_MAX_REQUESTS PHP_FCGI_CHILDREN $COMMAND -a $ADDRESS -p $PORT -u $USER -g $GROUP -f $PHPCGI -P $PIDFILE}stop() { /usr/bin/killall -9 php-cgi}case "$1" in start) start RETVAL=$? ;; stop) stop RETVAL=$? ;; restart|reload) stop start RETVAL=$? ;; *) echo "Usage: fastcgi {start|stop|restart}" exit 1 ;;esacexit $RETVAL
init.d目录下的文件需要更新才可以启动生效:
sudo update-rc.d php7.0-fcgi defaultssudo ./php7.0-fcgi start
完成,总结的比较潦草,因为没做笔记的习惯,不过有时间我就会马上写得详细点,有问题联系QQ 794687485