WordPress – millions use this powerful, open-source, customizable, pluggable CMS worldwide to create blogs and fully functional websites. It is easy to use and understand, even for those with no previous website design or development experience. There are millions of themes and plugins available that have been developed by a dedicated community of developers and users. You can use these to customize your website or blog to look exactly how you want it to.
There are many ways to access WordPress. However, some setups are more complicated than others. This tutorial will demonstrate how to install WordPress on Ubuntu 20.04 with the LAMP stack. You will also learn how to set up and configure a fully functional LAMP stack, including installing the Apache web server and MySQL database server.
Prerequisite
You will need to have access to an Ubuntu 20.04 server in order to follow the steps in this tutorial.
Before I install WordPress using a LAMP stack, let me briefly explain what a LAMP stack is.
LAMP Stack
The LAMP stack is a popular open-source solution stack used primarily for web development. LAMP stands for Linux, Apache MySQL, PHP, and Perl. It consists of four necessary components for a fully functional web development environment.
Linux: Linux is the first layer. It is a free, open-source operating system created in the mid-1990s. Linux is the foundation of the stack model and for all other layers.
Apache: This layer is made up of web server software. It is usually Apache Web Server and is located on top of Linux. Web servers translate web browsers to the correct website. Apache’s web server processes requests and delivers web assets via HTTP to make the application accessible through a simple URL to everyone in the public domain.
MySQL: This is the third layer where databases reside. MySQL is an open-source relational database management software for storing application data. MySQL stores information that can be accessed by scripting to build a website. It is usually found on top of Apache/layer two and the Linux layer. MySQL can be offloaded to a separate host server in high-end configurations.
PHP: Our fourth and final layer. PHP is an open-source scripting language that Apache can use to create dynamic web pages. The scripting layer is made up of PHP or similar web programming languages. This layer hosts websites and web applications.
Now, let’s start with the LAMP stack and WordPress installation.
Step 1: Install Apache
Open the terminal on your Ubuntu system. The terminal is a text interface to your computer, which you will use to run all the commands.
First, update your software package list.
ubuntu@ubunu2004:~$ sudo apt-get update
The next step in setting up the LAMP stack will be installing and configuring Apache2, the web server. Run the below command to install Apache 2 on Ubuntu 20.04.
ubuntu@ubunu2004:~$ sudo apt install apache2
It is necessary to allow Apache2 to start at the system boot time and to start the service to verify its status as well.
ubuntu@ubunu2004:~$ sudo systemctl enable apache2 ubuntu@ubunu2004:~$ sudo systemctl status apache2
Open your web browser, and type localhost in the address box to verify that the Apache server has been started.
If the Apache2 web server is running, it will display the default Apache2 index page.
Step 2: Install MySQL
After Apache has been started, it is time to install MySQL. Run the following command in the terminal to do this:
ubuntu@ubunu2004:~$ sudo apt install mysql-server
It is highly recommended that you run a security program after the database server has been installed to remove unsecure default settings and protect your database.
ubuntu@ubunu2004:~$ sudo mysql_secure_installation
You will be asked to install the validate_password plugin. So, type Y/Yes, then press Enter and finally choose the default password strength.
To answer the remaining questions, press Y and hit the ENTER key for each prompt.
This command will also enable MySQL to begin on boot.
ubuntu@ubunu2004:~$ sudo systemctl enable mysql ubuntu@ubunu2004:~$ sudo systemctl status mysql
Step 3: Install PHP
Our LAMP stack setup ends with PHP. WordPress is a PHP-based CMS. We need PHP to process the dynamic content on our WordPress site.
Ubuntu 20.04 defaults to PHP 7.4. We will need additional modules to allow PHP to communicate with Apache and MySQL instances. The following command will install PHP along with the MySQL and Apache modules:
ubuntu@ubunu2004:~$ sudo apt install php libapache2-mod-php php-mysql
WordPress and many plugins use PHP extensions, which you will need to install manually.
ubuntu@ubunu2004:~$ sudo apt install php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip
The following command will verify that PHP 7.4 has been successfully installed:
ubuntu@ubunu2004 :$ php -v
After PHP has been installed and any required extensions have been installed, Apache must be restarted to load the new extensions.
ubuntu@ubunu2004:~$ sudo systemctl restart apache2
Step 4: Install WordPress
Once we have set up our LAMP environment, we can begin installing WordPress. First, we will download the WordPress installation files and place them in the default web server root directory /var/www/html.
ubuntu@ubunu2004:~$ cd /var/www/html
Now download the latest WordPress install with the following command.
ubuntu@ubunu2004:/var/www/html$ sudo wget -c http://wordpress.org/latest.tar.gz
Extract the files
ubuntu@ubunu2004:/var/www/html$ sudo tar -xzvf latest.tar.gz ubuntu@ubunu2004:/var/www/html$ ls -l
The extracted WordPress files will be now placed in the WordPress directory at the following location on your server
/var/www/html/wordpress
The user of your web server must own these files.
We are using Apache as our web server. Apache is running on Ubuntu 20.04. The following command will allow you to change the owner of these files and set the appropriate permissions:
ubuntu@ubunu2004: sudo chown -R www-data:www-data /var/www/html/wordpress
Step 5: Create a Database for WordPress
Next, we will create a WordPress database for the site and set up a user account. This will make it easier to manage the site and increase its security.
Log in to your MySQL root account via Terminal by entering:
When prompted, enter the MySQL root password we have previously set up.
ubuntu@ubunu2004:/var/www/html$ sudo mysql -u root -p
Create a separate database for WordPress to manage
CREATE DATABASE demo_db;
To access the new database, we will create a MySQL user account. Enter a strong password
CREATE USER demo_user@localhost IDENTIFIED BY 'demo-password';
You have just created a new user.
GRANT ALL PRIVILEGES ON demo_db. * TO demo_user@localhost;
After completing the above, flush your privileges to allow MySQL to implement the changes.
FLUSH PRIVILEGES; exit;
Allow the executable permission to be granted to the WordPress folder.
ubuntu@ubunu2004:/var/www/html$ sudo chmod -R 777 wordpress/ ubuntu@ubunu2004:/var/www/html$ cd wordpress/
Step 6: Setup and Configure WordPress
After setting up a database for WordPress, the next and final step is to set up and configure WordPress. Firstly, you need to create a configuration file for WordPress. So, rename the sample WordPress configuration file using the following command:
ubuntu@ubunu2004:/var/www/html/wordpress$ mv wp-config-sample.php wp-config.php
Edit the wpconfig. As shown below, edit the php file.
ubuntu@ubunu2004:/var/www/html/wordpress$ gedit wp-config.php
Update the database settings by replacing demo_db, demo_user, and demo_password with your own details.
Save the file and close it.
Once you have done this, you can access your WordPress page to finish the installation. Open the browser and go to https://localhost/wordpress/
The next screen will open. Click on Continue to select the language.
Click on “Install WordPress” to enter your preferred information, including site title, username, and password.
- Site Title: Enter the WordPress website name. We recommend entering the domain name to optimize your site.
- Username: Create a new username to log in to WordPress.
- Password: Create a password to protect your WordPress account.
- Your email: Add your email address to receive updates and notifications.
- Search engine visibility: You can leave this box unchecked to prevent search engines from indexing your site until it’s ready.
WordPress will now be installed successfully. You can log in to your admin dashboard with the previously set up information.
To log in, enter your username and password.
After successfully logging in, the WordPress dashboard page will greet you.
Congratulations, WordPress installation is successful!
Conclusion
WordPress is a popular content management platform that’s great for creating websites. This article covers all the needed steps to install WordPress on an Ubuntu 20.04 server. First, install Apache2; this will serve as the base for your web server. Next, install MySQL. This will be the database that hosts all WordPress files. Install PHP for WordPress to communicate with the database. Make sure also to install the PHP extensions. After that, download WordPress and install it. Finally, set up WordPress CMS. This tutorial should have shown you how to set up and configure WordPress on Ubuntu. Go ahead and try it for yourself.