Installing a LAMP Stack for WordPress on Ubuntu Server

Abhijith Vilangapparayil Prabha
7 min readJun 17, 2023

--

In this article, I will guide you through the process of installing a LAMP stack for WordPress on Ubuntu 22.04.2 LTS. The LAMP stack consists of Linux as the operating system, Apache as the web server, MySQL as the database management system, and PHP as the server-side scripting language. By setting up this stack, you will have a powerful foundation to run WordPress and create dynamic websites.

I will walk you through each step of the installation process, from updating your system packages to configuring WordPress.

By the end of this tutorial, you’ll have a fully functional LAMP stack ready to host your WordPress site.

LAMP architecture

LAMP architecture The LAMP stack consists of the following components:

  1. Linux: We’ll be using Ubuntu 22.04.2 LTS as our Linux distribution. You can use any other Linux distribution of your choice as well.
  2. Apache: Apache is a widely used open-source web server known for its stability and security. It supports virtual hosting, modular architecture, URL rewriting, access control, logging, and security features.
  3. MySQL: MySQL is a popular and powerful open-source relational database management system. It provides a robust and scalable database solution for web applications.
  4. PHP: PHP is a server-side scripting language used for web development. It allows you to create dynamic web pages and interact with databases.

I’ve already set up an Ubuntu machine on my Vmware workstation Pro 17.
You can use Oracle VirtualBox or any other virtualization software for the Ubuntu machine.

Ubuntu Machine Configuration

Ubuntu Machine Configuration

Since it’s a fresh installation of Ubuntu, let’s begin by updating the system packages to ensure we have the latest updates and security patches. Run the following commands.

sudo apt update
sudo apt upgrade

Install Apache

Apache2 is available in the default Ubuntu repositories, so we can easily install it using the following command:

sudo apt install apache2

After the installation is complete, Apache should start automatically. You can check the status of the Apache service using the following command

apachectl -V

check version

To verify if the Apache server has been started on your local machine, open your web browser and enter “localhost” in the address box. If the Apache2 web server is running successfully, you should see the default Apache2 index page displayed in your browser.

Install MySQL

MySQL is also available in the default Ubuntu repositories. To install it, use the following command:

sudo apt install mysql-server

Once the installation is complete, enable the MySQL service to start on boot

sudo systemctl enable mysql-server

To check the status of the MySQL service, use the following command

sudo systemctl status mysql-server

mysql version check

After installing the database server, it is strongly recommended to run a security program to remove insecure default settings and ensure the protection of your database.

sudo mysql_secure_installation

During the installation process, you will be prompted to set a root password for MySQL. Choose a strong password and remember it, as you’ll need it later to access MySQL.

For the remaining questions, press Y and hit the ENTER key for each prompt. This will apply the recommended security configurations.

Type the following command to enable MySQL to begin on boot

sudo systemctl enable mysql

check the status

sudo systemctl status mysql

Install PHP

To install PHP and necessary extensions, run the following command:

sudo apt install php libapache2-mod-php php-mysql

Here’s what each package does:

  1. php: Installs the PHP programming language itself.
  2. libapache2-mod-php: Installs the Apache module for PHP, allowing Apache to process PHP files.
  3. php-mysql: Installs the PHP extension for MySQL, enabling PHP to interact with MySQL databases.

By installing these packages together, you ensure that PHP is properly integrated with Apache and has the necessary extensions to work with MySQL databases.

WordPress and many plugins use PHP extensions, which you will need to install manually.

sudo apt install php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip

Install WordPress

Now that we have Apache, MySQL, and PHP installed, let’s proceed with setting up WordPress. First, we will download the WordPress installation files and place them in the default web server root directory /var/www/html/

cd /var/www/html/

Now download the latest WordPress install with the following command.

sudo wget https://wordpress.org/latest.tar.gz

Extract the files

sudo tar -xzvf latest.tar.gz

The user of your web server must own these files.

Running the command will show the owner of the apache2 webserver

ps -ef | grep apache2

To set the correct ownership and permissions for the extracted WordPress files located at /var/www/html/wordpress/ run the following command

sudo chown -R www-data:www-data /var/www/html/wordpress/

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

sudo mysql -u root -p

Enter the password you set during the MySQL installation.

Once logged in, Create a separate database for WordPress to manage

CREATE DATABASE wordpress_db;

To access the new database, we will create a MySQL user account. Enter a strong password

CREATE USER wordpress_user@localhost IDENTIFIED BY ‘Testpass1!’;

You have created a user ‘wordpress_user’

GRANT ALL PRIVILEGES TO wordpress_db.* TO wordpress_user@localhost;

After completing the above, flush your privileges to allow MySQL to implement the changes.

l

Allow the executable permission to be granted to the WordPress folder.

Setup and Configure WordPress

After preparing the WordPress database, the next and final step is to set up and configure WordPress itself. To do this, you need to create a configuration file specifically for WordPress. Simply rename the sample WordPress configuration file using the given command.

sudo mv wp-config-sample.php wp-config.php

and edit the wp-config.php file using vim editor or any editor

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, the WordPress installation is successful!

In conclusion, this guide has provided simplified instructions for installing WordPress on an Ubuntu server. By following the outlined steps, you can set up the necessary components, such as Apache2, MySQL, and PHP, to enable WordPress functionality. With WordPress successfully installed, you can now create and manage your website with ease.

Stay tuned for my next article, where I will explore the automation magic of Ansible to automate the entire LAMP installation. See you soon, and take care! Goodbye!

Abhi :)

--

--