buntu 9.10 安装nginx + fastcgi + spawn-fcgi +mysql

buntu 9.10 安装nginx + fastcgi + spawn-fcgi +mysql 日记

1.安装nginx

运行:
sudo apt-get intsall nginx
Ubuntu安装之后的文件结构大致为:
* 所有的配置文件都在/etc/nginx下,并且每个虚拟主机已经安排在了/etc/nginx/sites-available下
* 程序文件在/usr/sbin/nginx
* 日志放在了/var/log/nginx中
* 并已经在/etc/init.d/下创建了启动脚本nginx
* 默认的虚拟主机的目录设置在了/var/www/nginx-default

下面可以启动nginx来看看效果(请确保80端口没有其他服务在使用):
Ubuntu请运行:
sudo /etc/init.d/nginx start
然后打开浏览器,查看http://localhost/ 看看是否看到了“Welcome to nginx!” 如果看到了,说明安装成功。当然,基本上,这块儿都不会出问题。
如果运行不成功,可以先 sudo killall apache2 杀掉apache进程
2.安装php:
当然,现在我们都用php5了。运行:
sudo apt-get install php5 php5-cgi php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-pspell php5-recode php5-snmp php5-tidy php5-xmlrpc php5-sqlite php5-xsl

3.安装spawn-fcgi
运行sudo apt-get install spawn-fcgi
为什么要安装spawn-fcgi呢,它用来控制php-cgi进程,以防止进程崩溃或是单进程的效率太低。
网上很多人都说要使用spawn-fcgi必须得安装lighttpd,实际上不必要,可以直接安装spawn-fcgi

接下来就是最让人头疼的配置。
配置Nginx和spawn-fcgi配合运行
(1).在/etc/nginx/fastcgi_params 文件最后,加入一行,可以用sudo gedit /etc/nginx/fastcgi_params打开文件
加入此行:fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

(2).另外需要在PHP-CGI的配置文件(Ubuntu 上此配置文件位于/etc/php5/cgi/php.ini)中,找到cgi.fix_pathinfo选项,修改为:
cgi.fix_pathinfo=1;
这样php-cgi方能正常使用SCRIPT_FILENAME这个变量。

(3).打开/etc/nginx/sites-available/default文件

server {
listen 80;
server_name localhost;

下面添加
root /var/www/nginx-default
即root和server_name同级
这段即相当于apache的默认目录 如果没有这个的话,容易在执行php 文件的时候,会提示”No input file specified”。我就曾在此绕了好大个圈子才发现问题。

然后修改
#location ~ \.php$ {
#fastcgi_pass 127.0.0.1:9000;
#fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
#includefastcgi_params;
#}

修改成

location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /var/www/nginx-default$fastcgi_script_name; 这段没啥用了,留在这儿做个提醒而已
include /etc/nginx/fastcgi_params; #fastcgi的参数文件地址
}

nginx上的参考文档地址:http://wiki.nginx.org/NginxFullExample

然后运行
sudo /usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid
来启动fast-cgi进程,然后我们可以将这行代码加入到/etc/rc.local文件底部,这样系统启动的时候也可以同时启动PHP的FastCGI进程。

再运行sudo /etc/init.d/nginx restart 重启nginx
如果出现:
Restarting nginx: [emerg]: unexpected end of file, expecting ";" or "}" in /etc/nginx/fastcgi_params:25

configuration file /etc/nginx/nginx.conf test failed
我就出现这种情况,是/etc/nginx/fastcgi_params文件第25行少了一个;号,加上即可

好了,可以把你的php文件放在/var/www/nginx-default下面来测试一下了。

 

如果打开php文件出现:No input file specified
请检查
php.ini的配置中
cgi.fix_pathinfo=1
doc_root=
还有,每个虚机要根据自己不通的虚机设置不能的目录,要保证这个路径正确。
检查/etc/nginx/sites-available下的配置文件中,server内包含 root 及地址 而非location内的root

附重启nginx和php-cgi 的命令

nginx: sudo /etc/init.d/nginx restart 同样也可以有start,stop等参数
php-cgi: 先杀死进程
sudo killall -HUP php5-cgi
再启动
sudo /usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid

参数含义如下

* -f 指定调用FastCGI的进程的执行程序位置,根据系统上所装的PHP的情况具体设置
* -a 绑定到地址addr
* -p 绑定到端口port
* -s 绑定到unix socket的路径path
* -C 指定产生的FastCGI的进程数,默认为5(仅用于PHP)
* -P 指定产生的进程的PID文件路径
* -u和-g FastCGI使用什么身份(-u 用户 -g 用户组)运行,Ubuntu下可以使用www-data,其他的根据情况配置,如nobody、apache等
———————————-
如果要安装zendOptimizer
先去zend官网下载,地址http://www.zend.com/en/products/guard/downloads
找对应你操作系统的zendOptimizer,如果下载过程中要求注册,而你没有注册过,那就不防注册一次,一劳永逸。
然后解压,打开data文件夹,再找出对应你php版本的so文件。基本上现在都是php5.2了,所以在5_2_x_comp/ZendOptimizer.so
可以把这个文件放在任何位置,只要在php.ini中指定出绝对位置就行。
比如我们将其放在/usr/local下面。
sudo mkdir /usr/local/zend //按提示输入密码
在你解压出的文件夹内,执行
sudo cp ZendOptimizer.so /usr/local/zend
将这个文件拷过去。
编辑php.ini ,在终端输入
sudo gedit /etc/php5/cgi/php.ini
在文件末尾加入
[Zend Optimizer]
zend_optimizer.optimization_level=1
zend_extension=”/usr/local/zend/ZendOptimizer.so”

然后重启fastcgi
sudo killall -HUP php5-cgi
再启动
sudo /usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid
OK了。用php探针看看吧。
4、安装PHP和MySQL
sudo apt-get install mysql-server mysql-client
中间会提示输入Root用户密码,依次输入即可。

启动MySQL
sudo /etc/init.d/mysql start

mysql -uroot -p
输入mysql密码
mysql> show databases;
+——————–+
| Database |
+——————–+
| information_schema |
| mysql |
+——————–+
mysql已正确安装了。

原文地址:http://blog.sina.com.cn/s/blog_679656130100pgso.html

项目中要用到zend Optimizer,但是目前只支持php5.2,Ubuntu默认安装的php版本为5.3,找了好多 方法,终于借助下面这篇文章的方法成功的安装了5.2及5.3两个版本的php Although Drupals 7+ run smoothly on PHP 5.3, Drupal 6 still feels much better with PHP 5.2. Even though D6 core is compatible with PHP 5.3 for quite some time now, a lot of contributes modules still get nasty hiccup when asked to run on the newer version. Therefore developing for both D7 and D6 at the same time becomes much less painful when running both versions of PHP in parallel. One way of doing it is using mod_php5 Apache module to serve PHP 5.3 applications, while running PHP 5.2 applications using fastcgi module. Under Ubuntu 12.04 this can be achieved by installing PHP 5.3 from the repositories and manually compiling and installing PHP 5.2 afterwards. Installing PHP 5.3 from repositories is fairly easy process, which you most probably already have under your belt, so let's just say that it looks more or less like this: sudo apt-get install php5 php5-common php5-cli php5-dev php5-mysql phpmyadmin php5-pgsql phppgadmin php5-gd php5-mcrypt php5-curl php-pear libapache2-mod-php5 php5-xdebug php5-codesniffer What is much more interesting though, and what this post will focus on, is how to add PHP 5.2 to the whole picture and make both those versions work nicely together. Please note that this tutorial is for Apache's name- based virtual hosts, and essentially leaves PHP 5.3 enabled globally while allowing to use PHP 5.2 on specific, selected virtual hosts only.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值