CDKでEC2インスタンスを初期化される場合の注意点

CDK で EC2 インスタンスを ec2.InstanceCfnInstance を使って定義すると、CDK のスタックが更新される際に、新しいインスタンスが作成され、既存のインスタンスが削除される ことがあります。

特に以下の変更を加えた場合、CDK は新しいインスタンスを作成します:

  1. AMI ID の変更
  2. インスタンスタイプの変更
  3. IAM ロールの変更
  4. Elastic IP の関連付け変更
  5. CDK の Instance リソースを変更・削除して再デプロイ
  6. リソースの一意識別子 (Logical ID) の変更
Posted in AWS, CDK, 技術情報 | Leave a comment

WordPress のUpdraftPlus の HTTP エラー 413 (Request Entity Too Large) が発生する問題

WordPress のバックアッププラグイン UpdraftPlus を使用している際に、ファイルのアップロード時に HTTP エラー 413 (Request Entity Too Large) が発生する問題です。

Nginx default.conf

sudo vi /etc/nginx/conf.d/default.conf
server {
    listen 80;
    server_name example.com;

    client_max_body_size 512M;
}

php.ini

$ sudo vi /etc/php.ini
upload_max_filesize = 512M
post_max_size = 512M
max_execution_time = 300
max_input_time = 300
memory_limit = 512M
Posted in Linux, Nginx, php, 技術情報 | Leave a comment

デレクトリのみの権限を一括変換

$ sudo find . -type d -exec chmod 766 {} \;
Posted in AWS, CentOS, Linux, 技術情報 | Leave a comment

WordPressのwp-config.phpの定義

WordPressのSSLの設定で下記の定義をwp-config.phpの最終行に追記した。

define('FORCE_SSL_ADMIN', true);
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
    $_SERVER['HTTPS'] = 'on';
}
define('FS_METHOD', 'direct');

しかし、どうしても「このページにアクセスする権限がありません。」というエラーが出て困っていた。そこで、下記にてデバッグをtrue設定してみた。

define( 'WP_DEBUG', true );

すると、「Warning: Constant FORCE_SSL_ADMIN already defined in /var/www/wordpress/wp-config.php on line 105」というエラーが出てきた。よくよく調査してみると、wp-config.php に新たな定義を行う時は、下記の場所に記述しなければならないらしい。

/* Add any custom values between this line and the "stop editing" line. */

/* ここに新しい定義をしなければならない。 */
define('FORCE_SSL_ADMIN', true);
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
    $_SERVER['HTTPS'] = 'on';
}
define('FS_METHOD', 'direct');

/* That's all, stop editing! Happy publishing. */

解決にかなりの時間を使ったよ。

Posted in AWS, Linux, php, WordPress, 技術情報 | Leave a comment

Amazon Linux 2023にnginx とphp-fpmをインストールしてphpが実行できるよう設定する

$ sudo vi /etc/nginx/conf.d/default.conf
server {
    listen 80;
    server_name localhost;

    root /usr/share/nginx/html; #ドキュメントルートを変更する
    index index.php index.html index.htm;
    
    client_max_body_size 512M;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass unix:/run/php-fpm/www.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

Posted in AWS, Linux, Nginx, php, 技術情報 | Leave a comment

AWS CDKでロードバランサとターゲットグループの設定

SSL証明書を指定

    // SSL証明書指定(ACM)
    const certificate = acm.Certificate.fromCertificateArn(
      this,
      'MyCertificate',
      'arn:aws:acm:ap-northeast-1:123456789012:certificate/abcdefg1-h2ijk-3456-7890-1m2n3o4p5q6r',
    );

ALB(ロードバランサ)の設定

    // ALB作成
    const alb = new elbv2.ApplicationLoadBalancer(this, 'MyALB', {
      vpc,
      vpcSubnets: { subnetType: ec2.SubnetType.PUBLIC },
      securityGroup,
      internetFacing: true,
    });

ターゲットグループの作成

    // ターゲットグループ
    const targetGroup = new elbv2.ApplicationTargetGroup(this, 'MyTargetGroup', {
      vpc,
      port: 80,
      protocol: elbv2.ApplicationProtocol.HTTP,
      targetType: elbv2.TargetType.INSTANCE,
      targets: [new InstanceTarget(ec2Instance, 80)],
      // 以下の設定ではCDK 2.1001.0 で動作しない。
      // targets: [ec2Instance],
      // targets: [new elbv2.InstanceTarget(ec2Instance, 80)],
      // targets: [new elbv2.InstanceTargetId(ec2Instance.instanceId)],
      healthCheck: {
        path: '/',
        port: 'traffic-port',
      },
    });
    // 以下の設定ではCDK 2.1001.0 で動作しない。
    // targetGroup.addTarget(ec2Instance);

ALBにリスナーを追加(ターゲットグループと証明書を追加)

    // ALBにリスナーを追加
    alb.addListener('Listener', {
      port: 443,
      protocol: elbv2.ApplicationProtocol.HTTPS,
      certificates: [certificate],
      defaultAction: elbv2.ListenerAction.forward([targetGroup]),
    });
Posted in AWS, CDK, TypeScript, 技術情報 | Leave a comment

Amazon Linux 2023 の httpd のVertualHost (WordPress)設定

WordPress用のhttpdのconfファイルを追加

$sudo vi /etc/httpd/conf.d/wordpress.conf

wordpress.conf に追記

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/wordpress
    ServerName your-domain.com

    <Directory /var/www/wordpress>
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog /var/log/httpd/wordpress-error.log
    CustomLog /var/log/httpd/wordpress-access.log combined
</VirtualHost>

httpd の再起動

$sudo systemctl restart httpd
Posted in Linux, WordPress, 技術情報 | Leave a comment

Amazon Linux 2023 へWordPressをインストールする

cd /var/www
sudo wget https://wordpress.org/latest.tar.gz
sudo tar -xzf latest.tar.gz
# nginxの場合
sudo chown -R nginx:nginx wordpress
# Apache httpdの場合
sudo chown -R apache:apache wordpress
sudo chmod -R 755 wordpress
Posted in Linux, Nginx, WordPress, 技術情報 | Leave a comment

Amazon Linux 2023 にphpをインストール

$sudo dnf install -y php-cli php-fpm php-mysqlnd php-json php-gd php-mbstring php-xml php-curl php-zip php-intl php-opcache

Posted in AWS, Linux, php, 技術情報 | Leave a comment

Vi でファイル全選択してDelete

:%dを入力して、Enterキー
Posted in Linux, Vi, 技術情報 | Leave a comment