# 在Ubuntu 22.04上面使用LAMP系統設定Wordpress LAMP= Linux, Apache, MySQL, PHP 1. 系統更新 & 安裝 Apache以及設定防火牆 ```bash= $ sudo apt update ``` 然後安裝Apache ```bash=2 $ sudo apt install apache2 ``` 使用UFW來設定防火牆 ```bash=3 $ sudo ufw app list $ sudo ufw allow in "Apache Secure" ``` 2. 使用Certbot安裝&設定自動更新Let's Encrypt憑證 ```bash= $ sudo snap install --classic certbot $ sudo ln -s /snap/bin/certbot /usr/bin/certbot $ sudo certbot --apache $ sudo certbot renew --dry-run #安裝完成後測試是否自動更新有正常運作 ``` 3. 安裝MySQL ```bash= $ sudo apt install mysql-server $ sudo mysql_secure_installation ``` 4. 安裝PHP ```bash= $ sudo apt install php libapache2-mod-php php-mysql $ php -v ``` 5. 新增Database & User讓WordPress使用 ```bash= $ sudo mysql ``` ```sql= mysql> CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci; mysql >CREATE USER 'wordpressuser'@'%' IDENTIFIED WITH mysql_native_password BY '密碼'; mysql> GRANT ALL ON wordpress.* TO 'wordpressuser'@'%'; mysql> FLUSH PRIVILEGES; mysql>EXIT; ``` 6. 安裝額外會用到的PHP套件 ```bash= sudo apt update sudo apt install php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip sudo systemctl restart apache2 ``` 7. 設定Apache設定.htaccess權限 ```bash= sudo nano /etc/apache2/sites-available/這邊要看預設是哪個.conf ``` 將設定插入檔案當中 ``` <VirtualHost *:80> . . . ServerName 這邊記得要修改 <Directory /var/www/wordpress/> AllowOverride All </Directory> . . . </VirtualHost> ``` ```bash=4 sudo a2enmod rewrite sudo apache2ctl configtest ``` 8. 下載WordPress ```bash= cd /tmp curl -O https://wordpress.org/latest.tar.gz tar xzvf latest.tar.gz touch /tmp/wordpress/.htaccess cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php mkdir /tmp/wordpress/wp-content/upgrade sudo cp -a /tmp/wordpress/. /var/www/wordpress ``` 9. 設定WordPress資料夾路徑 ```bash= sudo chown -R www-data:www-data /var/www/wordpress sudo find /var/www/wordpress/ -type d -exec chmod 750 {} \; sudo find /var/www/wordpress/ -type f -exec chmod 640 {} \; curl -s https://api.wordpress.org/secret-key/1.1/salt/ #把回傳的訊息複製起來貼到wp-config.php sudo nano /var/www/wordpress/wp-config.php #貼到這裡面 ``` 裡面其他地方也要修正 ``` . . . // ** MySQL settings - You can get this info from your web host ** // /** The name of the database for WordPress */ define( 'DB_NAME', 'wordpress' ); /** MySQL database username */ define( 'DB_USER', 'wordpressuser' ); /** MySQL database password */ define( 'DB_PASSWORD', '這邊要修改密碼' ); /** MySQL hostname */ define( 'DB_HOST', 'localhost' ); /** Database Charset to use in creating database tables. */ define( 'DB_CHARSET', 'utf8' ); /** The Database Collate type. Don't change this if in doubt. */ define( 'DB_COLLATE', '' ); . . . define('FS_METHOD', 'direct'); ``` ```bash= sudo systemctl restart apache2 ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up