1. 程式人生 > >Centos 7.4 搭建LNMP

Centos 7.4 搭建LNMP

Centos 7.4 映象  selinux 與 firewall 已關閉。

工作環境

  • 騰訊雲 1核 1GB 1Mbps 雲伺服器
  • CentOS 7.2 64位
  • 已經安裝了PHP
  • 使用putty連結伺服器

1.安裝nginx

rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm Retrieving http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

安裝nginx

yum -y install nginx

1.4 啟動nginx

     systemctl start nginx

2.安裝PHP7

2.1 安裝  epel-release 

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

2.2 安裝 php7 的 yum 源 

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

2.3 安裝php7.0

yum install -y php70w

2.4 安裝php擴充套件

yum install -y  php70w-mysql.x86_64   php70w-gd.x86_64   php70w-ldap.x86_64   php70w-mbstring.x86_64  php70w-mcrypt.x86_64

2.5 安裝 php-fpm

yum install -y php70w-fpm

3 修改配置檔案

3.1 修改nginx配置檔案,nginx配置檔案的位置在  /etc/nginx/nginx.config

vim  /etc/nginx/nginx.conf
  1. server {

  2. listen 80 default_server;

  3. listen [::]:80 default_server;

  4. # 這裡改動了,也可以寫你的域名

  5. server_name localhost;

  6. root /usr/share/nginx/html;

  7. # Load configuration files for the default server block.

  8. include /etc/nginx/default.d/*.conf;

  9. location / {

  10. # 這裡改動了 定義首頁索引檔案的名稱

  11. index index.php index.html index.htm;

  12. }

  13. error_page 404 /404.html;

  14. location = /40x.html {

  15. }

  16. error_page 500 502 503 504 /50x.html;

  17. location = /50x.html {

  18. }

  19. # 這裡新加的

  20. # PHP 指令碼請求全部轉發到 FastCGI處理. 使用FastCGI協議預設配置.

  21. # Fastcgi伺服器和程式(PHP,Python)溝通的協議.

  22. location ~ \.php$ {

  23. # 設定監聽埠

  24. fastcgi_pass 127.0.0.1:9000;

  25. # 設定nginx的預設首頁檔案(上面已經設定過了,可以刪除)

  26. fastcgi_index index.php;

  27. # 設定指令碼檔案請求的路徑

  28. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

  29. # 引入fastcgi的配置檔案

  30. include fastcgi_params;

  31. }

  32. }

3.2  修改php-fpm 配置檔案 (/etc/php-fpm.d/www.conf)

  1. user =nginx

  2. ​group=nginx

3.3 重新啟動nginx

systemctl restart nginx

3.4 啟動php-fpm

systemctl start php-fpm.service

3.5 設定服務開機自啟

  1. systemctl enable nginx

  2. systemctl enable php-fpm

4. 安裝mysql

4.1下載mysql的repo源

wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

4.2 安裝mysql-community-release-el7-5.noarch.rpm包

rpm -ivh mysql-community-release-el7-5.noarch.rpm

4.3 安裝mysql

sudo yum install -y  mysql-server

4.4 更改mysql的使用者許可權

sudo chown -R root:root /var/lib/mysql

4.5 重啟服務

systemctl restart mysql.service

4.6 登陸並修改密碼

  1. mysql -u root

  2. mysql > use mysql;

  3. mysql > update user set password=password(‘66666‘) where user=‘root‘;

  4. mysql > flush privileges;

  5. mysql > exit;

若有錯誤和疏漏,歡迎留言指正 --------------------- 本文來自 var_lin 的CSDN 部落格 ,全文地址請點選:https://blog.csdn.net/mu_mu111/article/details/80813556?utm_source=copy