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.
- Reference: Setting Up a LAMP Stack on Ubuntu
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.
- Log into MySQL:
sudo mysql - Create the database:
CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci; - Create a dedicated user:
- Replace
your_strong_passwordwith a secure password.CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'your_strong_password';
- Replace
- Grant the user permissions:
GRANT ALL ON wordpress.* TO 'wp_user'@'localhost'; - 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.
- Navigate to a temporary folder and download WordPress:
cd /tmp curl -O https://wordpress.org/latest.tar.gz - Extract the archive:
tar xzvf latest.tar.gz - 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/
- This command moves the WordPress core files into the directory that Apache serves to the public.
- 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 {} \;
- This is a critical security step. It allows Apache to manage the WordPress files.
4. The Famous 5-Minute Install
With the backend configured, you can now complete the installation through the web interface.
- Navigate to your site: Open your browser and go to
http://localhost. - Select your language and click Continue.
- 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
- Database Name:
- Click Submit. If the details are correct, you'll see a success screen. Click Run the installation.
- Fill out your site information: Provide a site title, create an admin username, and set a strong password for your WordPress dashboard.
- 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.
- Enable the module:
sudo a2enmod rewrite - Restart Apache:
sudo service apache2 restart
You can now go to Settings -> Permalinks in your WordPress dashboard and choose the "Post name" structure.