, , , , ,

How to Install WordPress on Apache Using a LAMP Stack

How to Install WordPress on Apache Using a LAMP Stack

WordPress is a great way to build a website, but before you can start choosing themes and installing plugins, you need a server that can run it.

One popular way to do that is with a LAMP stack. It brings together Linux, Apache, MariaDB or MySQL, and PHP to create a complete environment for hosting WordPress.

The good news is that you don’t need a dedicated hosting company to get started. With a Linux server and a little help from AI, you can build your own WordPress installation and learn how the pieces fit together along the way.

In this guide, we’ll install WordPress on Ubuntu Server using Apache, configure a database, and get the website ready for its first login. These instructions also work on most Ubuntu-based distributions, including Linux Mint, with minor differences depending on the environment.

READ: Installing Apache On A Server

What Is a LAMP Stack?

LAMP stands for four components that work together to run a dynamic website.

  • Linux: The operating system that runs the server.
  • Apache: The web server that receives requests and delivers website content.
  • MariaDB or MySQL: The database that stores WordPress posts, pages, users, settings, and other information.
  • PHP: The programming language WordPress uses to generate dynamic pages.

When someone visits your website, Apache handles the incoming request, PHP runs the WordPress application, and the database supplies the information needed to build the page.

Once everything is configured, WordPress manages most of the day-to-day work through its dashboard.

Step 1: Prepare Your Linux Server

For this tutorial, we’ll use Ubuntu Server. You’ll need a server with administrator access and an internet connection.

Start by updating your package lists and installing available updates:

sudo apt update
sudo apt upgrade

Next, install Apache, MariaDB, PHP, and the PHP extensions WordPress commonly needs:

sudo apt install apache2 mariadb-server \
php libapache2-mod-php php-mysql \
php-curl php-gd php-mbstring php-xml \
php-zip php-intl php-bcmath php-imagick \
curl tar

If a package isn’t available in your distribution’s repositories, check the package name and available version before substituting another source.

Start Apache and MariaDB, and configure them to start automatically when the server boots:

sudo systemctl enable --now apache2
sudo systemctl enable --now mariadb

Check that Apache is running:

sudo systemctl status apache2

You can also open your server’s IP address in a browser. If Apache is accessible, you should see its default welcome page.

At this point, you have the foundation of your LAMP stack. Now it’s time to configure the database.

Step 2: Create a Database for WordPress

WordPress needs a database to store its content and settings. Rather than using a database administrator account for the website, create a separate database and user specifically for WordPress.

Open the MariaDB command line:

sudo mariadb

At the MariaDB prompt, run the following commands. Replace the example password with a strong, unique password of your own.

CREATE DATABASE wordpress
    CHARACTER SET utf8mb4
    COLLATE utf8mb4_unicode_ci;

CREATE USER 'wpuser'@'localhost'
    IDENTIFIED BY 'REPLACE_WITH_A_STRONG_PASSWORD';

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

EXIT;

You now have a database called wordpress and a database user called wpuser.

Keep the database name, username, and password available for the WordPress configuration. You’ll need them in a later step.

Don’t reuse this password for other accounts, and don’t publish it in a blog post, repository, or public configuration file.

Step 3: Download WordPress

Rather than relying on an operating system package that might lag behind the official release, we’ll download WordPress directly from WordPress.org.

Ubuntu’s default Apache document root is /var/www/html. For this tutorial, we’ll give WordPress its own directory instead, which makes it easier to configure a dedicated website.

Download and extract WordPress:

cd /tmp
curl -fLO https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz

Create the website directory and copy the WordPress files into it:

sudo mkdir -p /var/www/wordpress
sudo cp -a /tmp/wordpress/. /var/www/wordpress/

Set the initial ownership and permissions:

sudo chown -R www-data:www-data /var/www/wordpress
sudo find /var/www/wordpress -type d -exec chmod 755 {} \;
sudo find /var/www/wordpress -type f -exec chmod 644 {} \;

These commands give Apache access to the files and allow it to serve the website.

For a production server, consider a more restrictive ownership model so that the web server cannot modify every WordPress core file. WordPress updates and media uploads may require additional permission planning.

Step 4: Configure Apache for WordPress

Apache uses a feature called a virtual host to determine which website should respond to a request.

Create a new configuration file:

sudo nano /etc/apache2/sites-available/wordpress.conf

Add the following configuration:

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com

    DocumentRoot /var/www/wordpress

    <Directory /var/www/wordpress>
        Options -Indexes +FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/wordpress-error.log
    CustomLog ${APACHE_LOG_DIR}/wordpress-access.log combined
</VirtualHost>

Replace example.com and www.example.com with your actual domain names. If you’re testing locally, you can use a temporary hostname or configure your local hosts file.

Save the file and exit the editor.

Next, enable the website and Apache’s URL rewriting module:

sudo a2ensite wordpress.conf
sudo a2enmod rewrite

The rewrite module allows WordPress to use friendly URLs, such as /about-us/, instead of relying on query strings for every page.

If this server is dedicated to this WordPress site, you can disable Apache’s default website:

sudo a2dissite 000-default.conf

Before applying the changes, test the configuration:

sudo apache2ctl configtest

You should see:

Syntax OK

If the test passes, reload Apache:

sudo systemctl reload apache2

If your domain already points to this server and the network is configured correctly, Apache is now ready to serve your WordPress installation.

Step 5: Connect WordPress to MariaDB

WordPress needs to know how to connect to the database you created earlier.

Start by creating the configuration file from WordPress’s sample:

cd /var/www/wordpress
sudo cp wp-config-sample.php wp-config.php

Open it:

sudo nano wp-config.php

Find the database settings and update them to match your installation:

define( 'DB_NAME', 'wordpress' );
define( 'DB_USER', 'wpuser' );
define( 'DB_PASSWORD', 'REPLACE_WITH_A_STRONG_PASSWORD' );
define( 'DB_HOST', 'localhost' );

Replace the placeholder password with the same password you used when creating the MariaDB user.

Next, find the authentication key and salt section. WordPress uses these values to help protect login sessions. Generate fresh values using the official WordPress secret-key service and replace the sample entries.

Save the file when you’re done.

Because this file contains database credentials, don’t publish it or expose it through a public repository. For a production environment, you should also restrict access to configuration files and consider a more secure file-ownership arrangement.

Step 6: Finish the Installation in Your Browser

Now comes the easy part.

Open your website’s domain in a browser. If you’re testing on a local network, use the server’s IP address or the hostname you’ve configured.

You should see the WordPress installation screen.

Follow the prompts to choose your language, enter a website title, create an administrator account, and finish the setup.

Use a strong administrator password, and avoid using admin as your username.

Once the installation finishes, sign in at:

https://example.com/wp-admin

The HTTPS address assumes you’ve already configured a valid TLS certificate. If you haven’t configured HTTPS yet, use your working HTTP address for initial local testing and set up HTTPS before exposing the site publicly.

You now have a working WordPress installation running on Apache.

Step 7: Set Up HTTPS and Secure the Website

Before making the website publicly accessible, configure HTTPS so that connections between visitors and your server are encrypted.

A common option on Ubuntu is Certbot. The Apache plugin can help obtain and configure a certificate when your domain points to the server and the required network ports are reachable.

Follow the current instructions on the official Certbot website, selecting Apache and your operating system.

You should also:

  • Keep Ubuntu, Apache, PHP, MariaDB, WordPress, themes, and plugins updated.
  • Configure your firewall to allow only the services you need.
  • Back up your WordPress files and database regularly.
  • Use strong passwords and secure administrator accounts.
  • Install only plugins and themes from sources you trust.

A website that loads successfully isn’t automatically secure. Take time to verify your configuration before relying on it for a business or public website.

Troubleshooting Common Problems

If something doesn’t work, check the basics before changing several configuration files at once.

Apache won’t start

sudo apache2ctl configtest
sudo systemctl status apache2

WordPress reports a database connection error

Check that MariaDB is running and verify the database name, username, password, and host in wp-config.php.

sudo systemctl status mariadb

Your website displays a 403 Forbidden error

Check the Apache error log and verify the website directory permissions and virtual-host configuration.

sudo tail -n 50 /var/log/apache2/wordpress-error.log

WordPress pages return 404 errors

Confirm that the rewrite module is enabled and that AllowOverride All is set for the WordPress directory. Once the site loads, you can also visit Settings → Permalinks in WordPress and save your permalink settings.

If you’re using AI to troubleshoot, share the relevant error message and explain what you’ve already tried. Ask it to diagnose the problem before recommending changes, and remove any passwords or sensitive information from logs.

Final Thoughts

Installing WordPress on Apache is a good way to learn how the different pieces of a web server work together. Linux provides the operating environment, Apache serves the site, MariaDB stores its content, and PHP runs WordPress.

Once the installation is working, you can start customizing the website, adding themes and plugins, configuring backups, and improving performance.

The LAMP stack is a proven approach to WordPress hosting, and understanding how to build it yourself gives you more control over your website and its infrastructure.