在centos6.5下搭建lnmp
1.查看环境:
[root@localhost /]# cat /etc/redhat-release CentOS release 6.5 (Final)
2.关掉防火墙(需要到国外地址下载软件包)
[root@localhost /]# chkconfig iptables off
3.配置CentOS 6.x 第三方yum源(CentOS默认的标准源里没有nginx软件包)
[root@localhost /]# wget http://www.atomicorp.com/installers/atomic [root@localhost /]# sh ./atomic [root@localhost /]# yum check-update
4.安装开发包和库文件(必备扩展)
[root@localhost /]# 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
1)
查看apache是否安装成功
[root@localhost /]# rpm -qa | grep httpd
查看apache安装文件路径
[root@localhost /]# rpm -ql httpd
2)
查看mysql是否安装成功
[root@localhost /]# rpm -qa | grep mysql
查看mysql安装文件路径
[root@localhost /]# rpm -ql mysql
3)
查看php是否安装成功
[root@localhost /]# rpm -qa | grep php
查看php安装文件路径
[root@localhost /]# rpm -ql php
卸载已安装的apache、mysql、php
[root@localhost /]# yum remove httpd [root@localhost /]# yum remove mysql [root@localhost /]# yum remove php
6.安装nginx,并且设2、3、5级别开机启动
[root@localhost /]# yum install nginx [root@localhost /]# service nginx start [root@localhost /]# chkconfig --levels 235 nginx on
7.安装mysql,并且设2、3、5级别开机启动
[root@localhost /]# yum install mysql mysql-server mysql-devel [root@localhost /]# service mysqld start [root@localhost /]# chkconfig --levels 235 mysqld on
登陆MySQL删除空用户,修改root密码
mysql>select user,host,password from mysql.user;
mysql>drop user ''@localhost;
mysql>update mysql.user set password = PASSWORD('*********') where user='root';
mysql>flush privileges;
8.安装php和所需组件使PHP支持MySQL、FastCGI模式
[root@localhost /]# 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 [root@localhost /]# yum install php-tidy php-common php-devel php-fpm php-mysql [root@localhost /]# service php-fpm start [root@localhost /]# chkconfig --levels 235 php-fpm on
9.配置nginx支持php
1)将配置文件改为备份文件
[root@localhost /]# mv /etc/nginx/nginx.conf /etc/nginx/nginx.confbak
2)由于原配置文件要自己去写因此可以使用默认的配置文件作为配置文件,如果没有nginx默认配置文件,那么可以自己写配置文件vim /etc/nginx/nginx.conf,编辑内容参考https://www.cnblogs.com/heyongzhen/p/9157023.html
[root@localhost /]# cp /etc/nginx/nginx.conf.default /etc/nginx/nginx.conf
3)修改nginx配置文件,添加fastcgi支持
[root@localhost /]# vim /etc/nginx/nginx.conf root html; 修改为 root /usr/share/nginx/html; index index.html index.htm; 修改为 index index.php index.html index.htm; //加入index.php //将下面代码注释去掉,并修改成nginx默认路径 location ~ \.php$ { root /usr/share/nginx/html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name; include fastcgi_params; }
10.配置php,编辑文件php.ini
[root@localhost /]# vim /etc/php.ini //去掉下面代码注释 cgi.fix_pathinfo = 1
11.重启nginx和 php-fpm
[root@localhost /]# service nginx restart [root@localhost /]# service php-fpm restart
12.开启80端口
1)添加80端口
[root@localhost /]# vim /etc/sysconfig/iptables 将 -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT 添加到22端口配置的下面
2)重启防火墙
[root@localhost /]# /etc/init.d/iptables restart
13.建立info.php文件
# vim /usr/share/nginx/html/info.php <?php phpinfo(); ?>
14:测试nginx是否解析php
本地浏览器输入:http://192.168.126.140/info.php
显示php界面 环境搭建成功