Tutorials

Install WordPress on Ubuntu 18.04 with Apache: LAMP Stack Guide

WordPress is the most popular open-source content management system in the world, powering over a quarter of all websites. It is built on PHP and MySQL and comes with a plugin and theme ecosystem that can handle anything from a personal blog to a full e-commerce store.

This guide walks you through installing WordPress on Ubuntu 18.04 with Apache as the web server. You will end up with a working WordPress site running behind HTTPS using a Let’s Encrypt SSL certificate.

Prerequisites:

  • A domain name pointing to your server’s public IP
  • Apache installed and running
  • A Let’s Encrypt SSL certificate installed for your domain

Run a quick package update before starting:

bashsudo apt update && sudo apt upgrade

Install WordPress on Ubuntu: Set Up the MySQL Database

WordPress needs a MySQL or MariaDB database to store posts, pages, users, plugins, and theme settings. If MySQL or MariaDB is not already installed on your server, set that up before continuing.

Log into the MySQL shell:

bashsudo mysql

Create a dedicated WordPress database with the correct character set:

sqlCREATE DATABASE wordpress CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

Create a MySQL user and grant it full access to the database. Replace the placeholder with a strong password:

sqlGRANT ALL ON wordpress.* TO 'wordpressuser'@'localhost' IDENTIFIED BY 'change-with-strong-password';

Exit the MySQL shell:

sqlEXIT

Install PHP and Download WordPress Files

PHP 7.2 is the default PHP version on Ubuntu 18.04 and is fully supported by WordPress. Install it along with all required extensions:

bashsudo apt install php7.2 php7.2-cli php7.2-mysql php7.2-json php7.2-opcache php7.2-mbstring php7.2-xml php7.2-gd php7.2-curl

Restart Apache to load the new PHP extensions:

bashsudo systemctl restart apache2

Create the document root directory for your domain:

bashsudo mkdir -p /var/www/example.com

Download the latest WordPress archive to the /tmp directory and extract it:

bashcd /tmp && wget https://wordpress.org/latest.tar.gztar xf latest.tar.gzsudo mv /tmp/wordpress/* /var/www/example.com/

Set the correct ownership so Apache can read and write to the WordPress files:

bashsudo chown -R www-data: /var/www/example.com

Configure Apache and Run the Web Installer

Create an Apache virtual host file for your domain:

bashsudo nano /etc/apache2/sites-available/example.com.conf

Paste the following configuration, replacing example.com with your domain and updating the SSL certificate paths:

apache<VirtualHost *:80>  ServerName example.com  Redirect permanent / https://example.com/</VirtualHost><VirtualHost *:443>  ServerName example.com  DocumentRoot /var/www/example.com  SSLEngine On  SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem  SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem  <Directory /var/www/example.com>    AllowOverride All    Require all granted  </Directory></VirtualHost>

The AllowOverride All directive lets WordPress manage URL rewrites through its .htaccess file, which is required for pretty permalinks.

Enable the site and restart Apache:

bashsudo a2ensite example.comsudo systemctl restart apache2

Open your domain in a browser. The WordPress setup wizard walks you through:

  1. Language selection
  2. Database connection – enter the database name (wordpress), username (wordpressuser), password, host (localhost), and table prefix
  3. Site details – enter your site name, choose an admin username (do not use admin for security), and set a strong password
  4. Admin email – enter your email address and choose whether to allow search engine indexing

Click Install WordPress. Once complete, you are redirected to the WordPress dashboard where you can install themes, add plugins, and create your first pages.

WordPress is now installed on your Ubuntu 18.04 server. Check out the First Steps With WordPress guide to get started customizing your site. Leave a comment below if you run into any issues during setup.

Cyber Defence

Recent Posts

Install Asterisk on Ubuntu 18.04: Source Build and Secure Config

Asterisk is the most widely deployed open-source PBX (Private Branch Exchange) platform in the world. It…

23 hours ago

Install Ghost on Ubuntu 18.04: Node.js, MySQL, and Nginx SSL

Ghost is an open-source publishing platform built on Node.js. It is designed for bloggers, journalists, and…

23 hours ago

Install Mattermost on Ubuntu 18.04: Nginx SSL Reverse Proxy Setup

Mattermost is an open-source, self-hosted team messaging platform and a direct alternative to Slack. It is…

23 hours ago

Install Ruby on Ubuntu 18.04: apt, Rbenv, and RVM Methods

Ruby is a dynamic, open-source programming language known for its clean, readable syntax. It powers the…

23 hours ago

Install PyCharm on Ubuntu 18.04: Community Edition via Snap

PyCharm is a full-featured Python IDE developed by JetBrains. It includes built-in debugging, embedded Git control,…

23 hours ago

Install PHP on Ubuntu 26.04: Apache, Nginx, and Multiple Versions

PHP 8.5 is included in Ubuntu 26.04's default repositories and is the recommended version for…

3 days ago