記錄一下整個安裝的過程
安裝php與相關的套件
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt -y install php7.4 php7.4-fpm php-mysql
安裝 Nginx
sudo apt-get install nginx
安裝 MariaDB與設定 MariaDB
sudo apt-get install mariadb-server
sudo mysql_secure_installation
mysql -u root -h localhost -p
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MY_NEW_PASSWORD');
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'newpassword';
CREATE DATABASE wordpress;
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress'@'localhost'
FLUSH PRIVILEGES;
安裝wordpress
wget -c http://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz
sudo cp -R wordpress/ /var/www/html/wordpress
sudo chmod -R 775 /var/www/html/wordpress
sudo mv wp-config-sample.php wp-config.php
設定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', 'the_db_name' );
/** MySQL database username */
define( 'DB_USER', 'the_db_user' );
/** MySQL database password */
define( 'DB_PASSWORD', 'db_password );
/** MySQL hostname */
define( 'DB_HOST', 'localhost' );
設定Nginx
在安裝好nginx以後,可以先到/etc/nginx/sites-enabled/
中將預設所有目前服務的http 網站移除,然後將wordpress的設定檔 wordpress.conf
加入到/etc/nginx/conf.d/
這個資料夾下
server {
listen 80;
server_name blog.gechen.xyz;
index index.php;
root /var/www/html/wordpress;
client_max_body_size 100M;
error_log /var/log/nginx/wordpress_error.log;
access_log /var/log/nginx/wordpress_access.log;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
fastcgi_param
SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
關閉Apache
/etc/init.d/apache2 stop
WordPress 網址
最後在設定中,還需要設定目前網站的位扯;而這個部分可以從wordpress 的管理界面中設定,或者是透過直接設定對應的DB 資料。
如果是透過DB 設定的話,則可以透過以下的SQL 來更新:
update wp_options set option_value = "http://blog.gechen.xyz" where option_name = "home" OR option_name = "siteurl";