以下流程測(cè)試兩遍乏屯,沒(méi)問(wèn)題啊终。如有問(wèn)題請(qǐng)回復(fù)提問(wèn)
準(zhǔn)備工作
配置防火墻
開(kāi)啟80端口部默、3306端口
刪除原有的 iptables , 添加合適的配置
rm -rf /etc/sysconfig/iptables
vi /etc/sysconfig/iptables
添加如下內(nèi)容 :
################################ 添加好之后防火墻規(guī)則如下所示################################
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
#######################################################################################
:wq
保存退出, 重啟防火墻使配置生效
/etc/init.d/iptables restart
關(guān)閉SELINUX
rm -rf /etc/selinux/config
vi /etc/selinux/config
添加一行內(nèi)容:
SELINUX=disabled
:wq
保存退出
重啟系統(tǒng)
shutdown -r now
安裝第三方y(tǒng)um源
#安裝下載工具
yum install wget
#下載
wget http://www.atomicorp.com/installers/atomic
wget http://www.atomicorp.com/installers/atomic
#安裝
sh ./atomic
sh ./atomic
#更新yum源
yum check-update
開(kāi)始安裝
安裝nginx
#刪除系統(tǒng)自帶的軟件包
yum remove httpd* php*
#安裝nginx
yum install -y nginx
#設(shè)置nginx開(kāi)機(jī)啟動(dòng)
chkconfig nginx on
#啟動(dòng)nginx
service nginx start
創(chuàng)建用戶組帽蝶,執(zhí)行:
/usr/sbin/groupadd -f nginx
/usr/sbin/useradd -g nginx nginx
安裝nginx
安裝PHP
檢查當(dāng)前安裝的PHP包
yum list installed | grep php
如果有安裝的PHP包,先刪除他們, 如:
yum remove php.x86_64 php-cli.x86_64 php-common.x86_64
配置安裝包源:
# Centos 5.X
rpm -Uvh http://mirror.webtatic.com/yum/el5/latest.rpm
# CentOs 6.x
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm
# CentOs 7.X
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
webtatic
如果想刪除上面安裝的包纯赎,重新安裝
rpm -qa | grep webstatic
rpm -e [上面搜索到的包即可]
執(zhí)行安裝PHP
yum -y install php56w.x86_64
yum -y --enablerepo=webtatic install php56w-devel
yum -y install php56w-gd.x86_64 php56w-ldap.x86_64 php56w-mbstring.x86_64 php56w-mcrypt.x86_64 php56w-mysql.x86_64 php56w-pdo.x86_64 php56w-opcache.x86_64
安裝PHP FPM
yum -y install php56w-fpm
#設(shè)置php-fpm開(kāi)機(jī)啟動(dòng)
chkconfig php-fpm on
#啟動(dòng)php-fpm
/etc/init.d/php-fpm start
安裝PHP FPM
安裝 MySQL
安裝
yum install -y mysql mysql-server
#啟動(dòng)MySQL
/etc/init.d/mysqld start
/etc/init.d/mysqld start
#設(shè)為開(kāi)機(jī)啟動(dòng)
chkconfig mysqld on
#拷貝配置文件(注意:如果/etc目錄下面默認(rèn)有一個(gè)my.cnf谦疾,直接覆蓋即可)
cp /usr/share/mysql/my-medium.cnf /etc/my.cnf
為root賬戶設(shè)置密碼
mysql_secure_installation
# 回車,根據(jù)提示輸入Y犬金,輸入2次密碼念恍,回車,根據(jù)提示一路輸入Y
# 最后出現(xiàn):Thanks for using MySQL!
# MySql密碼設(shè)置完成
Thanks for using MySQL
#重啟
/etc/init.d/mysqld restart
#停止
/etc/init.d/mysqld stop
#啟動(dòng)
/etc/init.d/mysqld start
image.png
配置
配置nginx
rm -rf /etc/nginx/conf.d/*
vi /etc/nginx/conf.d/default.conf
添加如下內(nèi)容
server{
listen 80;
server_name _;
index index.php index.html index.htm;
root /data/www/wwwroot/default;
location ~ .*\.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
}
}
說(shuō)明:
/data/www/wwwroot/default
為web根目錄, location / ... 為url的rewrite,隱藏 index.php
配置php-fpm
vi /etc/php-fpm.d/www.conf
將用戶和用戶組設(shè)置為nginx, 如:
#修改用戶為nginx
user = nginx
#修改組為nginx
group = nginx
開(kāi)始測(cè)試
mkdir /data
mkdir /data/www
mkdir /data/www/wwwroot
mkdir /data/www/wwwroot/default
cd /data/www/wwwroot/default
vi index.php
添加以下代碼
<?php
phpinfo();
?>
:wq
保存退出
#設(shè)置權(quán)限
chown nginx.nginx /data/www/wwwroot -R
#重啟nginx
service nginx restart
#重啟php-fpm
service php-fpm restart
在客戶端瀏覽器輸入服務(wù)器IP地址(如: 127.0.0.1)晚顷,可以看到相關(guān)的配置信息峰伙!
說(shuō)明lnmp配置成功!
配置信息
使用PHPMyAdmin報(bào)錯(cuò):Error during session start; please check your PHP and/or webserver log file and configure your PHP installation properly. Also ensure that cookies are enabled in your browser.
查看此文章:http://www.reibang.com/p/94c250325db7