Explaining how to build Word Press on AWS
Hello.
I'm Yagitani from the System Solutions Department, and I dyed my hair for the first time in my life last month, but I didn't follow the steps and dyed it blue the first time.
It doesn't seem like I have the option of dyeing it a safe color anymore, so I'm wondering what color I should dye it next.
Now, this is my first post on the Beyond blog, and I'm going to write about how to build a LAMP environment using AWS services, and ultimately how to make it possible to post to WordPress.
It would be too long to write about each service in detail, so I will only briefly write about the settings.
*Web and DB will be created in a configuration where they coexist.
AWS
[VPC]
Name: wp-test-vpc
CIDR: 10.0.0.0/16
[Internet Gateway]
Tag Name:wp-test-igw
Key Name Value: wp-test-igw
Once created, select wp-test-igw and select "Attach to VPC" from the action
Available VPCs: wp-test-vpc
[Route table]
Name tag: wp-test-rt
VPC:
After creating wp-test-vpc, select wp-test-rt ⇒ Edit route ⇒ Add route
Destination: 0.0.0.0/0 Target: wp-test -igw
[Subnet]
Name: wp-test-public-subnet-1a
VPC: wp-test-vpc
CIDR: 10.0.0.0/24
[Security Group]
Security Group Name: wp-test-sg
Description: wp-test-sg
VPC: wp-test-vpc
Inbound Rule
Type: SSH Protocol: TCP Port Range: 22 Source: My IP
Type: HTTP Protocol: TCP Port Range: 80 Source: Custom 0.0.0.0/0
[EC2]
Amazon Linux2
t2.micro
VPC: wp-test-VPC
Subnet: wp-test-public-subnet-1a
Automatically assigned public IP: Valid
storage: Leave as default
Tag Key: Name Value: wp-test-ec2
Security Group :wp-test-sg
key pair:
Create a new key pair
Key pair name wp-test-key
Now that we have completed the work using the AWS console, we will install and configure the middleware on the server.
Connect to the server using ssh, specifying the key, user name, and public IP as shown below, using either a command prompt or Windows Powershell.
ssh -i wp-test.pem ec2-user@[Public IP]
Apache
Let's start by installing Apache.
# yum install httpd -y
It is OK if the last word is "Complete!".
Start Apache
# systemctl start httpd
Set up automatic startup as follows so that it will start automatically even if the instance is restarted.
# systemctl enable httpd
Check below, if it is enabled, it is OK.
# systemctl is-enabled httpd
This time, we will create a VirtualHost with the following settings.
Path: /etc/httpd/conf.d/wp-test.conf
Server name: wp-test
Document root: /var/www/html/wp-test
Access log: /var/log/httpd/wp-test-access_log
Error log: /var/log/httpd/wp-test-error_log
First, create a document root and a file for confirmation.
# vi /var/www/html/wp-test/index.html test
# vi /etc/httpd/conf.d/wp-test.conf <VirtualHost *:80> ServerName wp-test DocumentRoot "/var/www/html/wp-test" CustomLog "/var/log/httpd/wptest -access_log" combined ErrorLog "/var/log/httpd/wptest-error_log" </VirtualHost>
conf file, so restart Apache for it to take effect.
# systemctl restart httpd
Search for the public IP in your browser and if "test" is displayed, it's OK.
Once confirmed, delete index.html.
# rm -f /var/www/html/wp-test/index.html
PHP
Let's move on to PHP.
By default, only the 5.4 series is installed, so install the epel and remi repositories first.
# yum info php Loaded plugins: extras_suggestions, langpacks, priorities, update-motd Available Packages Name : php Arch : x86_64 Version : 5.4.16 Release : 46.amzn2.0.2 Size : 1.4 M Repo : amzn2-core/2/x86_64 Summary : PHP scripting language for creating dynamic web sites URL : http://www.php.net/ License : PHP and Zend and BSD Description : PHP is an HTML-embedded scripting language. PHP attempts to make it : easy for developers to write dynamically generated web pages. PHP also : offers built-in database integration for several commercial and : non-commercial database management systems, so writing a : database-enabled webpage with PHP is fairly simple. The most common : use of PHP coding is probably as a replacement for CGI scripts. : : The php package contains the module (often referred to as mod_php) : which adds support for the PHP language to Apache HTTP Server.
epel repository installation
# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
remi repository installation
# yum install http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
Let's check if 7.3 series is included.
# yum info php --enablerepzo=remi-php73 Loaded plugins: extras_suggestions, langpacks, priorities, update-motd remi-php73 | 3.0 kB 00:00:00 remi-php73/primary_db | 234 kB 00:00:01 261 packages excluded due to repository priority protections Available Packages Name : php Arch : x86_64 Version : 5.4.16 Release : 46.amzn2.0.2 Size : 1.4 M Repo : amzn2-core/2/x86_64 Summary : PHP scripting language for creating dynamic web sites URL : http://www.php.net/ License : PHP and Zend and BSD Description : PHP is an HTML-embedded scripting language. PHP attempts to make it : easy for developers to write dynamically generated web pages. PHP also : offers built- in database integration for several commercial and : non-commercial database management systems, so writing a : database-enabled webpage with PHP is fairly simple. The most common : use of PHP coding is probably as a replacement for CGI scripts. : : The php package contains the module (often referred to as mod_php) : which adds support for the PHP language to Apache HTTP Server.
It's 5.4 series.
The cause is that the amzn2-core repository has a high priority.
# less /etc/yum.repos.d/amazon-2-core.repo [amzn2-core] name=Amazon Linux 2 core repository mirrorlist=$awsproto://$amazonlinux.$awsregion.$awsdomain/$releasever/$ product/$target/$basearch/mirror.list priority=10 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-amazon-linux-2 enabled=1 metadata_expire=300 mirrorlist_expire =300 report_instanceid=yes [omitted]
Since "priority=10" is set, let's lower the priority by setting "priority=99".
# vi /etc/yum.repos.d/amazon-2-core.repo [amzn2-core] name=Amazon Linux 2 core repository mirrorlist=$awsproto://$amazonlinux.$awsregion.$awsdomain/$releasever/$ product/$target/$basearch/mirror.list priority=99 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-amazon-linux-2 enabled=1 metadata_expire=300 mirrorlist_expire =300 report_instanceid=yes [omitted]
Please check again.
# yum info php --enablerepo=remi-php73 Loaded plugins: extras_suggestions, langpacks, priorities, update-motd 1 packages excluded due to repository priority protections Available Packages Name : php Arch : x86_64 Version : 7.3.27 Release : 1.el7. remi Size: 3.2 M Repo: remi-php73 Summary: PHP scripting language for creating dynamic web sites URL: http://www.php.net/ License: PHP and Zend and BSD and MIT and ASL 1.0 and NCSA Description: PHP is an HTML-embedded scripting language. PHP attempts to make it : easy for developers to write dynamically generated web pages. PHP also : offers built-in database integration for several commercial and : non-commercial database management systems, so writing a : database- enabled webpage with PHP is fairly simple. The most common : use of PHP coding is probably as a replacement for CGI scripts. : : The php package contains the module (often referred to as mod_php) : which adds support for the PHP language to Apache HTTP Server.
It is now 7.3 series.
Now let's install the module as well.
# yum install php php-mbstring php-xml php-xmlrpc php-gd php-pdo php-pecl-mcrypt php-mysqlnd php-pecl-mysql --enablerepo=remi-php73
Create a file called index.php under the document root.
# vi /var/www/html/index.php <?php phpinfo(); ?>
Restart Apache, search for the public IP in your browser, and if you see a page like the one above, you're good to go.
MySQL
Next is MySQL.
First, let's install it.
# yum localinstall https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
If you check the mysql version using the command below, I think 8 series is enabled.
# yum repolist all repo id repo name status [Omitted] mysql57-community/x86_64 MySQL 5.7 Community Server disabled mysql80-community/x86_64 MySQL 8.0 Community Server enabled: 229 [Omitted]
This time we want to install the 5.7 series, so we will disable the 8 series and enable the 5.7 series.
Disable 8 series
# yum-config-manager --disable mysql80-community Enable 5.7 series # yum-config-manager --enable mysql57-community
Check if 5.7 series is enabled.
# yum repolist all [omitted] mysql57-community/x86_64 MySQL 5.7 Community Server enabled: 484 mysql80-community/x86_64 MySQL 8.0 Community Server disabled [omitted]
It seems to be fine, so I will install the 5.7 series.
# yum install mysql-community-server
Start MySQL
# systemctl start mysqld
Just like Apache, set it to start automatically.
# systemctl enable mysqld
confirmation
# systemctl is-enabled mysqld enabled
Change your password first before entering MySQL.
Confirm current password
# grep password /var/log/mysqld.log [Note] A temporary password is generated for root@localhost: xxxxxxxxx
The xxxxxx part is the password.
Change password
# mysql_secure_installation Securing the MySQL server deployment. Enter password for user root: [Previous password] The existing password for the user account root has expired. Please set a new password. New password: [New password] Re-enter new password: [ Re-enter] The 'validate_password' component is installed on the server. The subsequent steps will run with the existing configuration of the component. Using existing password for root. Estimated strength of the password: 100 Change the password for root ? ((Press y |Y for Yes, any other key for No) : y New password:【New password】 Re-enter new password: 【Re-enter】 Estimated strength of the password: 100 Do you wish to continue with the password provided?(Press y |Y for Yes, any other key for No) : y By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. #Remove existing users Remove anonymous users? (Press y|Y for Yes, any other key for No) : y Success. Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. #Disallow root login remotely? (Press y|Y for Yes, any other key for No ) : y Success. By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y - Dropping test database... Success. - Removing privileges on test database... Success. Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y Success. All done!
Log in to MySQL and create a database for Word Press.
Login to MySQL
# mysql -u root -p Enter password: [New password you set earlier]
Database creation
mysql >database wp_test_db;
User creation
mysql >create user 'wp_user'@'localhost' identified with mysql_native_password by 'password';
If this continues, the created user (wp_user) will not be able to operate the database (wp_test_db), so grant privileges.
mysql >grant all privileges on wp_test_db.* to wp_user@'localhost';
mysql is now set up.
Word Press
Last but not least is Word Press.
You can install it anywhere, but this time we will use the ec2-user home directory.
# cd /home/ec2-user
Install Word Press package
# wget https://ja.wordpress.org/latest-ja.tar.gz
Verify that it is installed.
# ls latest-ja.tar.gz
If the extension is gz, it is compressed, so use the tar command to decompress it.
# tar -zxvf latest-ja.tar.gz
Verify that it has been extracted using the ls command.
A new directory called wordpress has been created.
# ls latest-ja.tar.gz wordpress
Move all directories and files under the wordpress directory to the document root.
# mv ./wordpress/* /var/www/html/wp-test/
Edit wp-config-sample.php as below
# vi wp-config-sample.php /** Database name for WordPress */ define( 'DB_NAME', 'wp_test_db' ); /** User name for MySQL database */ define( 'DB_USER', 'wp_user' ); /** MySQL database password */ define( 'DB_PASSWORD', '-GrrLr5A7ymN' );
If you've made it this far, it's just a matter of time.
When you search for the public IP in your browser, you will see a screen like the one below.
Click "Let's get started!" and enter the contents entered in wp-config-sample.php (it is okay to leave the table prefix as is).
Then, the wp-config.php file will be created as shown in the image. You will be asked to make a paper and paste the contents, so please follow the instructions calmly.
# vi /var/www/html/wp-test/wp-config.php {Please paste what you copied}
Go back to your browser and proceed.
Finally, decide on a title and username, save your username and password, and press "Install WordPress."
Log in to WordPress, post appropriately, and once it's reflected, you're done!