NGINXを使用してWordPress構築

WebServer 構築

ーーーーーーーーーーーーーーーーーーー
OS・格パッケージのVersion
OS: ubuntu server 20.04.2
php: 7.4
※ 基本的に全て特権ユーザで実行する
※ SSHでインスタンスにログイン・ドメインの取得については割愛します。
ーーーーーーーーーーーーーーーーーーー

    Ubuntuを使用してインスタンスを作成
    — インスタンス情報

1. nginx的设置

ubuntu@ubuntu:~$ sudo apt update -y   // apt のupdate
ubuntu@ubuntu:~$ sudo apt upgrade //aptでインストールしたパッケージの更新
ubuntu@ubuntu:~$ sudo apt install nginx

`nginxの起動設定`
ubuntu@ubuntu:~$ sudo systemctl start nginx
ubuntu@ubuntu:~$ sudo systemctl enable nginx

2. HTTPS 设置

关于SSL·TLS

    Let’s Encryptを使用
    ##### – 証明書を発行するためのクライアントツールをインストール
ubuntu@ubuntu:~$ sudo apt install -y certbot
ubuntu@ubuntu:~$ sudo certbot certonly --webroot -w /var/www/html -d xxxx.domain.name.com
– 更改config配置
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
ssl_certificate        /etc/letsencrypt/live/xxxx.domain.name.com/fullchain.pem;
ssl_certificate_key    /etc/letsencrypt/live/xxxx.domain.name.com/privkey.pem;


server_name xxxx.domain.name.com;
重新启动nginx

ubuntu@ubuntu:~$ 使用超级用户权限重启nginx systemctl restart nginx

3. WordPress建设

    MariaDBのインストール・設定
ubuntu@ubuntu:~$ sudo apt install mariadb-server mariadb-client

ubuntu@ubuntu:~$ sudo systemctl start mariadb
ubuntu@ubuntu:~$ sudo systemctl enable mariadb
在MariaDB中创建数据库和用户(包括授予权限)。

    ubuntu@ubuntu:~$ sudo mysql -u rootコマンドを使用してmariadbにログイン

CREATE DATABASE wordpress

CREATE USER 'wordpress'@'%' IDENTIFIED BY 'wordpress';
GRANT ALL ON wordpress.* TO 'wordpress'@'%' WITH GRANT OPTION;

UPDATE mysql.user SET password=password('root') WHERE user = 'root';

FLUSH PRIVILEGES;

创建用户’wordpress’@’%’,密码为’wordpress’。
– wordpress@’%’:无限制。
– wordpress@’localhost’: 如果在定义中写入”localhost”,则表示该用户只能在当前实例访问mariadb。
*在本案例中,即使写入”localhost”也是可以的。

– PHP的安装和设置
ubuntu@ubuntu:~$ sudo apt install php7.4-fpm -y
ubuntu@ubuntu:~$ sudo apt install php7.4-xml php7.4-curl php7.4-gd php7.4-mbstring php7.4-readline -y 
ubuntu@ubuntu:~$ sudo apt install php7.4-bz2 php7.4-zip php7.4-json php7.4-opcache -y 

该命令使用php来创建/解压缩zip文件,进行json解码/编码和图像处理,所以需要安装。

ubuntu@ubuntu:~$ sudo apt install -y php-mysql //phpを使用してmysqlに接続・操作するためにインストール
请编辑 /etc/php/7.4/fpm/php.ini 或者ファイル。

~ 由于最大发送量较少 ~

post_max_size = 32兆字节

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

                # With php-fpm (or other unix sockets):
                fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
                # With php-cgi (or other tcp sockets):
        #       fastcgi_pass 127.0.0.1:9000;
        }
    Wordpressのインストール・設定
ubuntu@ubuntu:~$ cd /tmp
ubuntu@ubuntu:~$ wget https://wordpress.org/latest.tar.gz
ubuntu@ubuntu:~$ tar -zxvf latest.tar.gz
ubuntu@ubuntu:~$ sudo mv wordpress /var/www/html/

使用tar命令的选项:
-z:解压.gz文件
-f:指定存档文件
-x:展开或恢复存档文件
-v:可视化执行过程

設定用於訪問wordpress/index.php的設置。
    – “index.php”を追記。
index index.php index.html index.htm index.nginx-debian.html;
    ファイルの所有者・グループを変更
ubuntu@ubuntu:~$ sudo chown -R www-data:www-data /var/www/html/wordpress/

便捷指令 jié

使用grep命令在文件中搜索字符串。

在根目录及其子目录中查找包含”hoge”字符串的文件路径。

bannerAds