1. 程式人生 > 其它 >Ubuntu18配置wordpress伺服器 (nginx + wordpress + mariadb)

Ubuntu18配置wordpress伺服器 (nginx + wordpress + mariadb)

技術標籤:亂七八糟nginxlinuxphpubuntuwordpress

公眾號:張小飛那些事兒

公眾號

Ubuntu18配置wordpress伺服器 (nginx + wordpress + mariadb)

三年前買的騰訊雲的學生機馬上過期,所以趁著這個機會趕緊玩玩,搜了下大家都是用apache來起的服務。(我原來也是)

nginx又比較輕量,所以趁著這個機會把伺服器清了,重新用nginx又重新配置了下wordpress。特意來記錄(水)下。

Ubuntu18預設源php版本就是7.2

安裝軟體

  • nginx
  • mariadb
  • php

Ubuntu18預設源php版本就是7.2

sudo apt-get
update sudo apt-get install nginx sudo apt-get install mariadb-server sudo systemctl enable mariadb.service apt-get install php7.2 php7.2-cli php7.2-fpm php7.2-mysql php7.2-json php7.2-opcache php7.2-mbstring php7.2-xml php7.2-gd php7.2-curl

資料庫操作

建立一個wordpress的資料庫,使用者為wordpress ,密碼為wordpress

mysql -u root -p
create database wordpress; //建立wordpress資料庫
create user 
[email protected]
identified by 'wordpress'; //建立使用者wordpress 密碼也是wordpress GRANT ALL ON *.* TO 'wordpress'@'localhost'; FLUSH PRIVILEGES; exit;

配置nginx

綁定了我的二級域名 blog.cryfeifei.cn
wordpress地址放到這裡 /var/www/html/wordpress

cd /etc/nginx/sites-available
sudo vim wordpress.conf

新增如下程式碼,埠放開到80,繫結域名blog.cryfeifei.cn。 指定root地址

server {
            listen 80;
            root /var/www/html/wordpress;
            index index.php index.html;
            server_name blog.cryfeifei.cn;

            access_log /var/log/nginx/SUBDOMAIN.access.log;
            error_log /var/log/nginx/SUBDOMAIN.error.log;

            location / {
                        try_files $uri $uri/ =404;
            }

            location ~ \.php$ {
                         include snippets/fastcgi-php.conf;
                         fastcgi_pass unix:/run/php/php7.2-fpm.sock;
            }

            location ~ /\.ht {
                         deny all;
            }

            location = /favicon.ico {
                         log_not_found off;
                         access_log off;
            }

            location = /robots.txt {
                         allow all;
                         log_not_found off;
                         access_log off;
           }

            location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
                         expires max;
                         log_not_found off;
           }
}

建立完這個檔案後給個軟鏈

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

配置nginx

把wordpress zip檔案解壓到 目錄/var/www/html/wordpress
一定要做的
www-data許可權是nginx預設的使用者組。需要給對應目錄許可權。否則下載外掛也下載不下來

sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www/html/*

最後改一下wordpress的 config;

# cd /var/www/html/wordpress/public_html
# mv wp-config-sample.php wp-config.php
# vi wp-config.php

 define('DB_NAME', 'wordpress');
 define('DB_USER', 'wordpress');
 define('DB_PASSWORD', 'wordpress');

最後別忘了

sudo systemctl restart nginx

最後就可以用wordpress起個服務了。

公眾號:張小飛那些事兒

公眾號