You have to know...
什么是LNMP疤估?
LNMP全稱是:Linux+Nginx+Mysql+PHP
為什么要使用LNMP溪掀?
目前主流的Web服務(wù)器有三種:Apache尸执、Nginx抒痒、IIS杉允。IIS是運行在Windos環(huán)境下的膳犹,而Apache和Nginx都是運行在Linux環(huán)境下的Web服務(wù)器终蒂;Nginx相比Apache有使用更少的系統(tǒng)資源蜂林,支持更多的并發(fā)連接數(shù),性能穩(wěn)定拇泣,使用簡單等諸多優(yōu)點噪叙,輕巧而高效,體現(xiàn)出更高的效率霉翔。
下面進入安裝步驟:
1构眯、關(guān)閉SELinux和防火墻
打開SELinux文件并修改SELINUX參數(shù)
vim /etc/sysconfig/selinux
SELINUX=disabled
執(zhí)行如下命令?臨時關(guān)閉(不用重啟機器)
setenforce 0
關(guān)閉防火墻
systemctl stop firewalld.service
禁止防火墻開機啟動
systemctl disable firewalld.service
2、安裝Mysql
下載Mysql的repo源
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
安裝mysql-community-release-el7-5.noarch.rpm包
rpm -ivh mysql-community-release-el7-5.noarch.rpm
執(zhí)行安裝Mysql
yum install -y mysql-server
更改Mysql用戶權(quán)限
chown -R root:root /var/lib/mysql
重啟服務(wù)
systemctl restart mysql.service
查看Mysql是否開啟
systemctl status mysql.service
登陸Mysql并修改密碼
mysql -u root
mysql > use mysql;
mysql > update user set password=password(‘123456‘) where user=‘root‘;
mysql >? GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
mysql > flush privileges;
mysql > exit;
設(shè)置Mysql開機啟動
systemctl enable mysqld.service
3早龟、安裝Nginx
下載對應(yīng)當前系統(tǒng)版本的Nginx包
wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
創(chuàng)建Nginx的yum倉庫
rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm
下載并安裝Nginx
yum install -y nginx
開啟Nginx
systemctl start nginx.service
查看Nginx是否運行成功
systemctl status nginx.service
設(shè)置Nginx開機啟動
systemctl enable nginx.service
4惫霸、安裝PHP7
rpm 安裝 PHP7 相應(yīng)的 yum源
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
執(zhí)行安裝PHP
yum install -y php70w
使用PHP -V命令查看是否安裝成功(如果出現(xiàn)版本號則代表安裝成功)
php -v
安裝PHP擴展
yum install -y php70w-mysql.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64
安裝PHP-FPM
yum install -y php70w-fpm
使用PHP-FPM -V命令查看是否安裝成功(如果出現(xiàn)版本號則代表安裝成功)
php-fpm -v
開啟PHP-FPM
systemctl start php-fpm.service
設(shè)置PHP-FPM開機啟動
systemctl enable php-fpm.service
安裝Redis擴展
yum install?-y php70w-pecl-redis
安裝OPcache擴展
yum install?-y php70w-opcache
5、修改Nginx配置文件
打開配置文件
vim /etc/nginx/conf.d/default.conf
修改如下(去掉# 參考root目錄和fastcgi_param參數(shù))
location ~.php$ {
? ? root ? ? ? ? ? ? ? ? ? ? /usr/share/nginx/html;
? ? ?fastcgi_pass ? ? ? 127.0.0.1:9000;
? ? ?fastcgi_index ? ? ? index.php;
?????fastcgi_param ? ? ?SCRIPT_FILENAME $document_root$fastcgi_script_name;
? ? ?include ? ? ? ? ? ? ? ? fastcgi_params;
? }
重啟Nginx服務(wù)
systemctl restart nginx.service
再次查看Nginx是否運行成功
systemctl status nginx.service
6葱弟、最后安裝FTP上傳PHP文件測試效果
安裝FTP
yum install -y vsftpd
開啟FTP
systemctl start vsftpd.service
設(shè)置FTP開機啟動
systemctl enable vsftpd.service
新建用戶
adduser test
為用戶設(shè)置密碼
passwd test
給Nginx網(wǎng)站根目錄設(shè)置權(quán)限
chmod -R 777 /usr/share/nginx/html
使用剛剛新建的用戶上傳一個PHP文件壹店,如果訪問成功則證明LNMP環(huán)境已部署成功。
有可能出現(xiàn)的問題
Centos7上默認是安裝了Vi編輯器芝加,但Vim編輯器是未安裝或者是未完全安裝的硅卢;但Vim功能是要比Vi要強大的射窒,那么如果我們要安裝Vim編輯器應(yīng)該怎么做呢?
第一步:檢查是否已安裝過Vim
rpm -qa|grep vim
第二步:是否出現(xiàn)完整的包名 如:
vim-minimal-7.4.160-2.el7.x86_64
第三步:運行安裝
yum -y install vim*
同理Wget也一樣
rpm -qa|grep wget
安裝
yum -y install wget
注:Centos在最小化安裝下 如果不完成這兩步是無法完成LNMP環(huán)境的搭建的将塑。