yum搭建lnmp環(huán)境(CentOS6.5)
在CentOS6.3下實(shí)踐通過。
1.關(guān)閉防火墻
[root@CentOS ~]# chkconfig iptables off
2.關(guān)閉selinux
vi /etc/sysconfig/selinux
//將SELINUX=enforcing修改為disabled然后重啟生效
3、配置CentOS 6.0 第三方y(tǒng)um源(CentOS默認(rèn)的標(biāo)準(zhǔn)源里沒有nginx軟件包)
[root@CentOS ~]# yum install wget
//下載wget工具
[root@CentOS ~]# wget http://www.atomicorp.com/installers/atomic
//下載atomic yum源
[root@CentOS ~]# sh ./atomic
//安裝提示輸入時(shí)輸yes
[root@CentOS ~]# yum check-update
//更新yum軟件包
4.安裝開發(fā)包和庫文件
[root@CentOS ~]# 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
[root@CentOS ~]# yum remove httpd
[root@CentOS ~]# yum remove mysql
[root@CentOS ~]# yum remove php
6.安裝nginx
[root@CentOS ~]# yum install nginx
[root@CentOS ~]# service nginx start
[root@CentOS ~]# chkconfig --levels 235 nginx on
//設(shè)2、3、5級別開機(jī)啟動
7.安裝mysql
[root@CentOS ~]# yum install mysql mysql-server mysql-devel
[root@CentOS ~]# service mysqld start
[root@CentOS ~]# chkconfig --levels 235 mysqld on
[root@CentOS ~]# mysqladmin -u root password "123456"
//為root用戶設(shè)置密碼
[root@CentOS ~]# service mysqld restart
//重啟mysql
8.安裝php
[root@CentOS ~]# 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-tidy php-common php-devel php-fpm
//安裝php和所需組件使PHP支持MySQL、FastCGI模式
[root@CentOS ~]# service php-fpm start
[root@CentOS ~]# chkconfig --levels 235 php-fpm on
9.配置nginx支持php
[root@CentOS ~]# mv /etc/nginx/nginx.conf /etc/nginx/nginx.confbak
//將配置文件改為備份文件
[root@CentOS ~]# cp /etc/nginx/nginx.conf.default /etc/nginx/nginx.conf
//由于原配置文件要自己去寫因此可以使用默認(rèn)的配置文件作為配置文件
//運(yùn)城網(wǎng)站建設(shè)修改nginx配置文件,添加fastcgi支持
[root@CentOS ~]# 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默認(rèn)路徑
10.配置php
//編輯文件php.ini,在文件末尾添加cgi.fix_pathinfo = 1
[root@CentOS ~]# vi /etc/php.ini
11.重啟nginx php-fpm
[root@CentOS ~]# service nginx restart
[root@CentOS ~]# service php-fpm restart
12.建立info.php文件
[root@CentOS ~]# vi /usr/share/nginx/html/info.php
<?php
phpinfo();
?>
13.測試nginx是否解析php
輸入:192.168.1.105/info.php
顯示php界面說明解析成功