LoginSignup
1
1

More than 3 years have passed since last update.

DockerでWordPress環境構築の際にハマったこと

Last updated at Posted at 2019-06-19

はじめに

WordPress開発環境の構築をする際に、以前はVagrant+VirtualBoxを利用していましたが、最近GCPにDockerコンテナのデプロイをしてみようと思うようになりました。
その過程で、ハマったことを覚え書きしておきます。

環境構築

サーバー環境の準備からbedrockのインストールまで、こちらを参考にさせていただきました。

WordPressの日本語化

ハマった訳ではないけど、覚え書き程度に書いておきます。
composer.jsonを編集することで、日本語化も出来ます。

composer.json
"repositories":[
 {
  "type": "composer",
  "url": "https://wpackagist.org"
 },
 {
  "type": "composer",
  "url": "https://wp-languages.github.io"
 }
],
"extra": {
 "installer-paths": {
  "public/wp-content/plugins/{$name}/": ["type:wordpress-plugin"]
 },
 "dropin-paths": {
  "public/app/languages/": ["vendor:koodimonni-language"],
  "public/app/languages/plugins/": ["vendor:koodimonni-plugin-language"],
  "public/app/languages/themes/": ["vendor:koodimonni-theme-language"]
 },
 "wordpress-install-dir": "public"
}

最後に、

$ composer require koodimonni-language/ja:*

を実行したら日本語化完了です。

ハマったこと

その① 413 「Request Entity Too Large」

bedrockのインストールまで終わりテーマのアップロードをしようとすると、「413 Request Entity Too Large」の表示。
調べていると、デフォルトのnginx設定だと、最大アップロードが1MBになっているようで、これを変更しないといけないようです。合わせてPHP側でもアップロードの最大容量が設定されているので、そっちも設定しておかなくてはいけないようです。
する事は、

  • client_max_body_sizeの変更
  • post_max_sizeの変更
  • upload_max_filesizeの変更

client_max_body_sizeは/etc/nginx/nginx.conf中にあります。
post_max_size、upload_max_filesizeは/etc/php.iniの中にあります。今回は、upload_max_filesizeが小さかったようです。

その②

その①が解決し、再度テーマのアップロードを試みると、今度は「ディレクトリwp-content/uploads/を作成できませんでした。
この親ディレクトリのアクセス権はサーバーによる書き込みを許可していますか?」のような表示。どうもFTP接続が必要なのだそうです。これを回避する方法は、wp-configに

define('FS_METHOD', 'direct');

と追記します。さらに、upgrade、themes、plugins、languagesのディレクトリ権限を変ます。

$chmod 0707 app/****

その③

WordPressをインストールして使っていると、パーマリンク設定を変更後、「404」が表示されるようになりました。.htaccessが無かったので作成してみましたが、変わリませんでした。そもそも、nginxで.htaccessは不要だったようで。nginx.confを変更しないといけないようでした。

etc/nginx/default.template.conf
server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name ${NGINX_HOST};

    index index.php index.html;
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /var/www/html;

    location / {
        try_files $uri $uri/ @wordpress;
    }

    location ~ \.php$ {
        # try_files $uri =404;
        try_files $uri @wordpress;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass php:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }

    location @wordpress {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass php:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root/wp/index.php;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

無事、パーマリンク設定を変更できるようになりました。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1