新聞中心
記錄下在centos 7 安裝 LNMP 環(huán)境(php7 + mysql5.7 + Nginx1.10)過(guò)程筆記。
工具
-
VMware版本號(hào) : 12.0.0

-
CentOS版本 : 7.0
一、修改 yum 源
[root@localhost ~]# rpm -Uvh https://dl.Fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
[root@localhost ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
[root@localhost ~]# rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
Webtatic:https://webtatic.com
MySQL:https://dev.mysql.com/downloa...
二、安裝 Nginx、MySQL、PHP
[root@localhost ~]# yum -y install nginx
[root@localhost ~]# yum -y install mysql-community-server
[root@localhost ~]# yum -y install php70w-devel php70w.x86_64 php70w-cli.x86_64 php70w-common.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64 php70w-pdo.x86_64 php70w-mysqlnd php70w-fpm php70w-opcache php70w-pecl-Redis php70w-pecl-mongo
三、配置
1、配置 MySQLMySQL 安裝完成之后,在 /var/log/mysqld.log 文件中給 root 生成了一個(gè)默認(rèn)密碼
通過(guò)下面的方式找到root 默認(rèn)密碼,然后登錄 MySQL 進(jìn)行修改:
[root@localhost ~]# systemctl start mysqld # 啟動(dòng) MySQL
[root@localhost ~]# grep 'temporary password' /var/log/mysqld.log # 查找默認(rèn)密碼
2017-04-10T02:58:16.806931Z 1 [Note] A temporary password is generated for root@localhost: iacFXpWt-6gJ
登錄 MySQL:
[root@localhost ~]# mysql -uroot -p'iacFXpWt-6gJ'
修改root 默認(rèn)密碼:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyPass1!';
或者:
mysql> set password for 'root'@'localhost'=password('123abc');
詳見(jiàn) MySQL 官網(wǎng)密碼策略詳細(xì)說(shuō)明:https://dev.mysql.com/doc/ref...
配置默認(rèn)編碼為 utf8:
修改 /etc/my.cnf 配置文件,在 [mysqld] 下添加編碼配置,配置完成后重啟:
[root@localhost ~]# vim /etc/my.cnf
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
[root@localhost ~]# systemctl restart mysqld # 重啟 MySQL
設(shè)置開(kāi)機(jī)啟動(dòng):
[root@localhost ~]# systemctl enable mysqld
默認(rèn)配置文件路徑:
配置文件:/etc/my.cnf
日志文件:/var/log/mysqld.log
服務(wù)啟動(dòng)腳本:/usr/lib/systemd/system/mysqld.service
socket 文件:/var/run/mysqld/mysqld.pid
2、配置 Nginx
安裝完成以后查看自己防火墻是否開(kāi)啟,如果已開(kāi)啟,我們需要修改防火墻配置,開(kāi)啟 Nginx 外網(wǎng)端口訪問(wèn)。
[root@localhost ~]# systemctl status firewalld
如果顯示 active (running),則需要調(diào)整防火墻規(guī)則的配置。
修改 /etc/firewalld/zones/public.xml文件,在zone一節(jié)中增加
保存后重新加載 firewalld 服務(wù):
[root@localhost ~]# vim /etc/firewalld/zones/public.xml
...
[root@localhost ~]# systemctl reload firewalld
修改 Nginx 配置:
[root@localhost ~]# vim /etc/nginx/nginx.conf
在 server {} 里添加:
location / {
#定義首頁(yè)索引文件的名稱
index index.php index.html index.htm;
}
# PHP 腳本請(qǐng)求全部轉(zhuǎn)發(fā)到 FastCGI處理. 使用FastCGI默認(rèn)配置.
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
配置完成重啟 Nginx:
[root@localhost ~]# systemctl start nginx # 啟動(dòng) Nginx
注:本文只是簡(jiǎn)單配置 Nginx,具體更多配置請(qǐng)自行百度。
設(shè)置開(kāi)機(jī)啟動(dòng):
[root@localhost ~]# systemctl enable nginx
3、設(shè)置開(kāi)機(jī)啟動(dòng) php-fpm:
[root@localhost ~]# systemctl enable php-fpm
[root@localhost ~]# systemctl start php-fpm # 啟動(dòng) php-fpm
四、測(cè)試
-
在
/usr/share/nginx/html文件下創(chuàng)建php文件,輸出phpinfo信息
當(dāng)前名稱:CentOS7安裝LNMP環(huán)境(PHP7+MySQL5.7+Nginx1.10)
網(wǎng)頁(yè)URL:http://m.fisionsoft.com.cn/article/dpedsgp.html


咨詢
建站咨詢
