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

Install Required Packages

apt-get update & upgrade
apt-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_html
mkdir /srv/www/yourdomain/logs
chown -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-data
FASTCGI_GROUP=www-data
SOCKET=/var/run/php-fastcgi/php-fastcgi.socket
PIDFILE=/var/run/php-fastcgi/php-fastcgi.pid
CHILDREN=4
PHP5=/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-fastcgi
FASTCGI_USER=www-data
FASTCGI_GROUP=www-data
PID_DIR=/var/run/php-fastcgi
PID_FILE=/var/run/php-fastcgi/php-fastcgi.pid
RET_VAL=0

case "$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(); ?>
时间: 2024-08-01 22:37:30

Deploy Nginx + Mysql + Spawn-Fcgi On Debian/ubuntu的相关文章

Install LEMP (Linux, Nginx, MySQL and PHP) Stack on Ubuntu Linux 14.04 LTS(转)

Install LEMP (Linux, Nginx, MySQL and PHP) Stack on Ubuntu Linux 14.04 LTS Nginx Installation Nginx is one of the robust web server in Linux world. Nginx is a free, open source, high performance HTTP server and reverse proxy, as weell as an IMAP/POP3

在ubuntu中用apt-get安装LEMP栈(linux+nginx+mysql+php)

在ubuntu上安装lamp大家应该都很熟悉了,但对于现在很流行的lemp栈怎么样用apt-get安装,这样介绍的文章的不多.下面我用Ubuntu 12.04 LTS为例来介绍下如何用apt-get安装这些. 为什么要用apt-get不用编译安装 用包管理除了可以方便统一的管理软件外,他还可以帮你搞定启动脚本,自动更新等一大堆麻烦的问题.其实大多数人用的编译安装,也是使用的默认编译参数,大多数定制化的东西都可以通过配置文件完成.如果你对编译的定制化比较高,甚至可以自己做一个私有源来放你自己编译的

Linux Debian 下LNMP服务器——nginx+mysql+php环境搭建及配置

昨天刚给公司服务器装了LNMP服务器环境,在这里简单记录一下过程备忘. 这里我在安装的时候是用的Dotdeb源,仅供参考. 1.导入Dotdeb源,据说Dotdeb源里的软件版本比较新. 在向源中导入Dotdeb前,我们需要先获取GnuPG key并导入: wget http://www.dotdeb.org/dotdeb.gpg cat dotdeb.gpg | apt-key add - 提示OK,表明导入成功.然后我们开始导入Dotdeb源,源列表的位置在“/etc/apt/sources

ubuntu 14.04 nginx + mysql + php源码安装

本文参考了 http://www.tuicool.com/articles/3iUNFnA  并在细节上做了一些补充.使安装过程更加顺畅. 首先要说的是ubuntu 上操作需要加sudo命令,所以在以下的命令上都要以sudo开始. 先安装一些依赖资源gcc  g++ openssl  libssl-dev (RedHat.centos才是openssl-devel) sudo apt-get install openssl sudo apt-get install libssl-dev sudo

ubuntu下搭建nginx+mysql+php-fpm站点

概述 Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器.  nginx的优势在于能以低内存高效率处理静态页面大量请求. 可以参考下:三大WEB服务器对比分析(apache ,lighttpd,nginx) PHP-FPM是为PHP内核编写的补丁,用来根据需要处理FastCGI进程的启动,停止以及重启.有点在于: 较低的内存占用率(因为nginx单独运行时不用加载整个PHP环境). 轻松地管理用户权限

服务器操作系统应该选择 Debian/Ubuntu 还是 CentOS?

服务器操作系统应该选择 Debian/Ubuntu 还是 CentOS? 其实我觉得他的大部分说法都没有错.如果你需要装一个服务器,确实首选是RH系的. 但是... 联系QQ 2880990294 电话18326835655福州精品段:59.56.66.* 适用于游戏|棋牌|菠菜|cdn布点|网站等业务 选用RH系的主要理由 其实你把回复从头看到尾,主要论点就一点: 哪个发行版,可以在长达7-10年的时间里,始终保持硬件稳定性的同时,又持续的升级补丁? 结论当然是RH!这是RH的主要卖点. 我们

centos6 LNMP的搭建(linux+nginx+mysql+php)

LNMP的搭建(linux+nginx+mysql+php) 简介 LNMP代表的就是:Linux系统下Nginx+MySQL+PHP网站服务器架构. Linux是一类Unix计算机操作系统的统称,是目前最流行的免费操作系统.代表版本有:debian.centos.ubuntu.fedora.gentoo等. Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器. Mysql是一个小型关系型数据库管理系统. PHP是一种在服务器端执行的嵌入HTML文档

Linux下OneinStack一键安装JAVA+PHP+Tomcat+Nginx+MySQL网站环境

yum -y install wget screen python #for CentOS/Redhat # apt-get -y install wget screen python #for Debian/Ubuntu wget http://aliyun-oss.linuxeye.com/oneinstack-full.tar.gz #阿里云用户下载 wget http://mirrors.linuxeye.com/oneinstack-full.tar.gz #包含源码,国内外均可下载

Debian/Ubuntu源码编译安装PHP--支持FastCGI

从 php 5.3.3 起,就可直接使用 PHP-FPM ,不再需要打补丁了.此前已写过<Linux 从源码编译安装 PHP 5> 见 http://www.linuxidc.com/Linux/2011-10/45743.htm,但是以 mod_php 模块方式,而非 FastCGI 模式运行 php ,并不适用于 Lighttpd.Nginx.LiteSpeed ,而且当时对所有模块都采用编译安装也显得过于繁琐. 一.什么是 FastCGI.PHP-FPM.FastCGI ? CGI是一种