参考文档:
过程
####################设定升级源####################
cd /etc/yum.repos.d/
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.orig
sed -i -e 's/mirrorlist/#mirrorlist/' CentOS-Base.repo
sed -i -e 's/#baseurl/baseurl/' CentOS-Base.repo
sed -i -e 's/mirror.centos.org/lt.mirrors.sohu.com/' CentOS-Base.repo
vi centos.21andy.com.repo
[21Andy.com]
name=21Andy.com Packages for Enterprise Linux 5 - $basearch
baseurl=
enabled=1
gpgcheck=0
protect=1
rpm -ihv
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
yum -y update
#安装工具
yum install -y wget unzip mlocate ntp
#安装vim-enhanced
yum install -y vim-enhanced
#设置高亮
vi ~/.bashrc
添加:alias vi='vim'
#安装nginx和php扩展,mysql等等!
yum install -y nginx-stable mysql-server
yum install -y php-fpm php-cli php-pdo php-mysql php-mcrypt php-mbstring php-gd php-tidy php-xml
yum install -y php-xmlrpc php-pear php-pecl-memcache php-eaccelerator
(千万注意:这个时候没有安装php!!!!
rpm -qa|grep php
php-pdo-5.3.2-2.el5
php-gd-5.3.2-2.el5
php-xml-5.3.2-2.el5
php-mbstring-5.3.2-2.el5
php-cli-5.3.2-2.el5
php-eaccelerator-0.9.6-1.el5
php-pecl-memcache-2.2.5-3.el5
php-common-5.3.2-2.el5
php-mysql-5.3.2-2.el5
php-fpm-5.3.2-2.el5
php-tidy-5.3.2-2.el5
php-mcrypt-5.3.2-2.el5
php-xmlrpc-5.3.2-2.el5
php-pear-1.9.0-1.el5
)
#启动各项服务。
service mysqld start
service php-fpm start
service nginx start
#设置服务开机启动
chkconfig --level 345 mysqld on
chkconfig --level 345 php-fpm on
chkconfig --level 345 nginx on
#########检查端口
netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 2909/php-cgi
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2860/mysqld
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 2930/nginx.conf
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2595/sshd
#########设定防火墙:
添加一句:-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
但是:这句必须在
-A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited
之前添加!
这么样会错的
echo "-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT" >> /etc/sysconfig/iptables
#重启iptables
service iptables restart
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
用脚本的话,就这样:
用cat -b /etc/sysconfig/iptables发现要添加在18行之后:
18 -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
于是:
sed -i.bak '18 a\-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT' /etc/sysconfig/iptables
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
这个时候访问已经能够访问到index.html静态页面了。但是,尚需要做进一步设置才能解析php!!!!
现在就去访问
/info.php会把这个php文件给下载下来----这个时候即使去安装php包也无效!!!
而后检查端口做一个标记:
检查1)
netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 2909/php-cgi
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2860/mysqld
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 2930/nginx.conf
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2595/sshd
检查2)
ps auxww | grep cgi
root 2909 0.0 0.8 255228 4484 ? Ss 19:22 0:00 /usr/bin/php-cgi --fpm --fpm-config /etc/php-fpm.conf
nobody 2910 0.0 0.8 255228 4356 ? S 19:22 0:00 /usr/bin/php-cgi --fpm --fpm-config /etc/php-fpm.conf
nobody 2911 0.0 0.8 255228 4356 ? S 19:22 0:00 /usr/bin/php-cgi --fpm --fpm-config /etc/php-fpm.conf
nobody 2912 0.0 0.8 255228 4356 ? S 19:22 0:00 /usr/bin/php-cgi --fpm --fpm-config /etc/php-fpm.conf
nobody 2913 0.0 0.8 255228 4356 ? S 19:22 0:00 /usr/bin/php-cgi --fpm --fpm-config /etc/php-fpm.conf
nobody 2914 0.0 0.8 255228 4356 ? S 19:22 0:00 /usr/bin/php-cgi --fpm --fpm-config /etc/php-fpm.conf
root 3104 0.0 0.1 61148 776 pts/0 S+ 19:34 0:00 grep cgi
检查3)
ps auxww | grep nginx
root 2930 0.0 0.7 66988 3916 ? Ss 19:23 0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx 3092 0.0 0.5 67176 2932 ? S 19:33 0:00 nginx: worker process
nginx 3093 0.0 0.5 67176 2932 ? S 19:33 0:00 nginx: worker process
nginx 3094 0.0 0.5 67176 2932 ? S 19:33 0:00 nginx: worker process
nginx 3095 0.0 0.6 67176 3124 ? S 19:33 0:00 nginx: worker process
nginx 3096 0.0 0.5 67176 2932 ? S 19:33 0:00 nginx: worker process
nginx 3097 0.0 0.5 67176 2932 ? S 19:33 0:00 nginx: worker process
nginx 3098 0.0 0.5 67176 2932 ? S 19:33 0:00 nginx: worker process
nginx 3099 0.0 0.5 67176 2932 ? S 19:33 0:00 nginx: worker process
nginx 3100 0.0 0.5 67176 2932 ? S 19:33 0:00 nginx: worker process
nginx 3101 0.0 0.5 67176 2932 ? S 19:33 0:00 nginx: worker process
root 3106 0.0 0.1 61148 776 pts/0 S+ 19:36 0:00 grep nginx
重点是配置文件:nginx.conf。它的位置在:/etc/nginx/nginx.conf
nginx还“附赠”了一个配置文件备份:/etc/nginx/nginx.conf.default。
我把cd /etc/nginx/nginx.conf中的这段给启用了:
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;
}
但是访问:
提示:No input file specified.
(网上搜了一下,这是一个很经典的错误!!!)
后来将
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
改成了
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
~~~~~~~~~~~~~~~~~~~~~
千万注意:
1、有的文档说:
要在php.ini中将cgi.fix_pathinfo=1的注释给取消掉。
但是参考这里:http://www.afen.cn/blog/?p=379
还是屏蔽掉它为安全!!!!
参考:
; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI. PHP's
; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok
; what PATH_INFO is. For more information on PATH_INFO, see the cgi specs. Setting
; this to 1 will cause PHP CGI to fix its paths to conform to the spec. A setting
; of zero causes PHP to behave as before. Default is 1. You should fix your scripts
; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.
;
cgi.fix_pathinfo=1
2、虽然php解析成功了。
但是我们应该在fastcgi_param的头部添加如下6行为宜(曹头给的^_^):
###
if ($request_filename ~* (.*)\.php) {
set $php_url $1;
}
if (!-e $php_url.php) {
return 403;
}
###后面是默认内容
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 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-redirect
#fastcgi_param REDIRECT_STATUS 200;
尾声:
现在是2010年7月19日晚8时。算是首次正式配置nginx+fastcgi+php了。费了大约8个小时时间。
最开始是因为第一次需要yum升级,安装工具软件等原因。
回忆了一下:
第一次nginx解析php障碍的原因可能是:
1、没有安装php!只安装了一堆扩展!!!
2、有一个必须要设置:
启用location ~ \.php$段后还要将
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
改成:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
3、无意中发现:如果是killall -HUP nginx,是可以平滑启动nginx。但是无法检查出nginx.conf配置文件的错误。
比如说将document_root写成了documnet_root!!!
#############以上是安装篇。下一步是进行基本的配置#######################################
阅读(3367) | 评论(0) | 转发(0) |