2 min read

Installing WordPress on a LAMP Stack

This guide walks you through installing WordPress, the world's most popular Content Management System (CMS), on top of the LAMP stack you previously configured.

1. Prerequisites

You must have a fully functional LAMP (Linux, Apache, MySQL, PHP) stack.

2. Create a Database for WordPress

WordPress uses a MySQL database to store all of your site's content. We need to create a dedicated database and a user for it.

  1. Log into MySQL:
    sudo mysql
  2. Create the database:
    CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
  3. Create a dedicated user:
    • Replace your_strong_password with a secure password.
      CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'your_strong_password';
  4. Grant the user permissions:
    GRANT ALL ON wordpress.* TO 'wp_user'@'localhost';
  5. Apply the changes and exit:
    FLUSH PRIVILEGES;
    EXIT;

3. Download and Deploy WordPress Files

Next, we'll download the latest version of WordPress and place it in Apache's web root directory.

  1. Navigate to a temporary folder and download WordPress:
    cd /tmp
    curl -O https://wordpress.org/latest.tar.gz
  2. Extract the archive:
    tar xzvf latest.tar.gz
  3. Copy the files to the web root:
    • This command moves the WordPress core files into the directory that Apache serves to the public.
      sudo cp -a /tmp/wordpress/. /var/www/html/
  4. Set correct ownership and permissions:
    • This is a critical security step. It allows Apache to manage the WordPress files.
      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 {} \;

4. The Famous 5-Minute Install

With the backend configured, you can now complete the installation through the web interface.

  1. Navigate to your site: Open your browser and go to http://localhost.
  2. Select your language and click Continue.
  3. On the database connection screen, enter the credentials you created in Step 2:
    • Database Name: wordpress
    • Username: wp_user
    • Password: your_strong_password
    • Database Host: localhost
  4. Click Submit. If the details are correct, you'll see a success screen. Click Run the installation.
  5. Fill out your site information: Provide a site title, create an admin username, and set a strong password for your WordPress dashboard.
  6. Log In: Once complete, you can log in to your new WordPress dashboard at http://localhost/wp-admin.

5. Post-Installation: Enable Pretty Permalinks

By default, WordPress URLs look like ?p=123. To enable user-friendly URLs (e.g., /hello-world/), you need to enable Apache's mod_rewrite.

  1. Enable the module:
    sudo a2enmod rewrite
  2. Restart Apache:
    sudo service apache2 restart

You can now go to Settings -> Permalinks in your WordPress dashboard and choose the "Post name" structure.