生产环境服务器部署安装 wordpress 网站

文章目录

    虽然 wordpress 安装起来很简单,但是细节不算少,记录一下

    下载 wordpress

    到 wordpress.org 查看最新版的 wordpress 下载地址。
    如果目标用户是国内用户,直接去 cn.wordpress.org 查看即可。
    copy 下载地址,然后在服务器进行下载。例如:

    wget https://cn.wordpress.org/wordpress-4.7.2-zh_CN.tar.gz
    

    解压

    tar xvzf wordpress-4.7.2-zh_CN.tar.gz
    

    新建一个数据库及对应账号

    CREATE DATABASE wpdb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci;
    CREATE USER wpuser@localhost IDENTIFIED BY 'wppassword';
    GRANT ALL PRIVILEGES ON wpdb.* TO wpuser@localhost;
    FLUSH PRIVILEGES;
    

    使用 utf8mb4 的原因,参考 mysql utf8mb4 编码 - MySQL

    配置 Nginx

    server {
            listen 80;
            server_name wordpress-site.com;
    
            root /home/wp/wordpress-4.7.2/;
            index index.php index.html index.htm;
    
            location = /xmlrpc.php { deny all; }
    
            location / {
                    # try_files $uri $uri/ =404;
                    try_files $uri $uri/ /index.php?q=$uri&$args;
            }
    
            location ~ \.php$ {
    		include snippets/fastcgi-php.conf;
    		fastcgi_pass unix:/run/php/php7.0-fpm.sock;
            }
    }
    

    确认配置正确,并加载新配置

    sudo nginx -t
    sudo nginx -s reload
    

    配置 DNS 域名解析

    将 Nginx 中配置的域名,指向当前服务器的 IP

    调整相关目录的权限

    sudo chown -R www-data:www-data wordpress
    

    给予 wp-content 目录“用户组写权限”以便于在线安装主题和插件

    sudo chmod g+w wordpress/wp-content/
    sudo chmod -R g+w wordpress/wp-content/themes/
    sudo chmod -R g+w wordpress/wp-content/plugins/
    

    通过浏览器进行 wordpress 初始化

    在地址栏输入之前配置好的域名 http://wordpress-site.com

    之后按照引导一步一步来就可以了。

    参考

    关于作者 🌱

    我是来自山东烟台的一名开发者,有感兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊,或者关注我的个人公众号“大象工具”, 查看更多联系方式