☁️

Ubuntu24.04+nginx+php8.3-fpmでサクッとWP構築

2024/10/31に公開

ちょうどいい記事がなかったので備忘録的に

1. VMを用意

適当に拾ってきます
私は転がってたubuntu 22.04を24.04に更新したものを用意しました

2. 必要なものをインストール

nginx

sudo apt install curl gnupg2 ca-certificates lsb-release ubuntu-keyring
curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \
    | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" \
    | sudo tee /etc/apt/sources.list.d/nginx.list
echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" \
    | sudo tee /etc/apt/preferences.d/99nginx
sudo apt update
sudo apt install nginx

php8.3-fpm

apt install php8.3-fpm php8.3-cli php8.3-common php8.3-curl php8.3-bz2 php8.3-gd php8.3-mbstring php8.3-mysql opcache php8.3-readline php8.3-xml php8.3-zip

mariadb

apt install mariadb-server
mysql_secure_installation

3. DB作成

mysql -u root -p
CREATE DATABASE `wordpress` CHARACTER SET UTF8 COLLATE UTF8_BIN;
CREATE USER 'wp'@'%' IDENTIFIED BY 'hogehoge';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wp'@'%';
FLUSH PRIVILEGES;
quit;

※ユーザー名パスワードは適時変更すること

4. 設定

nginx

/etc/nginx/conf.d/default.conf

server {
    listen       80 default_server;
    server_name  localhost;

    client_max_body_size 64M;
    root /usr/share/nginx/html;
    index index.php index.html index.htm;

    location / {
        root   /usr/share/nginx/html;
        try_files $uri $uri/ =404;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    location ~ \.php$ {
        root           /usr/share/nginx/html;
        fastcgi_pass   unix:/var/run/php/php8.3-fpm.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root/$fastcgi_script_name;
        include        fastcgi_params;
    }
}

php-fpm

/etc/php/8.3/fpm/php.ini

post_max_size = 128M
upload_max_filesize = 64M
memory_limit = 512M
max_execution_time = 300

/etc/php/8.3/fpm/pool.d/www.conf

user = nginx
group = nginx

5. WPの配置

cd /usr/share/nginx/html
wget https://wordpress.org/latest.zip
unzip latest.zip
mv ./wordpress/* ./
rm -rf wordpress latest.zip

6. Webコンソールのセットアップ

なんかいい感じにやる
以上

Discussion