CentOS6.5 yum安装LNMP环境

2017-11-06 15:02:55 16966

一般情况下很多人安装LNMP环境都会编译安装,特别是生产环境上,但有时候我们对要求不是特别高的,也可以用yum方式来安装,毕竟yum安装那叫简单方便啊。


1:查看环境:


[root@localhost html]# cat /etc/redhat-release

CentOS release 6.5 (Final)



2:关掉防火墙

[root@localhost html]# chkconfig iptables off


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



#wget http://www.landui.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 -y nginx

# service nginx start

# chkconfig --levels 235 nginx on

//设2、3、5级别开机启动



7:安装mysql


# yum install -y mysql mysql-server mysql-devel

# service mysqld start

# chkconfig --levels 235 mysqld on


默认mysql登录密码为空,我们设置mysql的root密码

/usr/bin/mysqladmin -u root -h node10 password 'admin123'



8:安装php


# yum install -y 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  -y php-tidy php-common php-devel php-fpm php-mysql


# service php-fpm start

# chkconfig --levels 235 php-fpm on



9:配置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

 

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默认路径



yum安装后nginx的html目录路径为:/usr/share/nginx/html


检查nginx语法:

[root@localhost nginx]# nginx -t        

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok

nginx: configuration file /etc/nginx/nginx.conf test is successful

 

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


本地浏览器输入:192.168.1.10/info.php

显示php界面  环境搭建成功



QQ截图20161016114838.jpg


提交成功!非常感谢您的反馈,我们会继续努力做到更好!

这条文档是否有帮助解决问题?

非常抱歉未能帮助到您。为了给您提供更好的服务,我们很需要您进一步的反馈信息:

在文档使用中是否遇到以下问题: