centos配置安装lnmp

1,查看环境:

1 # cat /etc/redhat-release
2 CentOS release 6.5 (Final)

2,关掉防火墙:

# chkconfig iptables off

 

  查看防火墙状态

  

/etc/init.d/iptables status

 

 

3:配置CentOS 6.0 第三方yum源(CentOS默认的标准源里没有nginx软件包)

#wget http://www.atomicorp.com/installers/atomic
#sh ./atomic
#yum check-update

4:安装开发包和库文件 

yum -y install ntp make openssl openssl-devel pcre pcre-devel libpng libpng-devel libjpeg-6b libjpeg-devel-6b freetype freetype-devel gd gd-devel zlib zlib-devel gcc gcc-c++ libXpm libXpm-devel ncurses ncurses-devel libmcrypt libmcrypt-devel libxml2 libxml2-devel imake autoconf automake screen sysstat compat-libstdc++-33 curl curl-devel

5:卸载已安装的apache、mysql、php

# yum remove httpd
# yum remove mysql
# yum remove php

6:安装nginx

# yum install nginx
# service nginx start
# chkconfig --levels 235 nginx on
//设2、3、5级别开机启动

7:安装mysql

# yum install mysql mysql-server mysql-devel
# service mysqld start
# chkconfig --levels 235 mysqld on
//授权远程登录的用户名和密码
use mysql;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'newpassword' WITH GRANT OPTION;
FLUSH PRIVILEGES;

//修改本地用户名和密码
use mysql;
UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
FLUSH PRIVILEGES;

//如果遇到10060,重启

8:安装php

yum install php lighttpd-fastcgi php-cli php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-mssql php-snmp php-soap
//安装php和所需组件使PHP支持MySQL、FastCGI模式
# yum install  php-tidy php-common php-devel php-fpm php-mysql
# service php-fpm start
# chkconfig --levels 235 php-fpm on

9:配置nginx支持php

(1)不带项目名

server {
        listen       80;
        server_name  10.10.17.198;
        root   /usr/share/nginx/html/project;
        #autoindex on;
        index index.php;
 
        location / {
 
            try_files $uri $uri/ /index.php;
 
            location = /index.php {
 
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_param  SCRIPT_FILENAME /usr/share/nginx/html/project$fastcgi_script_name;
                include        fastcgi_params;
        client_max_body_size 10m;
            }
        }
 
        location ~ \.php$ {
            return 444;
        }
}

(2)带项目名

server {
        listen       80;
        server_name  10.10.17.198;
        root   /usr/share/nginx/html;
        #autoindex on;
        index index.php index.html;

        error_page 404 = /project/web/404.html;
        error_page 403 = /project/web/403.html;        
 
        location /project/ {
 
            try_files $uri $uri/ /project/index.php;
 
            location = /project/index.php {
 
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_param  SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
                include        fastcgi_params;
        client_max_body_size 10m;
            }
        }
 
        location ~ \.php$ {
            return 444;
        }
}

 

备用:

        location /ci3/ {
 
            try_files $uri $uri/ /ci3/index.php;
 
            location = /ci3/index.php {
 
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_param  SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
                include        fastcgi_params;
        client_max_body_size 10m;
            }
        }  

 

10:配置php

//编辑文件php.ini,找到cgi.fix_pathinfo = 1,去掉注释

[root@CentOS ~]# vi /etc/php.ini
 
11:重启nginx php-fpm
# service nginx restart
# service php-fpm restart

12:建立info.php文件

# vi /usr/share/nginx/html/info.php
<?php
   phpinfo();
?>

13:测试nginx是否解析php

本地浏览器输入:10.10.17.198/info.php
显示php界面  环境搭建成功

 

posted on 2016-02-17 11:01  ziyi_ang  阅读(146)  评论(0编辑  收藏  举报

导航