前言
本文主要介紹的是基于centos7進行yum安裝lnmp(linux+nginx+php7.1+mysql5.7)的相關教程,文中將一步步介紹的非常詳細,下面話不多說了,來一起看看詳細的介紹吧。
步驟如下:
yum的安裝
1
|
yum update |
yum安裝nginx
安裝nginx最新源
1
2
|
yum localinstall http: //nginx .org /packages/centos/7/noarch/RPMS/nginx-release-centos-7-0 .el7.ngx.noarch.rpm yum repolist enabled | grep "nginx*" |
安裝nginx
1
|
yum -y install nginx |
啟動nginx
1
|
service nginx start |
設置nginx服務器開機自啟動
1
|
systemctl enable nginx.service |
檢查開機自動是否設置成功
1
|
systemctl list-dependencies | grep nginx |
瀏覽器中輸入公網ip,檢測是否安裝成功
1
|
http://00.00.00.00/ |
使用yum安裝mysql5.7
安裝mysql源
1
2
|
yum -y localinstall http: //dev .mysql.com /get/mysql57-community-release-el7-7 .noarch.rpm yum repolist enabled | grep "mysql.*-community.*" |
安裝mysql
1
|
yum -y install mysql-community-server install mysql-community-devel |
啟動mysql
1
|
service mysqld start |
檢查mysql啟動是否正常
1
|
service mysqld status 或者 ps -ef | grep mysql |
設置mysqld服務開機自啟動
1
|
systemctl enable mysqld.service |
檢查mysqld開機自啟動是否設置成功
1
|
systemctl list-dependencies | grep mysqld |
mysql5.7以后的爭強了安全機制, 所以使用yum安裝,啟動會系統會自動生成一個隨機的密碼,修改mysql密碼
查看mysql的隨機密碼
1
|
grep 'temporary password' /var/log/mysqld .log |
使用查詢得到的隨機密碼在終端登錄
1
2
|
mysql -u root -p 更改密碼(mysql文檔規定,密碼必須包括大小寫字母數字加特殊符號>8位) ALTER USER 'root' @ 'localhost' IDENTIFIED BY 'Yourpassword' ; |
退出mysql客戶端,用剛才修改的密碼登錄確保密碼修改成功
1
2
|
exit ; mysql -u root -p |
安裝php7.1
安裝php源
1
2
|
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 |
檢查源是否安裝成功
1
|
yum repolist enabled | grep "webtatic*" |
安裝php擴展源
1
2
3
4
|
yum -y install php71w php71w-fpm yum -y install php71w-mbstring php71w-common php71w-gd php71w-mcrypt yum -y install php71w-mysql php71w-xml php71w-cli php71w-devel yum -y install php71w-pecl-memcached php71w-pecl-redis php71w-opcache |
驗證php7.1.x和擴展是否安裝成功
驗證php是否安裝成功
1
|
php - v |
驗證對應的擴展是否安裝成功
1
|
php -m |
設置php-fpm并檢測php-fpm的運行狀態
啟動php-fpm
1
|
service php-fpm star |
檢查啟動是否成功
1
|
service php-fpm status |
設置開機自啟動
1
|
systemctl enable php-fpm.service |
檢查開機自啟動是否設置成功
1
2
|
systemctl list-dependencies | grep php-fpm ps -ef | grep php-fpm |
nginx配置如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
server{ listen 80; server_name youserver; index index.html index.php; root /home/public ; #charset koi8-r; #access_log logs/host.access.log main; location / { index index.html index.htm index.php; try_files $uri $uri/ /index .php?$query_string; } error_page 404 /404 .html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x .html; location = /50x .html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ .php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ .php$ { root /home/public ; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /home/public $fastcgi_script_name; include fastcgi_params; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # location ~ /.ht { deny all; } } |
總結
以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,如果有疑問大家可以留言交流,謝謝大家對服務器之家的支持。
原文鏈接:https://segmentfault.com/a/1190000013842789