yum安装nginx+PHP+Mysql
#mkdir /var/www/yum_repo
1、nginx安装:
在http://nginx.org/en/linux_packages.html#stable中下载CentOSX对应版本的rpm文件
把下载的nginx-release-centos-5-0.el5.ngx.noarch.rpm拷贝到yum_repo目录下
#rpm -Uvh nginx-release-centos-5-0.el5.ngx.noarch.rpm
#yum install nginx
2、mysql安装:
在http://dev.mysql.com/downloads/repo/yum/中下载CentOSX对应版本的rpm文件
把下载的mysql-community-release-el5-5.noarch.rpm拷贝到yum_repo目录下
#rpm -Uvh mysql-community-release-el5-5.noarch.rpm
#yum install -y mysql-server mysql mysql-deve
3、PHP安装:
在/var/www/yum_repo下:
Centos 5.X
#rpm -Uvh http://mirror.webtatic.com/yum/el5/latest.rpm
CentOs 6.x
#rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm
CentOs 7.X
#rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
#rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
CentOs 6.x
#rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm
CentOs 7.X
#rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
#rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
运行yum install
#yum install php55w php55w-cli php55w-common php55w-gd php55w-ldap php55w-mbstring php55w-mcrypt php55w-mysql php55w-pdo
注:如果想升级到5.6把上面的55w换成56w就可以了。
注:如果想升级到5.6把上面的55w换成56w就可以了。
安装PHP FPM
#yum install php55w-fpm
注:如果想升级到5.6把上面的55w换成56w就可以了。
注:如果想升级到5.6把上面的55w换成56w就可以了。
【开放80、3306、22端口】
- #关闭防火墙
- service iptables stop
- vi /etc/sysconfig/iptables
- #添加
- -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
- -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
- -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
- #重启防火墙
- service iptables restart
【nginx配置】
- vi /etc/nginx/nginx.conf
- #在server下找到location / 修改解析PHP文件存放的路径, 修改为:
- location / {
- root /var/www/html;
- index index.html index.htm index.php;
- }
- #root表示虚拟目录设置为/var/www/html,增加默认解析index.php
- #在server下找到location ~ /.php$ 修改php解释器FastCGI配置,修改为:
- location ~ \.php$ {
- root /var/www/html;
- fastcgi_pass 127.0.0.1:9000;
- fastcgi_index index.php;
- fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
- include fastcgi_params;
- }
- #将nginx添加到自启动中
- echo "/usr/sbin/nginx" >> /etc/rc.d/rc.local
- #将php添加到自启动中
- echo "/usr/sbin/php-fpm start" >> /etc/rc.d/rc.local
【nginx虚拟主机配置】
vi /etc/nginx/nginx.conf
#在http最后一行加入
include /etc/nginx/conf.d/*.conf;
#不带url重写
- server {
- listen 80 default;
- server_name dev.localhost;
- access_log logs/dev.access.log;
- root /var/www/html;
- server_name_in_redirect off;
- location / {
- index index.html index.php;
- }
- location ~ \.php$ {
- fastcgi_pass 127.0.0.1:9000;
- fastcgi_index index.php;
- fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
- include fastcgi_params;
- }
- }
#带url重写(zend framework)
- server {
- listen 80;
- server_name dev.localhost;
- access_log logs/dev.access.log;
- root /var/www/html;
- location / {
- index index.html index.php;
- if (-e $request_filename ) {
- break;
- }
- if ( $request_filename ~* \.(js|ico|gif|jpg|jpeg|xml|swf|txt|png|css|html|htm)$ ) {
- return 404;
- }
- rewrite .* index.php;
- }
- location ~ .*\.php$ {
- include fastcgi_params;
- fastcgi_param SCRIPT_FILENAME $document_root/index.php;
- #fastcgi_param REQUEST_URI $document_uri?$query_string;
- fastcgi_read_timeout 120;
- fastcgi_pass 127.0.0.1:9000;
- fastcgi_index index.php;
- }
- }
- #重启nginx
- /usr/sbin/nginx -s reload
- #重启php
- /usr/sbin/php-fpm restart