分类: LINUX
2010-03-18 17:40:17
rpm -Uhv
rpm -Uvh
安装nginx\php\mysql\fastcgi
yum -y install nginx php mysql-server lighttpd-fastcgi php-mysql php-gd php-cgi
chkconfig nginx on
chkconfig mysqld on
service mysqld start
mysqadmin -uroot password “123456”
cp /usr/bin/spawn-fcgi /usr/bin/spawn-fcgi.back
yum remove -y lighttpd
mv /usr/bin/spawn-fcgi.back /usr/bin/spawn-fcgi
chmod 777 /usr/bin/spawn-fcgi
updatedb
locate php-cgi
locate spawn-fcgi
vi /etc/rc.local
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 10 -u nginx -g nginx -f /usr/bin/php-cgi
参数含义如下
-f 指定调用FastCGI的进程的执行程序位置,根据系统上所装的PHP的情况具体设置
-a 绑定到地址addr
-p 绑定到端口port
-s 绑定到unix socket的路径path
-C 指定产生的FastCGI的进程数,默认为5(仅用于PHP),3G以上可以50个,
-P 指定产生的进程的PID文件路径
-u和-g FastCGI使用什么身份(-u 用户 -g 用户组)运行,Ubuntu下可以使用www-data,其他的根据情况配置,如nobody、apache等
//查看PHP进程
#ps -aux |grep php
vi /etc/nginx/fastcgi_params
增加
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
vi /etc/nginx/nginx.conf
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
修改成:
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
}
location ~ \.php$ {
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
vi /etc/php.ini
doc_root=
cgi.fix_pathinfo=1
nginx虚拟主机设置(多个虚拟主机建立多个文件即可)
vi abc.conf
server {
listen 80;
server_name ;
index index.html index.htm index.php;
root /data/vhosts/abc;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
}
location ~ .*\.(css|gif|jpg|jpeg|png|bmp|swf|js)$ {
expires 7d;
}
}
service nginx restart
在不停止Nginx服务的情况下平滑变更Nginx配置
输入以下命令查看Nginx主进程号:
ps -ef | grep "nginx: master process" | grep -v "grep" | awk -F ' ' '{print $2}'
屏幕显示的即为Nginx主进程号,例如:
6302
这时,执行以下命令即可使修改过的Nginx配置文件生效:
kill -HUP 6302
四、测试
在IE地址栏输入服务器IP
看是否有欢迎界面
在/usr/share/nginx/html下面新建index.php
phpinfo();
?>
看是否有测试界面。
五、查看php进程是否运行
ps aux|grep php