雲網

 找回密碼
 立即註冊
搜索
熱搜: 活動 交友 discuz
查看: 1173|回復: 0

[實測]Centos 8 + Nginx + MySQL 8 + PHP 7.4 + phpMyAdmin 5 安裝

[複製鏈接]

75

主題

80

帖子

405

積分

超級版主

Rank: 8Rank: 8

積分
405
發表於 2020-4-11 13:03:36 | 顯示全部樓層 |閱讀模式
本帖最後由 info 於 2020-4-11 17:57 編輯

修改 hostname
  1. hostnamectl set-hostname cloud.hk
複製代碼

使用 Yum 更新
  1. sudo yum -y update
複製代碼

安裝 Nginx
  1. sudo yum install nginx -y
複製代碼

安裝完成後, 啟動 Nginx
  1. sudo systemctl start nginx
複製代碼

啟動 Centos 8 時, 自動啟動 Nginx
  1. systemctl enable nginx
複製代碼

檢查 Nginx 的狀態
  1. sudo systemctl status nginx
複製代碼
  1. # systemctl status nginx
  2. ● nginx.service - The nginx HTTP and reverse proxy server
  3.    Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor prese>
  4.    Active: active (running) since Sat 2020-04-11 04:57:45 UTC; 10s ago
  5. Main PID: 10407 (nginx)
  6.     Tasks: 2 (limit: 11510)
  7.    Memory: 3.9M
  8.    CGroup: /system.slice/nginx.service
  9.            ├─10407 nginx: master process /usr/sbin/nginx
  10.            └─10408 nginx: worker process
複製代碼

檢查 Nginx 版本
  1. nginx -v
複製代碼

結果:
  1. nginx version: nginx/1.14.1
複製代碼

可以使用 localhost 或 127.0.0.1 檢查 Web Server 是否正常運行

增加到服務器的防火牆
  1. sudo firewall-cmd --permanent --zone=public --add-service=http
  2. sudo firewall-cmd --permanent --zone=public --add-service=https
  3. sudo firewall-cmd --reload
複製代碼

改變目錄的擁有者 (預設是 root)
  1. chown nginx:nginx /usr/share/nginx/html -R
複製代碼


安裝 MySQL 8
  1. yum -y install @mysql
複製代碼
  1. Last metadata expiration check: 0:09:09 ago on Sat 11 Apr 2020 05:06:05 AM UTC.
  2. Dependencies resolved.
  3. ================================================================================
  4. Package            Arch   Version                              Repo       Size
  5. ================================================================================
  6. Installing group/module packages:
  7. mysql-server       x86_64 8.0.17-3.module_el8.0.0+181+899d6349 AppStream  22 M
  8. Installing dependencies:
  9. mariadb-connector-c-config
  10.                     noarch 3.0.7-1.el8                          AppStream  13 k
  11. mecab              x86_64 0.996-1.module_el8.0.0+41+ca30bab6.9 AppStream 397 k
  12. mysql              x86_64 8.0.17-3.module_el8.0.0+181+899d6349 AppStream  11 M
  13. mysql-common       x86_64 8.0.17-3.module_el8.0.0+181+899d6349 AppStream 143 k
  14. mysql-errmsg       x86_64 8.0.17-3.module_el8.0.0+181+899d6349 AppStream 557 k
  15. perl-Digest        noarch 1.17-395.el8                         AppStream  27 k
  16. perl-Digest-MD5    x86_64 2.55-396.el8                         AppStream  37 k
  17. perl-Net-SSLeay    x86_64 1.88-1.el8                           AppStream 379 k
  18. perl-URI           noarch 1.73-3.el8                           AppStream 116 k
  19. perl-libnet        noarch 3.11-3.el8                           AppStream 121 k
  20. protobuf-lite      x86_64 3.5.0-7.el8                          AppStream 150 k
  21. checkpolicy        x86_64 2.9-1.el8                            BaseOS    348 k
  22. libaio             x86_64 0.3.112-1.el8                        BaseOS     33 k
  23. perl-Data-Dumper   x86_64 2.167-399.el8                        BaseOS     58 k
  24. perl-Encode        x86_64 4:2.97-3.el8                         BaseOS    1.5 M
  25. perl-File-Temp     noarch 0.230.600-1.el8                      BaseOS     63 k
  26. perl-Getopt-Long   noarch 1:2.50-4.el8                         BaseOS     63 k
複製代碼

@mysql 會安裝最新版的 MySQL

安裝完成後, 啟動 MySQL 8
  1. sudo systemctl start mysqld
複製代碼

啟動 Centos 8 時, 自動啟動 MySQL 8
  1. sudo systemctl enable --now mysqld
複製代碼

檢查 MySQL 8 的狀態
  1. sudo systemctl status mysqld
複製代碼
  1. [root@auau ~]# systemctl status mysqld
  2. ● mysqld.service - MySQL 8.0 database server
  3.    Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: d>
  4.    Active: active (running) since Sat 2020-04-11 05:18:03 UTC; 13s ago
  5. Main PID: 17979 (mysqld)
  6.    Status: "Server is operational"
  7.     Tasks: 39 (limit: 11510)
  8.    Memory: 540.6M
  9.    CGroup: /system.slice/mysqld.service
  10.            └─17979 /usr/libexec/mysqld --basedir=/usr
複製代碼


設定 MySQL 8
  1. mysql_secure_installation
複製代碼
  1. Securing the MySQL server deployment.

  2. Connecting to MySQL using a blank password.

  3. VALIDATE PASSWORD COMPONENT can be used to test passwords
  4. and improve security. It checks the strength of password
  5. and allows the users to set only those passwords which are
  6. secure enough. Would you like to setup VALIDATE PASSWORD component?

  7. Press y|Y for Yes, any other key for No: y

  8. There are three levels of password validation policy:

  9. LOW    Length >= 8
  10. MEDIUM Length >= 8, numeric, mixed case, and special characters
  11. STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

  12. Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2
  13. Please set the password for root here.

  14. New password:

  15. Re-enter new password:

  16. Estimated strength of the password: 100
  17. Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y
  18. By default, a MySQL installation has an anonymous user,
  19. allowing anyone to log into MySQL without having to have
  20. a user account created for them. This is intended only for
  21. testing, and to make the installation go a bit smoother.
  22. You should remove them before moving into a production
  23. environment.

  24. Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
  25. Success.


  26. Normally, root should only be allowed to connect from
  27. 'localhost'. This ensures that someone cannot guess at
  28. the root password from the network.

  29. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y
  30. Success.

  31. By default, MySQL comes with a database named 'test' that
  32. anyone can access. This is also intended only for testing,
  33. and should be removed before moving into a production
  34. environment.


  35. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y
  36. - Dropping test database...
  37. Success.

  38. - Removing privileges on test database...
  39. Success.

  40. Reloading the privilege tables will ensure that all changes
  41. made so far will take effect immediately.

  42. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
  43. Success.

  44. All done!
複製代碼


安裝 PHP 7.4 (或 PHP 7.3, 或 PHP 7.2)
預設 Centos 8 會安裝 PHP 7.2, 如果需要安裝 PHP 7.2 請跳過下面幾步

PHP 7.4 / 7.3 請按下面步驟更新 EPEL Repo
  1. sudo dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm
複製代碼
  1. sudo dnf module list php
複製代碼
  1. Extra Packages for Enterprise Linux Modular 8 - x86_  69 kB/s | 116 kB     00:01
  2. Extra Packages for Enterprise Linux 8 - x86_64       4.2 MB/s | 6.2 MB     00:01
  3. Remi's Modular repository for Enterprise Linux 8 - x 112 kB/s | 541 kB     00:04
  4. Safe Remi's RPM repository for Enterprise Linux 8 -  244 kB/s | 1.5 MB     00:06
  5. CentOS-8 - AppStream
  6. Name       Stream         Profiles                        Summary
  7. php        7.2 [d]        common [d], devel, minimal      PHP scripting language
  8. php        7.3            common, devel, minimal          PHP scripting language

  9. Remi's Modular repository for Enterprise Linux 8 - x86_64
  10. Name       Stream         Profiles                        Summary
  11. php        remi-7.2       common [d], devel, minimal      PHP scripting language
  12. php        remi-7.3       common [d], devel, minimal      PHP scripting language
  13. php        remi-7.4       common [d], devel, minimal      PHP scripting language

  14. Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
複製代碼

如要安裝 PHP 7.3
  1. sudo dnf module reset php
  2. sudo dnf module enable php:remi-7.3
複製代碼

如要安裝 PHP 7.4
  1. sudo dnf module reset php
  2. sudo dnf module enable php:remi-7.4
複製代碼

準備好了就可以開始安裝
  1. sudo dnf install php php-opcache php-gd php-curl php-mysqlnd
複製代碼

PFP-FPM 作為 dependency 也已被安裝, 用於 FastCGI server, 啟動是自動啟動 PHP-FPM :
  1. sudo systemctl enable --now php-fpm
複製代碼

預設, PHP-FPM 的使用者是 apache, 為了避免以後的衝突, 我們需要修改成 nginx
  1. sudo vim /etc/php-fpm.d/www.conf
複製代碼

  1. /etc/php-fpm.d/www.conf
  2. ...
  3. user = nginx
  4. ...
  5. group = nginx
複製代碼

確保 /var/lib/php 目錄的權限正確:
  1. chown -R root:nginx /var/lib/php
複製代碼

成功後重啟 PHP-FPM 服務:
  1. sudo systemctl restart php-fpm
複製代碼


修改 nginx.conf
  1. server {

  2.     # . . . other code

  3.     location ~ \.php$ {
  4.         try_files $uri =404;
  5.         fastcgi_pass unix:/run/php-fpm/www.sock;
  6.         fastcgi_index index.php;
  7.         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  8.         include fastcgi_params;
  9.     }
  10. }
複製代碼

重啟 Nginx
  1. sudo systemctl restart nginx
複製代碼


安裝 phpMyAdmin 5下載, 解壓, 移到 html 根目錄, 複製 config.inc.php
  1. wget https://files.phpmyadmin.net/phpMyAdmin/5.0.2/phpMyAdmin-5.0.2-all-languages.tar.gz
  2. sudo tar -zxvf phpMyAdmin-5.0.2-all-languages.tar.gz
  3. sudo mv phpMyAdmin-5.0.2-all-languages /usr/share/nginx/html/phpMyAdmin
  4. sudo cp -pr /usr/share/nginx/html/phpMyAdmin/config.sample.inc.php /usr/share/nginx/html/phpMyAdmin/config.inc.php
複製代碼
設定 config.inc.php, 加入 Blowfish Secret
Blowfish Secret Generator
  1. sudo vim /usr/share/nginx/html/phpMyAdmin/config.inc.php
複製代碼

並加入以下
  1. $cfg['TempDir'] = '/tmp';
複製代碼

創建一個 tmp 在 phpMyAdmin 裡面
  1. sudo mkdir /usr/share/nginx/html/phpMyAdmin/tmp
  2. sudo chown -R nginx:nginx /usr/share/nginx/html/phpMyAdmin/tmp
複製代碼

為 phpMyAdmin 創建一個 table
  1. mysql < /usr/share/nginx/html/phpMyAdmin/sql/create_tables.sql -u root -p
複製代碼

創建一個 phpMyAdmin.conf
  1. sudo vim /etc/nginx/conf.d/phpMyAdmin.conf
複製代碼
  1. server {
  2. listen 80;
  3.    server_name pma.abc.com;
  4.    root /usr/share/nginx/html/phpMyAdmin;

  5.    location / {
  6.       index index.php;
  7.    }

  8. ## Images and static content is treated different
  9.    location ~*             ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
  10.   access_log off;
  11.   expires 30d;
  12.    }

  13.    location ~ /\.ht {
  14.       deny all;
  15.    }

  16.    location ~ /(libraries|setup/frames|setup/libs) {
  17.       deny all;
  18.       return 404;
  19.    }

  20.    location ~ \.php$ {
  21.       include /etc/nginx/fastcgi_params;
  22.       fastcgi_pass 127.0.0.1:9000;
  23.       fastcgi_index index.php;
  24.       fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/phpMyAdmin$fastcgi_script_name;
  25.    }
  26. }
複製代碼

為 phpMyAdmin 建立 SELinux Policy
  1. sudo semanage fcontext -a -t httpd_sys_content_t "/usr/share/nginx/html/phpMyAdmin(/.*)?"
  2. sudo restorecon -Rv /usr/share/nginx/html/phpMyAdmin
複製代碼
測試安裝是否成功 http://localhost/phpMyAdmin

本帖子中包含更多資源

您需要 登錄 才可以下載或查看,沒有帳號?立即註冊

x
回復

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 立即註冊

本版積分規則

Archiver|手機版|小黑屋|雲峰香港

GMT+8, 2020-8-12 20:46 , Processed in 0.052752 second(s), 19 queries .

© 2017 Cloud.hk. All Rights Reserved.

快速回復 返回頂部 返回列表