A-A+
CentOS6.5搭建LNMP环境
一、查看系统环境:
- # cat /etc/redhat-release
- CentOS release 6.5 (Final)
二、关闭防火墙
- #chkconfig iptables off
三、配置CentOS第三方yum源(CentOS默认的标准源里没有nginx软件包)
- #wget http://www.atomicorp.com/installers/atomic
- #sh ./atomic
- #yum check-update
四、安装开发包和库文件
- 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
五、卸载已安装的apache、mysql、php
- # yum remove httpd
- # yum remove mysql
- # yum remove php
六、安装nginx
- #yum install nginx
- #service nginx restart
- #chkconfig --levels 235 nginx on
- //设2、3、5级别nginx开机启动
七、安装mysql
- #yum install mysql mysql-server mysql-devel
- #service mysqld start
- #chkconfig --levels 235 mysqld on
- //设2、3、5级别mysql开机启动
修改mysql的root密码
- mysql> use mysql;
- mysql> UPDATE user SET password=PASSWORD('新密码')WHERE user='root';
- mysql> FLUSH PRIVILEGES;
八、安装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
九、配置nginx支持php
- # mv /etc/nginx/nginx.conf /etc/nginx/nginx.confbak
//将配置文件改为备份文件
- # cp /etc/nginx/nginx.conf.default /etc/nginx/nginx.conf
//由于原配置文件要自己去写因此可以使用默认的配置文件作为配置文件
//修改nginx配置文件,添加fastcgi支持
- # vi /etc/nginx/nginx.conf
- index index.php index.html index.htm;
- //加入index.php</code>
- 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;
- }
- //将以上代码注释去掉,并修改成nginx默认路径
十、配置PHP
- //编辑文件php.ini,在文件末尾添加cgi.fix_pathinfo = 1
- [root@CentOS ~]# vi /etc/php.ini
十一、重启nginx和php-fpm
- #service nginx restart
- #service php-fpm restart
十二、建立php.info文件
- # vi /usr/share/nginx/html/info.php
- <?php
- phpinfo();
- ?>
十三、访问localhost/php.info测试nginx是否解析php
本地浏览器输入:192.168.1.105/info.php
如果显示php界面,则环境搭建成功!
到此,centos的PHP、nginx、mysql环境搭建完毕!按以上一步步操作,一定可以成功的,更多文章请继续关注添翼博客