CentOS6.5 搭建 LNMP (linux + nginx + mysql + php)

前端之家收集整理的这篇文章主要介绍了CentOS6.5 搭建 LNMP (linux + nginx + mysql + php)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1:查看环境:

1
2
[root@10-4-14-168 html]# cat /etc/redhat-release
CentOS release 6.5 (Final)

2:关掉防火墙

1
[root@10-4-14-168 html]# chkconfig iptables off

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

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

4:安装开发包和库文件 

2
3
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、MysqLPHP

3
# 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
--levels 235 MysqLd on
4
5
6
7
8
登陆MysqL删除用户修改root密码
MysqL> select user ,host, password from MysqL. ;
drop user @H_301_245@'' @localhost;
update user set password = PASSWORD ( @H_301_245@'*********' ) where = @H_301_245@'root' ;
MysqL>flush privileges ;

  

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
--levels 235 PHP-fpm on

9:配置Nginx支持PHP

8
9
10
11
12
13
14
15
16
17
18
19
# mv /etc/Nginx/Nginx.conf /etc/Nginx/Nginx.confbak
/ / 配置文件改为备份文件
# cp /etc/Nginx/Nginx.conf.default /etc/Nginx/Nginx.conf
由于原配置文件要自己去写因此可以使用默认的配置文件作为配置文件
@H_624_404@修改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 html$fastcgi_script_name;
include fastcgi_params;
}
将以上代码注释去掉,并修改Nginx默认路径

1

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.105/info.PHP
显示PHP界面 环境搭建成功

转自:http://www.cnblogs.com/xiaoit/p/3991037.html

猜你在找的CentOS相关文章