Install LAMP on Amazon Linux 2 and build a WordPress environment.


The official AWS documentation says Hosting WordPress Blogs with Amazon Linux ( 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.

Construction environment

This version is as follows.

Environmental information

OS:Amazon Linux 2

In addition, we will not touch on the launch of EC2 or Security Group settings, so please take appropriate action.

Software package update

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

Installation of additional packages

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

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

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

Change root password

Since the operation cannot be performed unless the root password is changed for the first time, reset the password.


$ 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.

Database creation

After logging in again, first create the database.

Database creation

mysql> CREATE DATABASE wp_database;

User created

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";

Login confirmation

Login confirmation

$ mysql -uwp_user -p

Version confirmation

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.

Package download

Download the latest package.

Package download

$ wget

If you specify latest.tar.gz in the file name, the latest one will be downloaded.

Package decompression

$ tar -xzf latest.tar.gz

conf settings

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.

wp-config.php fix

$ vim wordpress/wp-config.php
$ diff wordpress/wp-config-sample.php wordpress/wp-config.php
< define( 'DB_NAME', 'database_name_here' );
> define( 'DB_NAME', 'wp_database' );
< define( 'DB_USER', 'username_here' );
> define( 'DB_USER', 'wp_user' );
< define( 'DB_PASSWORD', 'password_here' );
> define( 'DB_PASSWORD', 'g1myqg3lgr#M' );
< 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',       '****************************************************************');

Content copy

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/

WordPress permalink settings

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.


$ 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
<     AllowOverride All
>     AllowOverride None

Authority modification

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 {} \;

apache restart

Once all the settings are done, restart apache (since I also modified httpd.conf).


$ sudo systemctl restart httpd


Access the browser and install. Select ** Japanese ** on the language selection screen. スクリーンショット 2021-01-06 12.45.34.png

Fill in the fields and ** Install WordPress **. 9.png

**Succeeded! If ** is displayed, the process is complete.

スクリーンショット 2021-01-06 12.48.37.png

in conclusion

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.

reference --The following hosting environment is recommended to run WordPress. Install LAMP Web Server on Amazon Linux 2 (Step 1: Prepare LAMP Server) Hosting WordPress Blogs on Amazon Linux

Recommended Posts

Install LAMP on Amazon Linux 2 and build a WordPress environment.
Build Linux on a Windows environment. Steps to install Laradock and migrate
How to build a Python environment on amazon linux 2
Build an LNPP environment on Amazon Linux 2
Build WordPress on CentOS 8 in LAMP environment
[Linux] Build a Docker environment with Amazon Linux 2
Build a Selenium environment on Amazon Linux 2 in the shortest time
Build a LAMP environment [CentOS 7]
Install tomcat 5.5 on Amazon Linux.
Install Homebrew on Amazon Linux 2
Install strongSwan 5.9.1 on Amazon Linux 2
Install Python3 on Mac and build environment [Definitive Edition]
Compile and install MySQL-python for python2.7 on amazon linux
Build a TensorFlow development environment on Amazon EC2 with command copy and paste
Install Python Pillow on Amazon Linux
Install oracle java8 on amazon linux2
How to build a beautiful Python environment on a new Mac and install Jupter Notebook
(Windows10) Install Linux environment and gnuplot.
Build and install OpenCV on Windows
Install Arch Linux on DeskMini A300
Install pyenv on EC2 (Amazon Linux)
Create a Linux environment on Windows 10
How to create a Python 3.6.0 environment by putting pyenv on Amazon Linux and Ubuntu
[Note] Install Imagick on Amazon Linux2
Build a python3 environment on CentOS7
Build a LAMP environment with Vagrant (Linux + Apache + MySQL + PHP)
Introduce Python 3.5.2 environment on Amazon Linux
How to build a LAMP environment using Vagrant and VirtulBox Note
[MariaDB] Install MariaDB on Linux and create a DB and an operating user.
Build a Chainer environment using CUDA and cuDNN on a p2 instance
Build a 64-bit Python 2.7 environment with TDM-GCC and MinGW-w64 on Windows 7
Build a Python environment on your Mac with Anaconda and PyCharm
I'll install Ruby on EC2 (Amazon Linux2) 2020
[UE4] Build DedicatedServer on Windows and Linux
Building a Python3 environment with Amazon Linux2
Build Python3 and OpenCV environment on Ubuntu 18.04
Build a python environment on MacOS (Catallina)
Install wsl2 and master linux on windows
Build a simple WebDAV server on Linux
Install and launch k3s on Manjaro Linux
Install and Configure TigerVNC server on Linux
Learn sshd_config and authorized_keys (on Amazon Linux 2)
Build a Samba server on Arch Linux
How to install Anisble on Amazon Linux 2
[Linux] Build a jenkins environment with Docker
Build a Python + OpenCV environment on Cloud9
Install rJava on Linux in R3.6 environment.
Install Python 3.8, Pip 3.8 on EC2 (Amazon Linux 2)
Procedure for building a kube environment on amazon linux2 (aws) ~ (with bonus)
A story I was addicted to trying to install LightFM on Amazon Linux
Build a CentOS Linux 8 environment with Docker and start Apache HTTP Server
Summary of how to build a LAMP + Wordpress environment with Sakura VPS
Install Python3 and Django on Amazon Linux (EC2) and run your web server
Build a WardPress environment on AWS with pulumi
Simply build a Python 3 execution environment on Windows
Build a Django environment on Raspberry Pi (MySQL)
Build a python environment with ansible on centos6
Build a Python environment on Mac (Mountain Lion)
Build a Python development environment on your Mac
Build a virtual environment with pyenv and venv
Build a Kubernetes environment for development on Ubuntu