• Ubuntu22.04安装 wordpress


    1. 第一步安装 mysql 这个必须是第一步
    sudo apt install mysql-server
    
    • 1
    1. 第二步修改mysql密码 ubuntu 首次登录mysql8 未设置密码或忘记密码解决方法 亲测可用

    2. 第三步安装 nginx

    sudo apt update && sudo apt upgrade -y
    sudo apt install nginx
    sudo systemctl enable nginx
    sudo systemctl start nginx
    sudo systemctl status nginx
    sudo ufw allow http
    sudo chown www-data:www-data /usr/share/nginx/html -R
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    第 4 步:安装 PHP
    sudo apt install php8.1 php8.1-fpm php8.1-mysql php8.1-cli php8.1-common php-json  php8.1-readline php8.1-mbstring php8.1-xml php8.1-gd php8.1-curl
    sudo systemctl start php8.1-fpm
    sudo systemctl enable php8.1-fpm
    sudo systemctl status php8.1-fpm
    
    • 1
    • 2
    • 3
    • 4
    第 5 步:创建 Nginx 服务器块
    sudo rm /etc/nginx/sites-enabled/default
    sudo vim /etc/nginx/conf.d/default.conf
    
    • 1
    • 2
    server {
      listen 80;
      listen [::]:80;
      server_name _;
      root /usr/share/nginx/html/;
      index index.php index.html index.htm index.nginx-debian.html;
    
      location / {
        try_files $uri $uri/ /index.php;
      }
    
      location ~ \.php$ {
        fastcgi_pass unix:/run/php/php7.4-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        include snippets/fastcgi-php.conf;
      }
    
     # A long browser cache lifetime can speed up repeat visits to your page
      location ~* \.(jpg|jpeg|gif|png|webp|svg|woff|woff2|ttf|css|js|ico|xml)$ {
           access_log        off;
           log_not_found     off;
           expires           360d;
      }
    
      # disable access to hidden files
      location ~ /\.ht {
          access_log off;
          log_not_found off;
          deny all;
      }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32

    将以下文本粘贴到文件中。以下代码片段将使 Nginx 监听 IPv4 端口 80 和 IPv6 端口 80,并使用 catch-all 服务器名称。

    sudo nginx -t
    sudo systemctl reload nginx
    
    • 1
    • 2
    第 6 步:安装 WordPress
    sudo apt update && sudo apt upgrade
    wget https://wordpress.org/latest.zip sudo apt install unzip
    sudo mkdir -p /usr/share/nginx
    sudo unzip latest.zip -d /usr/share/nginx/
    
    • 1
    • 2
    • 3
    • 4
    第 7 步:为 WordPress 网站创建数据库和用户
    mysql  -u root -p
    
    • 1
    create database wordpress;
    flush privileges;
    exit;
    
    • 1
    • 2
    • 3
    第 8 步:配置 WordPress
    cd /usr/share/nginx/wordpress/
    sudo cp wp-config-sample.php wp-config.php
    sudo vim wp-config.php
    
    • 1
    • 2
    • 3
    找到以下行,并将下方中文文本替换为您在上一步中创建的数据库名称、用户名和密码
    /** The name of the database for WordPress */
    define('DB_NAME', ' wordpress');
    
    /** MySQL database username */
    define('DB_USER', 'root');
    
    /** MySQL database password */
    define('DB_PASSWORD', '这里是你自己设置的密码');
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    sudo chown www-data:www-data /usr/share/nginx/wordpress/ -R
    
    • 1
    第 9步:为 WordPress 创建 Nginx 服务器块
    sudo vim /etc/nginx/conf.d/wordpress.conf
    
    • 1
    将以下文本放入文件中
    server {
      listen 80;
      listen [::]:80;
      server_name www.wordpress wordpress;
      root /usr/share/nginx/wordpress/;
      index index.php index.html index.htm index.nginx-debian.html;
    
      location / {
        try_files $uri $uri/ /index.php;
      }
    
       location ~ ^/wp-json/ {
         rewrite ^/wp-json/(.*?)$ /?rest_route=/$1 last;
       }
    
      location ~* /wp-sitemap.*\.xml {
        try_files $uri $uri/ /index.php$is_args$args;
      }
    
      error_page 404 /404.html;
      error_page 500 502 503 504 /50x.html;
    
      client_max_body_size 20M;
    
      location = /50x.html {
        root /usr/share/nginx/html;
      }
    
      location ~ \.php$ {
        fastcgi_pass unix:/run/php/php8.1-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        include snippets/fastcgi-php.conf;
        fastcgi_buffers 1024 4k;
        fastcgi_buffer_size 128k;
    
        # Add headers to serve security related headers
        add_header X-Content-Type-Options nosniff;
        add_header X-XSS-Protection "1; mode=block";
        add_header X-Permitted-Cross-Domain-Policies none;
        add_header X-Frame-Options "SAMEORIGIN";
      }
    
      #enable gzip compression
      gzip on;
      gzip_vary on;
      gzip_min_length 1000;
      gzip_comp_level 5;
      gzip_types application/json text/css application/x-javascript application/javascript image/svg+xml;
      gzip_proxied any;
    
      # A long browser cache lifetime can speed up repeat visits to your page
      location ~* \.(jpg|jpeg|gif|png|webp|svg|woff|woff2|ttf|css|js|ico|xml)$ {
           access_log        off;
           log_not_found     off;
           expires           360d;
      }
     }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    sudo nginx -t
    sudo systemctl reload nginx
    
    • 1
    • 2
  • 相关阅读:
    基于SSM的生鲜配送系统的设计与实现
    ArcGIS Pro地图可视化—双变量关系映射
    2022牛客蔚来杯补题(第九场)
    【2015】408联考数据结构真题整理
    c++网络编程
    Apache Hive 的 SQL 执行架构
    vsftp3.0 匿名用户,本地用户,虚拟用户,主动模式以及被动模式,docker vsftpd,k8s vsftpd
    数据飞轮拆解车企数据驱动三板斧:数据分析、市场画像、A/B 实验
    Java Native尝试
    Arthas 启动时无法获取java进程
  • 原文地址:https://blog.csdn.net/luoganttcc/article/details/137168263