# wordpress AP server 安裝 ## 安裝項目 WordPress 6.5 PHP 8.2 MySQL 8.0 ### 1.WordPress 在/home/ec2-user目錄下 ``` mkdir Download cd Download wget https://wordpress.org/latest.tar.gz tar -xzvf latest.tar.gz 把wordpress搬到/opt目錄下 mv ~/Download/wordpress/ /opt/ ``` ### 2.php安裝 ``` sudo dnf install -y httpd wget php-fpm php-mysqli php-json php php-devel ``` ### 3. MySQL client 安裝 ``` sudo wget https://dev.mysql.com/get/mysql80-community-release-el9-1.noarch.rpm sudo rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2023 sudo dnf install mysql-community-client -y 測試資料庫連線 mysql -u admin -h wordpressdb.clye44uoew7z.ap-northeast-1.rds.amazonaws.com -P3306 -p ``` ## 設定 ### 1. wordpress 設定 ``` cd /opt/wordpress cp wp-config-sample.php wp-config.php 編輯 wp-config.php vi wp-config.php ``` 設定資料庫與多域名 資料庫設定內容有帳密請詳Line記事本附圖 ![截圖 2024-04-14 晚上11.06.51](https://hackmd.io/_uploads/HyiEb_Yl0.png) ### 2. apache 設定 設定 /etc/httpd/conf.d/wordpress-vhost.conf ``` <VirtualHost 127.0.0.1:80 _default_:80> ServerName dravzo.idv.tw ServerAlias * DocumentRoot /opt/wordpress <Directory "/opt/wordpress"> Options -Indexes +FollowSymLinks -MultiViews AllowOverride None Require all granted # BEGIN WordPress fix for plugins and themes # Certain WordPress plugins and themes do not properly link to PHP files because of symbolic links # https://github.com/bitnami/bitnami-docker-wordpress-nginx/issues/43 RewriteEngine On RewriteRule ^bitnami/wordpress(/.*) $1 [L] # END WordPress fix for plugins and themes # BEGIN nip.io redirection RewriteEngine On RewriteCond %{HTTP_HOST} ^([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})(:[0-9]{1,5})?$ RewriteRule ^/?(.*) %{REQUEST_SCHEME}://%1.nip.io%2/$1 [L,R=302,NE] # END nip.io redirection # BEGIN WordPress Multisite # Using subdomain network type: https://wordpress.org/support/article/htaccess/#multisite RewriteEngine On RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteBase / RewriteRule ^index\.php$ - [L] # add a trailing slash to /wp-admin RewriteRule ^wp-admin$ wp-admin/ [R=301,L] RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ - [L] RewriteRule ^(wp-(content|admin|includes).*) $1 [L] RewriteRule ^(.*\.php)$ $1 [L] RewriteRule . index.php [L] # END WordPress Multisite # BEGIN Disable WordPress XML-RPC endpoint # Disable the outdated WordPress XML-RPC endpoint to prevent security vulnerabilities. # https://github.com/bitnami/containers/pull/51077 <Files xmlrpc.php> Order Allow,Deny Deny from all </Files> # END Disable WordPress XML-RPC endpoint </Directory> Include "/etc/httpd/conf.d/wordpress-htaccess.conf" </VirtualHost> ``` 設定 /etc/httpd/conf.d/wordpress-htaccess.conf ``` <Directory "/opt/wordpress/wp-content/plugins/akismet"> # Only allow direct access to specific Web-available files. # Apache 2.2 <IfModule !mod_authz_core.c> Order Deny,Allow Deny from all </IfModule> # Apache 2.4 <IfModule mod_authz_core.c> Require all denied </IfModule> # Akismet CSS and JS <FilesMatch "^(form\.js|akismet(-frontend|-admin)?\.js|akismet(-admin)?(-rtl)?\.css|inter\.css)$"> <IfModule !mod_authz_core.c> Allow from all </IfModule> <IfModule mod_authz_core.c> Require all granted </IfModule> </FilesMatch> # Akismet images <FilesMatch "^(logo-(a|full)-2x\.png|akismet-refresh-logo\.svg|akismet-refresh-logo@2x\.png|arrow-left\.svg|icon-external\.svg)$"> <IfModule !mod_authz_core.c> Allow from all </IfModule> <IfModule mod_authz_core.c> Require all granted </IfModule> </FilesMatch> </Directory> ``` 啟動httpd ``` sudo systemctl start httpd ``` 把httpd設為開機時啟動 ``` sudo systemctl enable httpd ``` ## 憑證設定 ### certbot安裝 安裝certbot是為了使用免費憑證Let's encrpt, 待設定DNS之後才能繼續設定憑證。 安裝certbot方式來源參考:https://unix.stackexchange.com/questions/741450/installing-lets-encrypt-on-amazon-linux-2023 ``` sudo dnf install -y augeas-libs sudo python3 -m venv /opt/certbot/ sudo /opt/certbot/bin/pip install --upgrade pip sudo /opt/certbot/bin/pip install certbot certbot-apache ```