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

MySQL 2025年度版 初期設定

データベース作成 ※指定しなくてもDefaultは utf8mb4

CREATE DATABASE db_name CHARACTER SET utf8mb4;

データベース削除

DROP DATABASE db_name;

データベース情報表示

SHOW CREATE DATABASE db_name;

データベース一覧

SHOW DATABASES;

テーブル一覧

SHOW TABLES;

データベース変更

USE db_name;

ユーザ作成 ※8.0より以前はCREATE USERは使用しなかった

CREATE USER 'user_name'@'localhost' IDENTIFIED BY 'xxxxxxxx';

権限付与

GRANT ALL ON db_name.* TO 'user_name'@'localhost';

リフレッシュ

FLUSH PRIVILEGES;

パスワード変更

set password for user_name@localhost='xxxxxxxx';
ALTER USER 'user_name'@'localhost' IDENTIFIED BY 'xxxxxxxx';

DBユーザ一覧

SELECT user FROM mysql.user;
Posted in MySQL, 技術情報 | Leave a comment

Amazon Linux 2023へMySQLのインストール方法

久しぶりの投稿である。今更ながら勉強がてらAWSにサーバ構築。結構Linuxコマンド等が変わっていて習び直し。

1. dnf コマンドで localinstall にてローカルへダウンロードを行う

$ sudo dnf localinstall https://dev.mysql.com/get/mysql84-community-release-el9-1.noarch.rpm

2. dnf コマンドでインストール

$ sudo dnf install mysql-community-server mysql-community-client mysql-community-devel

3. インストールしたらmysqld を自動起動に設定する

$ sudo systemctl enable mysqld

4. MySQLサーバを起動する

$ sudo systemctl start mysqld

5. 初期パスワードは /var/log/mysqld.log に出力されているとのことなので下記を grep で抽出すると一時パスワードが取得できる

$ sudo cat /var/log/mysqld.log | grep 'A temporary password is generated for root@localhost:'

6. 上記で取得したパスワードをコピーして下記のパスワードにペーストする

$ mysql -u root -p
Enter password: 

7. ログイン成功

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.4.4

Copyright (c) 2000, 2025, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

8. root のパスワードを変更しておく

mysql> set password for root@localhost='xxxxxxxx';
Query OK, 0 rows affected (0.01 sec)

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

PostgreSQL DB変更

\c databasename
Posted in PostgreSQL, 技術情報 | Leave a comment