The official AWS documentation says Hosting WordPress Blogs with Amazon Linux (https://docs.aws.amazon.com/ja_jp/AWSEC2/latest/UserGuide/hosting-wordpress.html). However, it is hard to say that it is based on the latest version because the prerequisite LAMP environment is a procedure using php7.2. Also, looking at the current (2021/01/08) WordPress requirements, it is ** "PHP version 7.4 or higher" **** "MySQL version 5.6 or higher, or MariaDB version 10.1 or higher" **, etc. Requirement is not met. So, this time I would like to build a WordPress environment using php7.4 and mysql8.0.
This version is as follows.
Environmental information
OS:Amazon Linux 2
PHP:7.4
MySQL:8.0.22
WordPress:5.6
In addition, we will not touch on the launch of EC2 or Security Group settings, so please take appropriate action.
First, update the software to keep all software packages up to date.
Package update
$ sudo yum update -y
PHP First, install php. Install using the repository provided by AWS, and install additional packages that may be needed.
Install the Amazon Linux Extras repository to get the latest version of the Amazon Linux 2 PHP package.
php version check
$ amazon-linux-extras list |grep php
15 php7.2 available \
17 lamp-mariadb10.2-php7.2 available \
31 php7.3 available \
42 php7.4 available [ =stable ]
The latest version at the moment is php7.4, so install the php7.4 repository.
Repository installation
$ sudo amazon-linux-extras enable php7.4
~~abridgement~~
Now you can install:
# yum clean metadata
# yum install php-cli php-pdo php-fpm php-json php-mysqlnd
When you install the repository, you will see Now you can install:
, so run it.
Delete metadata
$ sudo yum clean metadata
php install
$ sudo yum install php-cli php-pdo php-fpm php-json php-mysqlnd
In addition, install the packages that you may need.
Additional packages
$ sudo yum install php php-gd php-mbstring php-opcache php-xml php-common
Version confirmation
$ php -v
PHP 7.4.11 (cli) (built: Oct 21 2020 19:12:26) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.11, Copyright (c), by Zend Technologies
MySQL Next is the installation of mysql.
Since there is no repository by default, add the repository from the MySQL site and install it.
Repository installation
$ sudo yum localinstall https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
mysql installation
$ sudo yum install --enablerepo=mysql80-community mysql-community-server mysql-community-devel
start mysql
$ sudo systemctl start mysqld.service
Enable mysql autostart
$ sudo systemctl enable mysqld.service
The first root password will be printed to mysql.log
.
Confirm root password
$ sudo grep password /var/log/mysqld.log
2021-01-06T02:45:38.728477Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: g1myqg3lgr#M
Since the operation cannot be performed unless the root password is changed for the first time, reset the password.
Login
$ mysql -uroot -p
You can set the same password.
Change Password
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'g1myqg3lgr#M';
After completing the settings, log out and log in again.
After logging in again, first create the database.
Database creation
mysql> CREATE DATABASE wp_database;
Next, create a user for WordPress that can access the database.
User created
mysql> CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'g1myqg3lgr#M';
mysql> GRANT ALL PRIVILEGES ON `wp_database `.* TO "wp_user"@"localhost";
mysql> FLUSH PRIVILEGES;
Login confirmation
$ mysql -uwp_user -p
Version confirmation
$ mysql --version
mysql Ver 8.0.22 for Linux on x86_64 (MySQL Community Server - GPL)
Apache When you install php, apache is installed as a dependency. Therefore, you can just start it.
Start apache and enable the autostart setting.
start apache
$ sudo systemctl start httpd
Enable apache autostart
$ sudo systemctl enable httpd
apache version check
$ httpd -v
Server version: Apache/2.4.46 ()
Server built: Aug 24 2020 18:54:20
WordPress Now that you have the software you need, it's time to install WordPress.
Download the latest package.
Package download
$ wget https://wordpress.org/latest.tar.gz
If you specify latest.tar.gz
in the file name, the latest one will be downloaded.
Package decompression
$ tar -xzf latest.tar.gz
Copy the wp-config-sample.php
file with the name wp-config.php
.
wp-config.php creation
$ cp wordpress/wp-config-sample.php wordpress/wp-config.php
Set the copied wp-config.php
to the database and user created in mysql.
Also, set KEY
and SALT
in the section called Authentication Unique Keys and Salts
.
Get and set the randomly generated key set value from the following URL.
https://api.wordpress.org/secret-key/1.1/salt/
wp-config.php fix
$ vim wordpress/wp-config.php
$ diff wordpress/wp-config-sample.php wordpress/wp-config.php
23c23
< define( 'DB_NAME', 'database_name_here' );
---
> define( 'DB_NAME', 'wp_database' );
26c26
< define( 'DB_USER', 'username_here' );
---
> define( 'DB_USER', 'wp_user' );
29c29
< define( 'DB_PASSWORD', 'password_here' );
---
> define( 'DB_PASSWORD', 'g1myqg3lgr#M' );
49,56c49,56
< define( 'AUTH_KEY', 'put your unique phrase here' );
< define( 'SECURE_AUTH_KEY', 'put your unique phrase here' );
< define( 'LOGGED_IN_KEY', 'put your unique phrase here' );
< define( 'NONCE_KEY', 'put your unique phrase here' );
< define( 'AUTH_SALT', 'put your unique phrase here' );
< define( 'SECURE_AUTH_SALT', 'put your unique phrase here' );
< define( 'LOGGED_IN_SALT', 'put your unique phrase here' );
< define( 'NONCE_SALT', 'put your unique phrase here' );
---
> define('AUTH_KEY', '****************************************************************');
> define('SECURE_AUTH_KEY', '****************************************************************');
> define('LOGGED_IN_KEY', '****************************************************************');
> define('NONCE_KEY', '****************************************************************');
> define('AUTH_SALT', '****************************************************************');
> define('SECURE_AUTH_SALT', '****************************************************************');
> define('LOGGED_IN_SALT', '****************************************************************');
> define('NONCE_SALT', '****************************************************************');
To run WordPress in the document root, copy the content as follows: The point to keep in mind here is that the directory itself is not copied.
Content copy
$ sudo cp -r wordpress/* /var/www/html/
You must use Apache's .htaccess
file for WordPress permalinks to work properly, but Amazon Linux is not enabled by default. Modify AllowOverride
in the section starting with<Directory "/ var/www/html">
to All
so that you can overwrite everything in the Apache document root.
python
$ sudo cp -pi /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf_org
$ sudo vim /etc/httpd/conf/httpd.conf
$ diff /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf_org
151c151
< AllowOverride All
---
> AllowOverride None
Some of the features available in WordPress require write permission to the document root (using the admin screen, uploading media, etc.).
First, grant file ownership of / var/www
and its contents to ** apache users/groups **.
Ownership change
$ sudo chown -R apache /var/www
$ sudo chgrp -R apache /var/www
Next, set the group write permission for / var/www
and its subdirectories.
By setting setgid, the created files belong to the group to which the directory belongs.
Change permissions(directory)
$ sudo chmod 2775 /var/www
$ find /var/www -type d -exec sudo chmod 2775 {} \;
Repeatedly change the file permissions for / var/www
and its subdirectories to add write permissions for the group.
Change permissions(File)
$ find /var/www -type f -exec sudo chmod 0664 {} \;
Once all the settings are done, restart apache (since I also modified httpd.conf).
Reboot
$ sudo systemctl restart httpd
Access the browser and install. Select ** Japanese ** on the language selection screen.
Fill in the fields and ** Install WordPress **.
**Succeeded! If ** is displayed, the process is complete.
This method is a general-purpose method, so if a new version of php or mysql is released in the future, I think that it can be handled by increasing the version accordingly.
--ja.wordpress.org --The following hosting environment is recommended to run WordPress. -docs.aws.amazon.com-Tutorial: Install LAMP Web Server on Amazon Linux 2 (Step 1: Prepare LAMP Server) -docs.aws.amazon.com-Tutorial: Hosting WordPress Blogs on Amazon Linux
Recommended Posts