WordPress environment construction using AWS (single configuration)
Sep 7, 2020
PHP
WordPress
MySQL
Apache
AWS
Advance preparation
Create an EC2 instance
SSH connection
$ ssh -i .ssh / key.pem ec2-user @ public_ip
-
Key.pem is ssh_key
-
Public_ip is the public_ip of the instance
Apache installation
- Install and start Apach
$ sudo yum install -y httpd
$ sudo systemctl start httpd
Install MySQL 5.7
Install MySQL 5.7 from the MySQL Yum Repository.
- Install Yum repository information
$ sudo yum localinstall https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
- Disable MySQL8.0 repository and enable MySQL5.7 repository
$ sudo yum-config-manager --disable mysql80-community
$ sudo yum-config-manager --enable mysql57-community
#Check if it is applied
$ cat /etc/yum.repos.d/mysql-community.repo
- Install / start MySQL
$ sudo yum install -y mysql-community-server
$ sudo systemctl start mysqld
- Check the initial password for MySQL
$ sudo cat /var/log/mysqld.log | grep root @ localhost
[Note] A temporary password is generated for root @ localhost: 12-digit string
- Change MySQL password
$ mysqladmin -uroot -p password
Enter password: old password
New password: New password
Confirm new password: new password
Even if #Warnig appears, it can be changed
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
-
Create a DB / user for WordPress
$ mysql -uroot -p
Enter password: Set password
#Create user for WordPress
mysql> CREATE USER'wordpress' @'localhost' IDENTIFIED BY'wordpress user password';
#Create DB for WordPress
mysql> CREATE DATABASE `wordpress`;
Grant #DB privilege to the user who created it
mysql> GRANT ALL PRIVILEGES ON `wordpress`. * TO" wordpress "@" localhost ";
#Reflect settings
mysql> FLUSH PRIVILEGES;
mysql> EXIT;
Install PHP 7.4
Running sudo yum install php
will install PHP 5.4.
This is because there is only PHP 5.4 in the Amazon Linux repository.
This can be solved by using amazon-linux-extras.
- Check if amazon-linux-extras exists
$ which amazon-linux-extras
/ usr / bin / amazon-linux-extras
- If amazon-linux-extras is not installed, install it
$ sudo yum install -y amazon-linux-extras
$ sudo yum update -y
- Install PHP 7.4 from amazon-linux-extras
$ sudo amazon-linux-extras install -y php7.4
$ sudo yum clean metadata
#Install additional packages (not needed if not needed)
$ sudo yum install -y php-mbstring php-xml
$ sudo yum update -y
Install WordPress
- Install WordPress
#Move to the directory you want to install
$ cd ~
$ wget http://ja.wordpress.org/latest-ja.zip
$ unzip latest-ja.zip
- Perform Edit configuration file.
#Copy sample
$ cp wordpress / wp-config-sample.php wordpress / wp-config.php
$ sudo vim wordpress / wp-config.php
Change the setting value of #DB.
define ('DB_NAME','database_name_here');
define ('DB_USER','username_here');
define ('DB_PASSWORD','password_here');
define ('DB_HOST','localhost');
#Change the security key.
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');
-
Please use Online Generator as the security key.
-
Apach settings
For Amazon Linux, .htaccess
is disabled by default and needs to be configured.
Write the settings in conf.d
instead of the actual parent file /etc/httpd/conf/httpd.conf
.
$ sudo vim /etc/httpd/conf.d/file_name.conf
# Specify the URI you want to access in "sample"
# Specify the installed directory for "/ home / ec2-user / wordpress /"
Alias / sample / / home / ec2-user / wordpress /
<Directory "/ home / ec2-user / wordpress">
AllowOverride All
Options None
Require all granted
Described when limiting #ip
Require ip ××××××××××××
</ Directory>
#Apache Grammar Check
$ sudo httpd -t
Syntax OK
$ sudo systemctl restart httpd
-
If you access
http: // host / sample /
and open the WordPress initial setting screen, you are successful! -
If a 403 error occurs when accessing, set the authority.
#Grant execution authority
# Specify the installed directory for "/ home / ec2-user"
$ sudo chmod o + x / home / ec2-user
Please let me know if there are any mistakes! Redundancy configuration will be updated at a later date!
Reference
Hosting WordPress Blogs with Amazon Linux
Install the latest version of MySQL 5.7 with yum on CentOS 7