Skip to main content

Installing WordPress on Ubuntu

Welcome to our journey of transforming a blank canvas of an Ubuntu server into a vibrant, dynamic WordPress website. WordPress is a powerful content management system (CMS) that powers a significant portion of the web, known for its flexibility and ease of use. In this guide, we'll walk through each step, from preparing your server to customizing your WordPress site. Whether you're a budding developer or a business owner looking to establish an online presence, this tutorial will provide you with the knowledge to succeed.

Prerequisites

Before we dive in, ensure you have the following:.

  • An Ubuntu server (18.04 or later is recommended).
  • A non-root user with sudo privileges.
  • A registered domain name pointed to your server's IP address.

Step 1: Updating Your Server

First things first, let's make sure your server is running the latest packages. This is akin to cleaning and organizing your workspace before starting a new project.

sudo apt update && sudo apt upgrade

You'll get a list of packages that will be updated along with a prompt asking for your confirmation to proceed.

Step 2: Installing LAMP Stack

LAMP stands for Linux, Apache, MySQL, and PHP. It's the foundation upon which your WordPress site will stand.

Install Apache

sudo apt install apache2

What to Watch Out For : Ensure that Apache is running by visiting your server's IP address in a web browser. You should see the default Apache2 Ubuntu page.

Install MySQL

sudo apt install mysql-server

You'll be prompted to set a root password for MySQL. Choose a strong one!

Install PHP and Extensions

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

What to Watch Out For : After installation, you may need to restart Apache to apply the PHP configuration.

sudo systemctl restart apache2

Step 3: Configuring MySQL

Secure your MySQL installation by running the mysql_secure_installation script.

sudo mysql_secure_installation

You'll be guided through several steps to remove anonymous users, disallow root login remotely, remove the test database, and reload privilege tables.

Step 4: Creating a Database for WordPress

Log in to the MySQL shell and create a database and user for WordPress.

sudo mysql -u root -p

Once inside the MySQL shell, execute the following commands:.

CREATE DATABASE wordpressdb;
CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'your_strong_password';
GRANT ALL ON wordpressdb.* TO 'wordpressuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

MySQL will confirm the creation of the database, user, and privileges.

Step 5: Installing WordPress

Download WordPress

Navigate to your web server's root directory and download the latest version of WordPress.

cd /var/www/html
sudo wget https://wordpress.org/latest.tar.gz

The latest WordPress tarball will be downloaded.

Extract WordPress Files

sudo tar -xzf latest.tar.gz

What to Watch Out For : This will create a wordpress directory. You'll need to move the contents of this directory to the root web directory.

sudo mv wordpress/* /var/www/html/
sudo chown -R www-data:www-data /var/www/html/
sudo find /var/www/html/ -type d -exec chmod 750 {} \;
sudo find /var/www/html/ -type f -exec chmod 640 {} \;

Configure WordPress

Create a wp-config.php file by copying the sample file provided by WordPress.

sudo cp /var/www/html/wp-config-sample.php /var/www/html/wp-config.php

Edit the wp-config.php file to enter your database details.

sudo nano /var/www/html/wp-config.php

Replace 'database_name_here', 'username_here', and 'password_here' with the database name, username, and password you created earlier.

With that you'll have a configured wp-config.php file ready for WordPress installation.

To ensure that permalinks work correctly, you'll need to update the Apache configuration.

sudo nano /etc/apache2/apache2.conf

Add the following block inside the <Directory /var/www/html> block:.

<Directory /var/www/html>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>

Enable the rewrite module and restart Apache.

sudo a2enmod rewrite
sudo systemctl restart apache2

Step 7: Completing the WordPress Installation

Open your web browser and navigate to your server's domain name or IP address. You should be greeted by the WordPress installation wizard.

  1. Choose your language and click 'Continue'.
  2. Fill in the site information and click 'Let's go!'.
  3. Enter the database details you configured in wp-config.php.
  4. Click 'Run the installation'.
  5. Fill in the site title, admin username, password, and email, then click 'Install WordPress'.

You'll get a success message indicating that WordPress is installed and that you can log in.

Step 8: Securing Your WordPress Site

Install an SSL Certificate

Use certbot to obtain a free SSL certificate from Let's Encrypt.

sudo apt install certbot python3-certbot-apache
sudo certbot --apache -d yourdomain.com -d www.yourdomain.com

The above commands will give you a series of prompts to configure HTTPS, followed by a success message.

Implement Security Best Practices

  • Regularly update WordPress, themes, and plugins.
  • Use strong passwords and limit login attempts.
  • Install security plugins like Wordfence or Sucuri.
  • Back up your site regularly.

Step 9: Customizing WordPress

Log in to your WordPress dashboard (https://yourdomain.com/wp-admin) to customize your site.

  • Install themes and plugins to extend functionality.
  • Create pages and posts to populate your site with content.
  • Customize your site's appearance through the theme customizer.

Summary

You've successfully installed WordPress on your Ubuntu server. From here, the possibilities are endless. Whether you're building a blog, an e-commerce site, or a portfolio, WordPress provides the tools you need to create a professional-looking website. Remember to keep your server and WordPress installation up to date, and always back up your data.