How to deploy WordPress on a Ubuntu LAMP Server

Where necessary, you may need to have access to a VPS server so you can follow how to implement the steps in this article.  You can get a cheaper VPS Server from Contabo with 4vCPU cores, 8GM RAM, and 32TB Bandwidth for less than $5.50 per month. Get this deal here now

Table of Contents

Cloud VPS S

$5.50 Monthly
  • 4 vCPU Cores | 8GB RAM


$15.50 Monthly
  • 6 vCPU Cores | 16GB RAM


$17.50 Monthly
  • 8 vCPU Cores | 24GB RAM

In this article, we would like to learn the in-depth part of the LAMP stack and how to use it to deploy dynamic web applications like WordPress. If you’re an absolute beginner in this area, no worries as we’re here to hold your hand so you can learn step by step. Let’s get started 🙂

LAMP Overview

LAMP is an acronym for: Linux, Apache, MySQL, and PHP. The LAMP stack is critical to hosting dynamic applications like those written in PHP language. Since WordPress is written in PHP as its core language, LAMP provides the perfect stack to achieve optimal performance.

All four components that make up the LAMP stack are necessary to host your WordPress website on a VPS machine.

Let’s try to break them down one by one below;

RECOMMENDED READING: How can I install an Open SSH Server on Ubuntu Linux?


This is the operating system that runs on the server. And just to let you know, Linux is the most commonly used operating system for servers. Over 90% of all cloud infrastructure, including servers, runs on Linux.

Linux is a choice operating system for hosting WordPress or any other web application out there because it’s open-source, more secure, and offers better performance compared to Windows servers in an enterprise web hosting environment.

RECOMMENDED READING: How to use Alibaba Cloud Free credit to Set up an Ubuntu server


Apache is a web server software that handles HTTP requests and responses. When your WordPress site is hosted on the server, Apache listens to incoming requests and responds back to those requests with the desirable content website visitors need. So, it’s the Apache server doing the behind-the-scenes logic to serve your website visitors with the content they’re looking for.


MySQL is the database management system that stores the website’s data.

When you install WordPress on a LAMP stack, it stores all of its data, including posts, pages, comments, and settings, in a MySQL database. WordPress uses MySQL to create, read, update, and delete data, allowing you to manage and display content on your website.

MySQL is responsible for ensuring the reliability, security, and scalability of the data storage used by WordPress. It provides features such as transactional support, ACID compliance, and a powerful query language that allows you to retrieve and manipulate data in a variety of ways.

RECOMMENDED READING: How to host a Laravel application on Ubuntu using Apache


PHP is the scripting language used to create dynamic web pages.

In this context, PHP is responsible for dynamically generating the HTML, CSS, and JavaScript that make up the WordPress website. It interacts with the WordPress core, plugins, and themes to generate the final output that is sent to the user’s web browser.

PHP is also responsible for connecting to the MySQL database server, which stores all the content and settings of the WordPress website. It retrieves the necessary data from the database and uses it to generate the pages requested by the user.

Without PHP, WordPress would not be able to function as a dynamic and interactive web application. Therefore, it is essential to have a compatible version of PHP installed and properly configured on the webserver to host a WordPress site.

Installing LAMP stack for WordPress

LAMP can be installed on common Linux Distros like Ubuntu, CentOS, and many more.

But the most common question people keep asking is: how much CPU & RAM do you need to run LAMP? Well, in the context of running WordPress, it will depend on the size of your site in terms of the number of plugins and the number of visitors. Large WordPress sites with many plugins are likely to need more computing power to achieve desirable performance. Furthermore, if you’re expecting more daily and monthly site visitors, you will also need to get a good VPS machine that can handle the load.

RECOMMENDED READING: How to Install WordPress on a VPS Server using Cloudron?

In most cases, when your WordPress site is small with limited traffic, 1 CPU core and 500MB RAM are just enough. But if your WordPress has more plugins and sizeable traffic, 4CPU cores and 6-8GB RAM can be a great way to optimize performance.
You should remember that there are various factors that can come into play if you’re to achieve high performance for your WordPress.

Update the System

As the common rule in the Linux community, every time you want to install a certain package or software, it’s advisable to first update your system. So, on your Linux terminal, run the following commands to update and upgrade;

apt update -y
apt upgrade -y

Install LAMP Server packages

We can install the LAMP stack with just one command, and it will ship with all the necessary packages once we specify them. Here is the command with defined packages and libraries we need to get the server ready for WordPress;

apt install apache2 mariadb-server php php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap libapache2-mod-php php-mysql -y

Let’s break down the meaning of the above command;

  • apt install: This is a command that installs software packages on Debian-based Linux systems.

  • apache2: This package installs the Apache web server.

  • mariadb-server: This package installs the MariaDB database server, which is a drop-in replacement for MySQL.

RECOMMENDED READING: How to download and install Ubuntu Linux on a Laptop

  • php: This package installs the PHP scripting language.

  • php-curl: This package provides support for cURL, a library for making HTTP requests.

  • php-gd: This package provides support for the GD library, which is used for image manipulation.

  • php-mbstring: This package provides support for multibyte string functions.

  • php-xml: This package provides support for XML parsing and manipulation.

  • php-xmlrpc: This package provides support for the XML-RPC protocol, which is used for remote procedure calls.

RECOMMENDED READING: How to Secure HLS & DASH Streams in Ant Media Server?

  • php-soap: This package provides support for SOAP, a protocol used for exchanging structured information between web services.

  • libapache2-mod-php: This package provides a module for Apache that allows it to work with PHP.

  • php-mysql: This package provides support for connecting PHP to MySQL databases.

  • -y: This flag tells apt to automatically answer “yes” to any prompts or confirmations during the installation process so that the installation can proceed without user input.

RECOMMENDED READING: How are Protocols implemented in applications?

Enable Apache Service

Apache server uses its background service to listen for incoming requests from clients, such as web browsers. When a request is received, Apache serves the appropriate content from the website’s root file system and sends it back to the client as a response.

Once you’ve installed the LAMP stack, you can enable the Apache service by running the following commands;

systemctl start apache2
systemctl enable apache2

Create WordPress Database

Just like any dynamic application that stores and retrieves data, WordPress needs to have its Database created so things like settings, User login data, posts, comments, pages, and other important data are stored on it.

So, WordPress uses MySQL for its backend database to store content, and we need to run the following command for its secure installation;


You Will be promoted to answer a couple of questions. Follow the steps below:

[ Please make sure you set your MySQL root password as you will need it after this step ].

Enter current password for root (enter for none): Press ENTER
Set root password? [Y/n]: Y
New password: Set-your-new-password
Re-enter new password: Set-your-new-password
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

We can now log into the database using the root credentials using the following command;

mysql -u root -p

Once you’ve executed the above command, you will be prompted to enter the root MySQL password you created earlier.

RECOMMENDED READING: How to install Ant Media Server on VPS

Now, that we’re inside the database terminal, we need to create the database named, wordpressdb and the Database user named wordpressusr. You can name your database and user anything you like. Here are the commands to create both database and database user;

CREATE DATABASE wordpressdb;
CREATE USER 'wordpressusr'@'localhost' IDENTIFIED BY 'yourpassword';

Make sure you insert your database user password by replacing; ‘yourpassword’ with the actual password, you want to be used.

The next step is to grant all the privileges to the wordpressdb database with the following command.

GRANT ALL PRIVILEGES ON wordpressdb.* TO 'wordpressusr'@'localhost';

We can flush the privileges and then exit the MySQL shell by running the following commands:


Download WordPress

We need to first go to the default Apache website directory: /var/www/html by running the following command:

cd /var/www/html

Download the latest WordPress

And it’s from here that we will be able to download the latest WordPress by running the following command:

sudo wget

Unzip the downloaded Zip file

RECOMMENDED READING: How to install and configure UFW firewall on Ubuntu Linux

Because our WordPress is packaged as a zip file, we need to unzip all the content in it by running the following command:

tar -xvzf latest.tar.gz

Change to WordPress directory

Once you’ve unzipped the file, we need to move to the WordPress directory by running the following command:

cd wordpress

Rename the WordPress configuration file

WordPress by default ships with a configuration file named: wp-config-sample.php. And we need to rename it the proper way as: wp-config.php. We can achieve this by running the following command:

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

Edit the configuration file

Once the configuration file is renamed to wp-config.php, we need to edit by running the following command:

nano wp-config.php

Change the following lines:

define( 'DB_NAME', 'wordpressdb' );

/** Database username */
define( 'DB_USER', 'wordpressusr' );

/** Database password */
define( 'DB_PASSWORD', 'yourpassword' );

/** Database hostname */
define( 'DB_HOST', 'localhost' );

Make sure you insert your appropriate credentials in the configuration files like the database name, database user, and the database user password

Save and close the file then change the ownership and permission of the WordPress directory by running the following commands:

chown -R www-data:www-data /var/www/html/wordpress
chmod -R 775 /var/www/html/wordpress

RECOMMENDED READING: Step-by-Step Guide to Installing FTP on Ubuntu Server

Create Apache Virtual Host for WordPress

An Apache Virtual Host file is a configuration file used by the Apache webserver to specify different configurations for different domains or subdomains on the same server. Virtual Hosts allow multiple websites to run on a single web server, each with its own domain name or IP address.,

The Virtual Host file typically contains directives such as the server name, the document root directory where the website files are stored, and other settings like access controls, SSL certificates, and logging options. The Virtual Host file also specifies which domain or IP address the configuration should apply to.

Virtual Host files are located in the Apache configuration directory, usually named httpd.conf or apache2.conf, or or 000-default.conf in a separate directory called conf.d or sites-available on some Linux systems. Once configured, Virtual Hosts, define the document root of our website, and also allow web administrators to host multiple websites on the same server, improving server efficiency and reducing costs.

RECOMMENDED READING: How can I fix Cloudron domain redirection issues?

For pros, you can create a new virtual host file and name it whatever you want as long as it is assigned a .conf file extension. Apache configuration files are appended with .conf extensions and it’s important to keep this in mind.

And for beginners, I would advise you to just go with the default configuration file. Inside the sites-available directory, you will find this file already created for you. In this example, our configuration file is named: 000-default.conf. In your case, it could be named something else and so, you don’t have to freak out. Just look for a file in the sites-available directory that has a .conf extension.

You can go to the sites-available directory via the following path on your terminal and create or use the default Apache configuration file;

cd /etc/apache2/sites-available

As we said, our default configuration file in this example is named:000-default.conf and so, we’re going to use nano editor to edit it by running the following command;

nano 000-default.conf 

One of the most important things we need to put in this file is to define the path to our website’s root directory. This enables the website to load directly when you either type the server IP address in the browser or the domain name without having to specify the directory.

So, for our case, we need to add the root directory, named WordPress containing our WordPress files as seen in the image below:

The file should be as follow with WordPress as the defined root directory of the website

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/wordpress

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf

RECOMMENDED READING: How to use Cloudflare on Namecheap Domain Pointed to Contabo

Save & activate the Apache Virtual Host file

Save the configuration file, 000-default.con and then activate the Apache virtual host and rewrite the module using the following commands. Please remember to replace 000-default.con with your own name of the configuration file.

a2ensite 000-default.conf
a2enmod rewrite

Restart Apache Service

We need to restart the Apache service again by running the following command:

systemctl restart apache2

Confirm if the Apache service is running by executing the following command:

systemctl status apache2

If Apache is running, you will be able to see something like this on your terminal:

● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2022-12-24 14:35:38 UTC; 2s ago
    Process: 53484 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
   Main PID: 53488 (apache2)
      Tasks: 6 (limit: 1030)
     Memory: 15.1M
        CPU: 37ms
     CGroup: /system.slice/apache2.service
             ├─53488 /usr/sbin/apache2 -k start
             ├─53489 /usr/sbin/apache2 -k start
             ├─53490 /usr/sbin/apache2 -k start
             ├─53491 /usr/sbin/apache2 -k start
             ├─53492 /usr/sbin/apache2 -k start
             └─53493 /usr/sbin/apache2 -k start

Dec 24 14:35:38 ubuntu2204 systemd[1]: apache2.service: Deactivated successfully.
Dec 24 14:35:38 ubuntu2204 systemd[1]: Stopped The Apache HTTP Server.
Dec 24 14:35:38 ubuntu2204 systemd[1]: Starting The Apache HTTP Server...

RECOMMENDED READING: How to Install WordPress on a VPS Server using Cloudron?

Initiate WordPress Installation

In this case, the process of installing WordPress is done through the browser. If you’ve been able to attach or bind a custom domain name to your server IP address, then you just have to type in that particular domain in the browser and the WordPress installation interface will appear. On the other hand, if you’ve not attached a domain name, then you can use your server’s IP address: http://your IP address/ in the browser to access the WordPress installation interface as in the image below;

You will need to select the appropriate language for you and then press continue. You will then land on another section where you will require to fill in a couple of details as seen below in the image:

The details you put are those of your WordPress Admin user, and you have to save them in a separate file for reference.

Once, you set up everything correctly, you will be able to log into WordPress without facing any problems.

RECOMMENDED READING: How are Protocols implemented in applications?

Install Let’s Encrypt SSL on WordPress

Install the SSL certificate on our WordPress website, we have to install the certbot client on the server.

Apache Certbot is a tool used to automate the process of obtaining and installing SSL/TLS certificates for Apache web servers. It is a free and open-source tool that simplifies the process of setting up HTTPS encryption for your website. Certbot is part of the Electronic Frontier Foundation’s (EFF) Let’s Encrypt project, which is a free, automated, and open certificate authority (CA) that provides HTTPS certificates to website owners.

RECOMMENDED READING: How to Point a Domain Name from Namecheap to Contabo VPS

Certbot works by communicating with the Let’s Encrypt CA to verify domain ownership and request a certificate. Once the certificate is issued, Certbot automatically configures your Apache server to use the new certificate and enable HTTPS encryption.

We can install certbot on the server by running the following command:

apt install python3-certbot-apache -y

Then, we need to run the following command to secure the website with Let’s Encrypt SSL. [ make sure to put your appropriate domain ]

certbot --apache -d

You will be asked to provide your email and accept the terms of service as shown below:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator standalone, Installer None
Enter email address (used for urgent renewal and security notices) (Enter 'c' to

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at You must
agree in order to register with the ACME server at
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Plugins selected: Authenticator apache, Installer apache
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for
Enabled Apache rewrite module
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/apache2/sites-available/wordpress-le-ssl.conf
Enabled Apache socache_shmcb module
Enabled Apache ssl module
Deploying Certificate to VirtualHost /etc/apache2/sites-available/wordpress-le-ssl.conf
Enabling available site: /etc/apache2/sites-available/wordpress-le-ssl.conf
Next, select whether or not to redirect HTTP traffic to HTTPS as shown below:

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

Once you’ve filled in the appropriate information, you will hit ENTER to generate and install the Let’s Encrypt SSL for your website. During the process, you will see something like this below;

Enabled Apache rewrite module
Redirecting vhost in /etc/apache2/sites-enabled/wordpress.conf to ssl vhost in /etc/apache2/sites-available/wordpress-le-ssl.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled

You should test your configuration at:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

 - Congratulations! Your certificate and chain have been saved at:
   Your key file has been saved at:
   Your cert will expire on 2023-02-29. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:
   Donating to EFF:          

Hire us to handle what you want

Hire us through our Fiverr Profile and leave all the complicated & technical stuff to us. Here are some of the things we can do for you:

  • Website migration, troubleshooting, and maintenance.
  • Server & application deployment, scaling, troubleshooting, and maintenance
  • Deployment of Kubernetes, Docker, Cloudron, Ant Media, Apache, Nginx,  OpenVPN, cPanel, WHMCS, WordPress, and more
  • Everything you need on AWS, IBM Cloud, GCP, Azure, Oracle Cloud, Alibaba Cloud, Linode, Contabo, DigitalOcean, Ionos, Vultr, GoDaddy, HostGator, Namecheap, DreamHost, and more.

We will design, configure, deploy, or troubleshoot anything you want. Starting from $10, we will get your job done in the shortest time possible. Your payment is safe with Fiverr as we will only be paid once your project is completed.