# Day99 伺服器應用與安裝
##
+ 資料庫(含管理)
+ 語言平台 -> php.fpm
+ Web平台 -> nginx
+ Wordpress
## 順序
+ 安裝 yum/dnf
+ 設定檔/如何設定
+ 啟動/中止
+ 安全/Firewall
## MySQL 安裝設定
+ dnf install mariadb-*
+ vim /etc/my.cnf
+ vim /etc/my.conf.d/mariadb-server.cnf
+ systemctl enabe \--now mariadb
+ firewall-cmd \--add-service=mysql
+ firewall-cmd \--add-service=mysql \--permanent
+ mysql_secure_installation ==安全配置設定==
+ systemctl status mariadb
+ mysql -u root -p
:::info
+ #相關指令
+ 查詢所有使用者權限
+ SELECT CONCAT('SHOW GRANTS FOR \'', user, '\'@\'', host, '\';') AS Grant_Command
+ FROM mysql.user;
+ 新增使用者 CREATE USER 'username'@'hostname' IDENTIFIED BY 'password';
+ 授予權限給新使用者 GRANT ALL PRIVILEGES ON `database_name`.* TO 'testuser'@'%';
+ 刷新權限 FLUSH PRIVILEGES;
+ 查詢使用權限 SHOW GRANTS FOR 'testuser'@'%';
+ 刪除使用者 DROP USER 'testuser'@'%';
+ 查詢所有使用者及基本資訊 SELECT User, Host FROM mysql.user;
+ 查詢使用者權限 SHOW GRANTS FOR 'username'@'hostname';
+ 修改root密碼 ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword';
:::
## PHP / nginx 安裝
+ dnf module list php
+ dnf module enable php:8.2
+ dnf module install php
+ dnf module list nginx
+ dnf module enable nginx:1.24
+ dnf module install nginx
+ vim /etc/php-fpm.d/www.conf
:::info
+ user = nginx
+ group= nginx
+ listen.acl_users = apache,nginx
:::
+ systemctl enable \--now php-fpm
+ ls -al /run/php-fpm/www.sock
+ getfacl /run/php-fpm/www.sock
+ 開網頁 -> www.phpmyadmin.net/downloads
+ download phpMyAdmin-5.2.1-all-languages.zip
+ 下載後將檔案移動放到 -> 其他的位置 -> 電腦 -> tmp 資料夾
+ cd /usr/share/nginx/html/
+ mv /tmp/phpMyAdmin-5.2.1-all-languages.zip ./
+ unzip phpMyAdmin-5.2.1-all-languages.zip
+ mv phpMyAdmin-5.2.1-all-languages phpmyadmin
+ restorecon -Rvv ./phpmyadmin/
+ cd phpmyadmin/
+ mv config.sample.inc.php config.inc.php
+ vim config.inc.php
+$ cfg['blowfish_secret'] = 'HelloWorld';
+ cd /var/lib/php
+ chown nginx session
+ dnf install php-mysql*
+ systemctl restart php-fpm
+ 開網頁 http://127.0.0.1/phpmyadmin
## Nginx 設定
:::info
重要檔案
nginx.conf (nginx.conf 設定檔)
php.conf (php 設定檔)
php-fpm.conf (sock 設定)
:::
+ cd /etc/nginx
+ vim nginx.conf (不用存檔)
:::info
複製修改內容
server {
listen 80;
listen [::]:80;
server_name ==www.student15.example==;
root ==/usr/share/nginx/html/wordpress==;
include /etc/nginx/default.d/*.conf;
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
:::
+ vim wordpress.conf
+ 貼上上面複製內容
+ mkdir /usr/share/nginx/html/wordpress
+ cd /usr/share/nginx/html/wordpress/
+ vim index.php
:::info
<?php
phpinfo();
?>
:::
+ nginx -t
+ nginx -s reload
+ systemctl start nginx
+ systemctl enable nginx
## 防火牆設定
+ firewall-cmd \--permanent \--zone=public \--add-service=http
+ firewall-cmd \--permanent \--zone=public \--add-service=https
+ firewall-cmd \--reload
## Wordpress下載及設定
+ 開啟網頁 https://tw.wordpress.org/download/
+ 下載後將檔案移動放到 -> 其他的位置 -> 電腦 -> tmp 資料夾
+ mv /tmp/wordpress-6.6.2-zh_TW.zip /usr/share/nginx/html
+ cd /usr/share/nginx/html
+ rm -rf wordpress
+ unzip wordpress-6.6.2-zh_TW.zip
+ cd wordpress
+ mv wp-config-sample.php wp-config.php
+ vim wp-config.php
:::info
修改內容
define('DB_NAME', 'wordpress') ;
define('DB_USER', 'wordpress') ;
define('DB_PASSWORD', 'a123456') ;
define('DB_HOST', 'localhost') ;
define('DB_CHARSET', 'utf8') ;
define('DB_COLLATE', '') ;
:::
+ restorecon -Rvv ./
+ 開網頁 www.student15.example
+ 進入設定後台www.student15.example/wp-admin
## phpmyadmin 設定
+ 資料庫:wordpress
+ ID:root
+ PW: mysql安裝過程中自行設置/預設密碼為空
+ 新增使用者帳號:wordpress
+ ID:a123456
+ PW:a123456
## FTP 安裝及設定
+ dnf install vsftpd
+ firewall-cmd \--add-service=ftp
+ firewall-cmd \-add-service=ftp \--permanent
+ systemctl start vsftpd
## 指令截圖
+ 
+ 
+ 