WordPress GuideAdmin → Install WordPress on Ubuntu

How to install WordPress on Ubuntu (+ a LAMP stack)

Close-up of hands working with a calculator and notebook on a desk, analyzing documents.

Want total control over your WordPress site setup? Installing it manually on an Ubuntu server with a LAMP stack (Linux, Apache, MySQL, PHP) is the way to go. It’s not as quick as using a one-click installer—but you’ll understand exactly how everything works and gain full flexibility.

Let’s walk through each step to get WordPress running on Ubuntu 22.04 with a fresh LAMP stack.

Get fast, reliable hosting for WordPress

Power your site with the industry’s fastest, most optimized WordPress hosting

Prerequisites

Make sure you have the following before you begin:

Step 1: Update the server and install the LAMP stack

We’ll start by installing Apache (the web server), MySQL (the database), and PHP (the scripting language WordPress uses).

Update your package index

Open your terminal and run:

sudo apt update && sudo apt upgrade -y

This makes sure your system is running the latest software and security patches.

Install Apache

Install Apache with:

sudo apt install apache2 -y

Once installed, enable it to start on boot:

sudo systemctl enable apache2

sudo systemctl start apache2

To confirm Apache is running, visit your server’s IP address in a browser. You should see the default Apache welcome page.

Install MySQL and secure it

Install MySQL with:

sudo apt install mysql-server -y

Then run the built-in security script:

sudo mysql_secure_installation

Follow the prompts to:

Create a database and user for WordPress

Log into the MySQL shell:

sudo mysql

Run the following commands to create a new database and user:

CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

CREATE USER ‘wpuser’@’localhost’ IDENTIFIED BY ‘strong_password’;

GRANT ALL PRIVILEGES ON wordpress.* TO ‘wpuser’@’localhost’;

FLUSH PRIVILEGES;

EXIT;

Replace ‘strong_password’ with a secure password.

Install PHP and required extensions

Install PHP along with the necessary modules for WordPress:

sudo apt install php php-mysql php-xml php-gd php-curl php-mbstring php-zip libapache2-mod-php -y

Then enable Apache’s rewrite module:

sudo a2enmod rewrite

sudo systemctl restart apache2

Step 2: Download and configure WordPress

Now that your LAMP stack is ready, let’s install WordPress itself.

Download WordPress

Change to your temporary directory and download WordPress:

cd /tmp
curl -O https://wordpress.org/latest.tar.gz
tar -xvzf latest.tar.gz

Move WordPress files to the web root

Copy the extracted files to your Apache document root:

sudo cp -a /tmp/wordpress/. /var/www/html

(Optional: delete the default Apache index file to avoid conflicts)

sudo rm /var/www/html/index.html

Set correct file permissions

Run these commands to give Apache permission to read and write the files:

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

sudo find /var/www/html -type d -exec chmod 755 {} \;

sudo find /var/www/html -type f -exec chmod 644 {} \;

This ensures security while still allowing WordPress to run properly.

Step 3: Configure WordPress to connect to the database

WordPress needs to know your database details to work correctly.

Create the config file

Copy the sample configuration to a working config:

cd /var/www/html

cp wp-config-sample.php wp-config.php

Edit the config file

Open the file in a text editor:

sudo nano wp-config.php

Update the following lines with your database info:

define( ‘DB_NAME’, ‘wordpress’ );

define( ‘DB_USER’, ‘wpuser’ );

define( ‘DB_PASSWORD’, ‘strong_password’ );

Save and exit (Ctrl+O, then Enter, then Ctrl+X).

Add security keys

Visit https://api.wordpress.org/secret-key/1.1/salt/ to generate a unique set of secret keys. Copy and paste them into the appropriate section of wp-config.php, replacing the placeholder lines.

These keys improve your site’s security by encrypting information stored in cookies.

Step 4: Complete the installation in your browser

At this point, WordPress is installed on your server. Time to finish the setup in your browser.

Once it finishes, you’ll be able to log into your WordPress dashboard at http://your_domain_or_IP/wp-admin.

Optional: Secure your WordPress site with HTTPS

If you’re using a domain name, adding HTTPS is essential.

Install Certbot

Install Certbot and the Apache plugin:

sudo apt install certbot python3-certbot-apache -y

Get a free SSL certificate

Run the interactive Certbot script:

sudo certbot –apache

Follow the prompts to choose your domain and automatically redirect HTTP to HTTPS.

Auto-renew SSL certificates

Certbot sets up auto-renewal by default. You can verify it with:

sudo systemctl status certbot.timer

Optional: Set up a custom Apache virtual host

If you’re hosting multiple sites or want cleaner domain-based access, create a virtual host config file.

Example:

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

Add:

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/html
    <Directory /var/www/html>
        AllowOverride All
    </Directory>
</VirtualHost>

Then:

sudo a2ensite example.com.conf

sudo systemctl reload apache2

Make sure your domain’s DNS is pointed at your server IP.

Troubleshooting tips

Here are some common issues and fixes:

Additional resources

How to use your WordPress admin login page →

How to find, use, and troubleshoot your admin page

Is WordPress scalable? (And how to do it right) →

Learn how to create a scalable WordPress admin experience for growing websites and teams.










Easy WordPress website maintenance tips →

7 simple steps to keep on regular rotation