ubuntu上搭建wordpress

前提条件:

  1. php7.4 +
  2. mysql 8+

参考ubuntu配置php环境ubuntu上安装mysql

  1. 下载源码,wget https://wordpress.org/latest.tar.gz
  2. 解压,tar xzvf latest.tar.gz
  3. 移动到/usr/share/nginx/html/wordpress
  4. 配置nginx
server {
        listen 80;
        listen [::]:80;

        # SSL configuration
        #
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;
        #
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;

        # root /var/www/html;
        # root /root/src/wordpress/wordpress;
        root /usr/share/nginx/html/wordpress;
        # root /usr/share/txy/wordpress;
        # Add index.php to the list if you are using PHP
        index index.php index.html index.htm index.nginx-debian.html;

        server_name wp.tangxuyang.cn;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }

        # pass PHP scripts to FastCGI server
        #
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;

                # With php-fpm (or other unix sockets):
                # fastcgi_pass unix:/run/php/php7.4-fpm.sock;
                # With php-cgi (or other tcp sockets):
                # fastcgi_pass 127.0.0.1:9000;
                fastcgi_pass unix:/run/php/php8.1-fpm.sock;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_param QUERY_STRING $query_string;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #       deny all;
        #}
}

访问https://wp.tangxuyang.cn,开始设置wordpress吧

其实在这个过程中我还遇到一个问题,最终原因是wordpress目录属于root,权限是drwxr-x-r-x,而nginx的用户是www-data,虽然可以访问wordpress中的文件,但是没有创建权限,所以wordpress会让自行创建wp-config.php,刚开始我也傻傻地自己去创建。后面在上传图片是总报错,才知道是权限的问题,解决方法就是把wordpress目录给www-data,chown -R www-data:www-data wordpress


评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注