在Ubuntu 20.04安装Nginx, PHP, Mariadb, Wordpress

安装 Nginx, PHP, and Mariadb

1
2
3
  $ sudo apt update
  $ sudo apt install nginx mariadb-server mariadb-client php-fpm php-mysql
  $ sudo apt-get install php-gd //如果不安装,在裁剪图像时会出错。

配置 Mariadb

1
2
3
4
5
6
$ sudo mysql
MariaDB [(none)]> CREATE DATABASE wordpress_db;
MariaDB [(none)]> CREATE USER 'wordpress_user'@'localhost' IDENTIFIED BY 'my_password';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON wordpress_db.* to wordpress_user@'localhost';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> exit

配置 Nginx

1
$ sudo nano /etc/nginx/sites-available/wordpress

配置文件模板:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
server {
    listen 80;
    listen [::]:80;
    root /var/www/wordpress;
    index index.php;
    server_name 127.0.0.1;   //这里修改成你的域名
    location / {
          try_files $uri $uri/ =404;
    }
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;  //使用 php --version 确定你的php版本
    }
}
1
2
3
$ sudo rm /etc/nginx/sites-enabled/default
$ sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/wordpress
$ sudo systemctl restart nginx

下载并安装 WordPress

1
2
3
$ wget -O /tmp/wordpress.tar.gz https://wordpress.org/latest.tar.gz
$ sudo tar -xzvf /tmp/wordpress.tar.gz -C /var/www
$ sudo chown -R www-data.www-data /var/www/wordpress

浏览器页面配置

打开浏览器 http://127.0.0.1 按照页面配置

记录并分享
Built with Hugo
主题 StackJimmy 设计