Launch your website: A detailed guide to installing WordPress, configuring Apache, MySQL, and essential security.
Estimated Time: Approximately 60 - 90 minutes (excluding prior LAMP setup)
WordPress is the world's most popular Content Management System (CMS), powering over 40% of all websites on the internet. It's a free and open-source platform that allows you to create and manage dynamic websites, blogs, and even e-commerce stores with ease, without needing extensive coding knowledge.
At its core, WordPress is a PHP application that uses a MySQL database to store all its content (posts, pages, comments, user data, settings). It typically runs on a web server like Apache or Nginx, making a LAMP (Linux, Apache, MySQL, PHP) stack an ideal environment.
Why Choose WordPress?
60 - 90 minutes
(Assuming a LAMP stack is already configured. If not, add 45-60 minutes for LAMP setup.)
Intermediate
Assumes basic familiarity with Linux terminal commands, Apache, MySQL, and DNS.
sudo
privileges on your Ubuntu server.Ensure your server is up-to-date and all LAMP components are correctly installed and running.
1. Update system packages:
sudo apt update && sudo apt upgrade -y
2. Verify Apache, MySQL, PHP:
sudo systemctl status apache2
sudo systemctl status mysql
php -v
3. Install PHP modules for WordPress: WordPress requires a few additional PHP modules.
sudo apt install php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip -y
4. Restart Apache to load new PHP modules:
sudo systemctl restart apache2
WordPress needs a dedicated database and a user with specific privileges to interact with it. Using a dedicated user with limited permissions is a key security practice.
1. Log in to MySQL as root:
sudo mysql -u root -p
2. Execute the following SQL commands in the MySQL prompt (`mysql>`):
CREATE DATABASE your_wp_database CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'your_wp_user'@'localhost' IDENTIFIED BY 'your_wp_user_password';
GRANT ALL PRIVILEGES ON your_wp_database.* TO 'your_wp_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Now, we'll download the latest version of WordPress and place its files in a suitable location on your server.
1. Navigate to the `/tmp` directory (for temporary downloads):
cd /tmp
2. Download the latest WordPress archive:
wget -c http://wordpress.org/latest.tar.gz
3. Extract the WordPress archive:
tar -xzvf latest.tar.gz
We'll create a dedicated Apache Virtual Host for your WordPress site, ensuring it responds correctly to your domain name and uses the correct document root.
1. Create the WordPress document root directory:
sudo mkdir -p /var/www/yourdomain.com/public_html
2. Copy WordPress files to the document root:
sudo mv /tmp/wordpress/* /var/www/yourdomain.com/public_html/
3. Set correct ownership and permissions for WordPress files:
sudo chown -R www-data:www-data /var/www/yourdomain.com/public_html
sudo find /var/www/yourdomain.com/public_html -type d -exec chmod 755 {} \;
sudo find /var/www/yourdomain.com/public_html -type f -exec chmod 644 {} \;
4. Create Apache virtual host configuration file:
sudo nano /etc/apache2/sites-available/yourdomain.com.conf
Paste the following, replacing `yourdomain.com` and `www.yourdomain.com` with your actual domain:
<VirtualHost *:80>
ServerAdmin webmaster@yourdomain.com
ServerName yourdomain.com
ServerAlias www.yourdomain.com
DocumentRoot /var/www/yourdomain.com/public_html
ErrorLog ${APACHE_LOG_DIR}/yourdomain.com_error.log
CustomLog ${APACHE_LOG_DIR}/yourdomain.com_access.log combined
<Directory /var/www/yourdomain.com/public_html>
Options Indexes FollowSymLinks
AllowOverride All # Crucial for WordPress permalinks to work
Require all granted
</Directory>
</VirtualHost>
Save (`Ctrl+O`, `Enter`) and exit (`Ctrl+X`).
5. Enable Apache `mod_rewrite` module: WordPress uses this for pretty permalinks.
sudo a2enmod rewrite
6. Enable your new virtual host and disable the default one (if applicable):
sudo a2ensite yourdomain.com.conf
sudo a2dissite 000-default.conf
# Only if replacing the default site
7. Test Apache configuration for syntax errors and restart:
sudo apache2ctl configtest
sudo systemctl restart apache2
This file tells WordPress how to connect to your database and provides unique security keys.
1. Copy the sample configuration file:
sudo cp /var/www/yourdomain.com/public_html/wp-config-sample.php /var/www/yourdomain.com/public_html/wp-config.php
2. Open `wp-config.php` for editing:
sudo nano /var/www/yourdomain.com/public_html/wp-config.php
3. Edit Database Settings: Find the following lines and update them with the database credentials you created in Step 2:
# ...
define( 'DB_NAME', 'your_wp_database' );
define( 'DB_USER', 'your_wp_user' );
define( 'DB_PASSWORD', 'your_wp_user_password' );
# ...
4. Generate Unique Security Keys: This significantly increases the security of your WordPress installation.
Save (`Ctrl+O`, `Enter`) and exit `nano` (`Ctrl+X`).
Now that all server-side configurations are done, you can complete the WordPress installation through your web browser.
1. Open your web browser: Navigate to `http://yourdomain.com`.
2. Follow the WordPress installation wizard:
Securing your WordPress site with HTTPS is critical for security, SEO, and user trust. We'll use Certbot and free SSL certificates from Let's Encrypt.
1. Install Certbot (if not already):
sudo snap install core
sudo snap refresh core
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot
2. Obtain SSL Certificate and Configure Apache:
sudo certbot --apache
Once WordPress is running, implement these crucial steps for better security and performance.
To prevent visitors from browsing directories without an `index.html` file, you should disable directory listing.
1. Edit your Apache virtual host file:
sudo nano /etc/apache2/sites-available/yourdomain.com-le-ssl.conf
2. Locate the `Options` line within the `<Directory /var/www/yourdomain.com/public_html>` block and remove `Indexes`:
# Change from:
Options Indexes FollowSymLinks
# To:
Options FollowSymLinks
Save and exit, then restart Apache:
sudo systemctl restart apache2
For an extra layer of security, you can move your `wp-config.php` file one directory above the `DocumentRoot`.
1. Move `wp-config.php`:
sudo mv /var/www/yourdomain.com/public_html/wp-config.php /var/www/yourdomain.com/wp-config.php
2. Modify `public_html/index.php` to include it:
sudo nano /var/www/yourdomain.com/public_html/index.php
At the top of the file, *above* the `/** Loads the WordPress Environment and Template */` line, add:
<?php
require_once( dirname(__FILE__) . '/../wp-config.php' );
require_once( ABSPATH . 'wp-settings.php' );
?>
If you accidentally used 'admin' as your WordPress username, change it immediately from the WordPress admin dashboard (Users > All Users > Edit your user). This is a common target for brute-force attacks.
Consider installing a reputable WordPress security plugin like Wordfence, Sucuri, or iThemes Security. These can help with firewalls, malware scanning, login attempt limits, and more.
For larger WordPress sites or those with many plugins, you might need to increase PHP's memory limit.
1. Open PHP configuration:
sudo nano /etc/php/8.1/apache2/php.ini
2. Find `memory_limit` and change it (e.g., to 256M or 512M):
# Change from:
memory_limit = 128M
# To:
memory_limit = 256M
Save and exit, then restart Apache: `sudo systemctl restart apache2`
Caching is vital for WordPress performance. Install a caching plugin (e.g., WP Super Cache, LiteSpeed Cache, W3 Total Cache) and configure it. You might also consider server-side caching like Nginx FastCGI Cache or Redis/Memcached with object caching.
WordPress has its own cron system. To ensure it runs reliably, it's best to disable WP-Cron and set up a system cron job.
1. Disable WP-Cron in `wp-config.php`:
sudo nano /var/www/yourdomain.com/wp-config.php
Add the following line, preferably above the `/* That's all, stop editing! Happy blogging. */` line:
define('DISABLE_WP_CRON', true);
Save and exit.
2. Set up system cron job:
sudo crontab -e -u www-data
Add the following line to run WordPress cron every 5 minutes:
*/5 * * * * /usr/bin/php /var/www/yourdomain.com/public_html/wp-cron.php >/dev/null 2>&1
Save and exit. (For more details on cron jobs, see our Cron Jobs Automation Guide).
Confirm your WordPress installation is functional, secure, and ready for use:
Congratulations! You have successfully installed and configured WordPress on your Ubuntu server, complete with Apache virtual hosts, MySQL database, and essential security measures including HTTPS. Your website is now live and ready for content!
From here, your WordPress journey truly begins. Consider these next steps to build, optimize, and maintain your site:
Need Expert WordPress Development, Hosting, or Optimization? Contact Us!