CentOS搭建LNMP環境


1:查看環境:

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

2:關掉防火牆

1 #開機禁用
2 [root@localhost ~]# chkconfig iptables off
3 ///centos7 systemctl disable firewalld
4 or
5 
6 #即時生效,重啟后失效
7 [root@localhost ~]# service iptables stop
///centos7 systemctl start firewalld

關閉selinux

#即時生效,重啟后失效
[root@localhost ~]#setenforce 0

 //將SELINUX=enforcing修改為disabled然后重啟生效
[root@localhost ~]# vi /etc/selinux/config        

3.配置CentOS 6.7 第三方yum源(CentOS默認的標准源里沒有nginx軟件包)

1 [root@localhost ~]#wget http://www.atomicorp.com/installers/atomic
2 
3 [root@localhost ~]#sh ./atomic
4 
5 [root@localhost ~]#yum check-update

4:安裝開發包和庫文件

1 #注意不要換行
2 [root@localhost ~]#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 nginx
# service nginx start
///centos7 systemctl status nginx.service # chkconfig
--levels 235 nginx on //設2、3、5級別開機啟動
///
centos7 systemctl enable nginx.service

7:安裝mysql

# yum install mysql mysql-server mysql-devel
# service mysqld start
# chkconfig --levels 235 mysqld on
//登陸MySQL刪除空用戶,修改root密碼
mysql>select user,host,password from mysql.user;
 
mysql>drop user ''@localhost;
 
mysql>update mysql.user set password = PASSWORD('your password') where user='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
# 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配置文件server段,添加fastcgi支持
# vi /etc/nginx/nginx.conf
//加入index.php
index index.php index.html index.htm;

//將下列代碼注釋去掉,並修改成nginx默認路徑
location ~ \.php$ {
            root           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;
        }

     

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.32.164/info.php
顯示phpinfo界面 環境搭建成功



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM