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 Joomla on Ubuntu 18.04 with Apache: LAMP Stack Guide

Joomla is one of the most popular open-source content management systems in the world. It is…

2 hours ago

Install Curl on Ubuntu 18.04: Setup and Common Usage Examples

You follow a tutorial, run a command, and get: curl: command not found. It simply means…

2 hours ago

Install Postman on Ubuntu 18.04: Snap Setup and First API Request

Postman is a complete API development environment used by developers at every stage of building APIs…

2 hours ago

Install VLC Media Player on Ubuntu 18.04: Snap Setup Guide

VLC is one of the most popular open-source multimedia players in the world, developed by the…

2 hours ago

Install Opera Web Browser on Ubuntu 18.04: Complete Setup Guide

Opera is one of the most popular cross-platform web browsers in the world, available on Windows,…

1 day ago

Install Gogs on Ubuntu 18.04: Self-Hosted Git Server Setup Guide

Gogs is a free, self-hosted Git service written in Go. It gives you a private GitHub-like…

1 day ago