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

Apache installation

$ sudo yum install -y httpd
$ sudo systemctl start httpd

Install MySQL 5.7

Install MySQL 5.7 from the MySQL Yum Repository.

$ sudo yum localinstall https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
$ 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
$ sudo yum install -y mysql-community-server
$ sudo systemctl start mysqld
$ sudo cat /var/log/mysqld.log | grep root @ localhost
[Note] A temporary password is generated for root @ localhost: 12-digit string
$ 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.
$ 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.

$ which amazon-linux-extras
/ usr / bin / amazon-linux-extras
$ sudo yum install -y amazon-linux-extras
$ sudo yum update -y
$ 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

#Move to the directory you want to install
$ cd ~
$ wget http://ja.wordpress.org/latest-ja.zip
$ unzip latest-ja.zip
#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');

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
#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

Install PHP 7.4 on AWS EC2 (Amazon Linux)