centos 6.5搭建LNMP环境

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源(EPEL)


4:安装开发包和库文件 

1
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、mysql、php

1
2
3
# yum remove httpd
# yum remove mysql
# yum remove php


6:安装nginx

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


7:安装mysql

1
2
3
# yum install mysql mysql-server mysql-devel
# service mysqld start
# chkconfig --levels 235 mysqld on



1
2
3
4
5
6
7
8
登陆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

1
2
# 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模式

1
#yum install  php-tidy php-common php-devel php-fpm php-mysql



1
2
# service php-fpm start
# chkconfig --levels 235 php-fpm on


9:配置nginx支持php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 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,将以下代码注释去掉,并修改成nginx默认路径
location ~ \.php$ {
            fastcgi_pass    127.0.0.1:9000;
            fastcgi_index   index.php;
            #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            fastcgi_param   SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include         fastcgi_params;
        }


10:配置php

1
2
//编辑文件php.ini,在文件末尾添加cgi.fix_pathinfo = 1
[root@Centos ~]# vi /etc/php.ini


11:重启nginx php-fpm

1
2
# service nginx restart
# service php-fpm restart


12:建立info.php文件

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


13:测试nginx是否解析php

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


这种软件包安装方式虽然简单,但版本较低,而且软件分布在/usr/下各个目录中,有些混乱,建议官方下载最新的稳定版源码,configure --prefix=/opt/software_name 来编译安装到一个目录下,便于管理。

posted @ 2014-11-20 21:59  colben  阅读(175)  评论(0编辑  收藏  举报