Nginx & Wordpress

 Nginx & Wordpress

(1) 先建立一個使用者、資料庫給Wordpres使用

CREATE DATABASE wordpress CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'wordpress'@'localhost' IDENTIFIED BY 'Kyy_y(YL901OzLBh';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress'@'localhost';
FLUSH PRIVILEGES;

(2) 下載 Wordpress,安裝unzip,同時解壓縮

wget https://tw.wordpress.org/latest-zh_TW.zip
sudo apt-get install unzip

(3) 將 Wordpress目錄複製到 /var/www/

sudo cp -R wordpress/ /var/www/wordpress.local

(4) 設定應對的權限給 wordpress.local

sudo chown -R www-data:www-data /var/www/wordpress.local
sudo chmod -R 775 /var/www/wordpress.local

(5) 需設定一個 wp-config給 Wordpress使用,我們拿範例來用,同時更改裡面的設定值

cd /var/www/wordpress.local/
cp wp-config-sample.php wp-config.php


define( 'DB_NAME', 'wordpress' );


/** Database username */

define( 'DB_USER', 'wordpress' );


/** Database password */

define( 'DB_PASSWORD', 'Kyy_y(YL901OzLBh' );


/** Database hostname */

define( 'DB_HOST', 'localhost' );

(6) 在 /etc/nginx/sites-available 底下建立一個虛擬服務器,同時連結過去

sudo nano /etc/nginx/sites-available/wordpress.local.conf


server {

        listen 80;

        listen [::]:80;

        root /var/www/wordpress.local;

        index  index.php index.html index.htm;

        server_name wordpress.local;


        error_log /var/log/nginx/mysite.com_error.log;

        access_log /var/log/nginx/mysite.com_access.log;


        client_max_body_size 100M;

        location / {

                try_files $uri $uri/ /index.php?$args;

        }

        location ~ \.php$ {

                include snippets/fastcgi-php.conf;

                fastcgi_pass unix:/run/php/php8.1-fpm.sock;

                fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;

        }

}


sudo ln -s /etc/nginx/sites-available/wordpress.local.conf /etc/nginx/sites-enabled/

(7) 刪除預設的虛擬服務器,同時檢查是否有問題,沒問題就重啟服務

sudo rm /etc/nginx/sites-enabled/default
sudo nginx -t
sudo systemctl restart nginx


留言

這個網誌中的熱門文章

黑暗靈魂3[所有重要物品的取得方式]

黑暗靈魂3[所有姿勢取得方式]

MySQL Replication