Introduction
The news says CentOS 8 will end in 2021, so I decided to rewrite my article below.
VirtualBoxでLAMP環境を構築し、WordPressをインストールする
It will not be worth article about installing LAMP stack on CentOS 8.
What is the LAMP Stack?
LAMP stack stands for:
Linux | Operating System Layer |
Apache | Web Server Layer |
MariaDB | Database Server Layer (MySQL) |
PHP | Scripting Layer (Python, Perl) |
LAMP stack is a popular open source web development platform.
Prerequisites
- Install Ubuntu 20.04 on Oracle VM VirtualBox.
- Change networking mode to Bridged.
Apache 2.4
Installing Apache
To update local package index, execute the following command:
# apt update
To install Apache, execute the following command:
# apt install apache2
After the installation is complete, enable Apache to start automatically at server boot by typing:
# systemctl enable --now apache2
Testing Apache
To check your private IP address, run:
# ip a
Search the above ip command output and look for your network interface name and private IP address. To verify Apache installation from CLI, execute the following command:
# curl http://192.168.0.6
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!--
Modified from the Debian original for Ubuntu
Last updated: 2016-11-16
See: https://launchpad.net/bugs/1288690
-->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Apache2 Ubuntu Default Page: It works</title>
<style type="text/css" media="screen">
* {
margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px;
}
・・・・
Make sure that curl command can get a page labeled “Apache2 Ubuntu Default Page”.
Next, open your web browser and type in the address bar:
http://IP_address
Make sure that the web browser can open a page labeled “Apache2 Ubuntu Default Page”.

MariaDB 10.3
Installing MariaDB
To install MariaDB, execute the following command:
# apt install mariadb-{server,client}
Configuring MariaDB
mysql_secure_installation is a simple shell script that enables you to improve the security of your MariaDB installation. Start the interactive script by running:
# mysql_secure_installation
-------(省略)---------
Enter current password for root (enter for none): # Return
Set root password? [Y/n] # Return
New password: # type
Re-enter new password: # type
Password updated successfully!
Reloading privilege tables...
... Success!
Remove anonymous users? [Y/n] # Return
.... Success!
Disallow root login remotely? [Y/n] # Return
... Success!
Remove test database and access to it? [Y/n] # Return
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reload privilege tables now? [Y/n] # Return
.... Success!
Setting Up for WordPress
You should create user and database for wordpress by running:
# mysql -uroot -p<rootパスワード>
-------(省略)----------
MariaDB [(none)]> create user username@localhost identified by '<パスワード>';
Query OK, 0 rows affected (0.000 sec)
MariaDB [(none)]> create database databasename;
Query OK, 1 row affected (0.000 sec)
MariaDB [(none)]> grant all privileges on databasename.* to username@localhost;
Query Ok, 0 rows affected (0.000 sec)
MariaDB [(none)]> exit
Bye
PHP 7.4
Installing PHP
To install PHP 7.4, execute the following command:
# apt install php7.4 php7.4-{mysql,mbstring}
To check the version of PHP installed on the system, run:
# php -v
PHP 7.4.3 (cli) (built: Oct 6 2020 15:47:56) ( NTS )
・・・・・
Testing PHP
To test PHP processing on web browser, you should create a index.php in the /var/www/html directory by running:
# cd /var/www/html
# vi index.php
<?php echo phpinfo(); ?>
Next, open your web browser and type in the address bar:
http://192.168.0.6/index.php
If you can see information about your PHP configuration, it means PHP is processing fine.

After testing, you should remove this file because it is unsafe that anyone can see this information about your system configuration.
# rm index.php
WordPress 5.6
Downloading WordPress
You can change your location to /tmp directory and start downloading WordPress by running:
# cd /tmp
# wget https://wordpress.org/latest.tar.gz
To extract this file, execute the following command:
# sudo tar -zxvf latest-ja.tar.gz -C /var/www/
To change the ownership, execute the following command:
$ sudo chown -R www-data.www-data /var/www/wordpress
Configuring Apache
To modify default DocumentRoot directive, edit the Apache configuration file.
# vim /etc/apache2/sites-enabled/000-default.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/wordpress # Change html to wordpress
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
To restart Apache, execute the following command:
# systemctl restart httpd
Editing wp-config.php
You can change your location to /var/www/wordpress directory and copy a sample configuration file with another name “wp-config.php” by running:
# cd /var/www/wordpress
# cp wp-config-sample.php wp-config.php
This file contains some settings for MariaDB connection. You should replace these with your setting.
# vi wp-config.php
-----------------------------------------
define( 'DB_NAME', '*********' );
define( 'DB_USER', '*********' );
define( 'DB_PASSWORD', '********* );
・・・・・・・
Setting Up WordPress
Now you can access WordPress via web browser by typing in the address bar:
http://IP_address
Then, you can see the image for setting up WordPress. Select the setting you would like to use.

After completing all settings, you need to log in your WordPress.

Finally, If you can see a Dashbord page, it means WordPress installation is complete.

Conclusion
The LAMP stack that we built this time is test environment for studying. It is dangerous to use in production environment, so we didn’t set up security configuration. If you use the LAMP stack in production environment, you should build and configure by AWS(Amazon Web Services), but not VirtualBox.
Sorry for my poor English. I hope this helps you!
References
標準テキスト CentOS7 構築・運用・管理パーフェクトガイド
How To Install WordPress on Ubuntu 20.04 with a LAMP Stack
How To Install Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu
Comments