BLOG POSTS
Install WordPress on Ubuntu – Step-by-Step Guide

Install WordPress on Ubuntu – Step-by-Step Guide

Installing WordPress on Ubuntu is one of the most fundamental skills any developer or sysadmin needs to master when dealing with web hosting infrastructure. Whether you’re setting up a development environment, migrating from shared hosting, or deploying production sites on VPS or dedicated servers, understanding the complete LAMP stack installation process gives you full control over your WordPress deployment. This guide walks you through every step from a fresh Ubuntu installation to a fully functional WordPress site, including troubleshooting common issues that’ll save you hours of debugging.

Understanding the Technical Foundation

WordPress requires a classic LAMP stack (Linux, Apache, MySQL, PHP) to function properly. Ubuntu Server provides the Linux foundation, while we’ll install Apache as the web server, MySQL (or MariaDB) for database management, and PHP for server-side scripting. The beauty of this setup is complete control over configuration, performance tuning, and security hardening.

Unlike managed WordPress hosting or one-click installers, manual installation lets you optimize each component for your specific use case. You can choose PHP versions, configure Apache modules, tune MySQL parameters, and implement custom security measures that shared hosting environments simply don’t allow.

Prerequisites and System Requirements

Before diving into installation, ensure your Ubuntu system meets these requirements:

  • Ubuntu 20.04 LTS or 22.04 LTS (recommended for stability)
  • Minimum 1GB RAM (2GB+ recommended for production)
  • At least 10GB disk space
  • Root or sudo access
  • Active internet connection
Configuration Development Small Production High Traffic
RAM 1GB 2-4GB 8GB+
CPU Cores 1 2 4+
Storage 20GB 50GB SSD 100GB+ NVMe
Expected Traffic Local testing <10K visitors/month 100K+ visitors/month

Step-by-Step Installation Guide

Step 1: Update System Packages

Start with a clean system update to ensure all packages are current:

sudo apt update && sudo apt upgrade -y
sudo apt install curl wget unzip -y

Step 2: Install Apache Web Server

Apache remains the most popular web server for WordPress due to its stability and extensive module support:

sudo apt install apache2 -y
sudo systemctl start apache2
sudo systemctl enable apache2
sudo systemctl status apache2

Configure Apache for better WordPress performance:

sudo a2enmod rewrite
sudo a2enmod ssl
sudo a2enmod headers
sudo systemctl restart apache2

Test Apache installation by visiting your server’s IP address in a browser. You should see the default Apache welcome page.

Step 3: Install MySQL Database Server

MySQL stores all WordPress content, user data, and configuration. MariaDB is a drop-in replacement that often performs better:

sudo apt install mysql-server -y
sudo systemctl start mysql
sudo systemctl enable mysql
sudo mysql_secure_installation

During the secure installation, choose these settings:

  • Set root password: Yes (use a strong password)
  • Remove anonymous users: Yes
  • Disallow root login remotely: Yes
  • Remove test database: Yes
  • Reload privilege tables: Yes

Step 4: Install PHP and Required Extensions

WordPress requires PHP 7.4 or newer, but PHP 8.1+ is recommended for better performance:

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

Verify PHP installation:

php -v

Create a PHP info file to test Apache-PHP integration:

sudo nano /var/www/html/info.php

Add this content:

<?php
phpinfo();
?>

Visit http://your-server-ip/info.php to confirm PHP is working. Remove this file after testing for security.

Step 5: Create WordPress Database and User

WordPress needs a dedicated database and user for security isolation:

sudo mysql -u root -p

Execute these MySQL commands:

CREATE DATABASE wordpress_db;
CREATE USER 'wordpress_user'@'localhost' IDENTIFIED BY 'strong_password_here';
GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wordpress_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Step 6: Download and Configure WordPress

Download the latest WordPress release:

cd /tmp
wget https://wordpress.org/latest.tar.gz
tar xzf latest.tar.gz
sudo cp -R wordpress/* /var/www/html/
sudo chown -R www-data:www-data /var/www/html/
sudo chmod -R 755 /var/www/html/

Create WordPress configuration file:

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

Update these database settings in wp-config.php:

define('DB_NAME', 'wordpress_db');
define('DB_USER', 'wordpress_user');
define('DB_PASSWORD', 'strong_password_here');
define('DB_HOST', 'localhost');

Generate and add security keys from WordPress salt generator.

Step 7: Configure Apache Virtual Host

Create a proper virtual host configuration for better security and flexibility:

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

Add this configuration:

<VirtualHost *:80>
    ServerAdmin admin@yourdomain.com
    DocumentRoot /var/www/html
    ServerName yourdomain.com
    ServerAlias www.yourdomain.com

    <Directory /var/www/html>
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/wordpress_error.log
    CustomLog ${APACHE_LOG_DIR}/wordpress_access.log combined
</VirtualHost>

Enable the site and disable the default:

sudo a2ensite wordpress.conf
sudo a2dissite 000-default.conf
sudo systemctl restart apache2

WordPress Installation Completion

Navigate to your server’s IP address or domain name in a web browser. The WordPress installation wizard should appear. Follow these steps:

  • Select your language
  • Enter site title, admin username, and strong password
  • Provide admin email address
  • Choose whether search engines should index the site
  • Click “Install WordPress”

After successful installation, you can access the WordPress admin dashboard at http://yourdomain.com/wp-admin/

Security Hardening and Best Practices

A fresh WordPress installation requires additional security measures for production use:

File Permissions

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 {} \;
sudo chmod 600 /var/www/html/wp-config.php

Hide WordPress Version

Add this to your theme’s functions.php file:

function remove_wp_version() {
    return '';
}
add_filter('the_generator', 'remove_wp_version');

Disable File Editing

Add this line to wp-config.php:

define('DISALLOW_FILE_EDIT', true);

Install SSL Certificate

Use Let’s Encrypt for free SSL certificates:

sudo apt install certbot python3-certbot-apache -y
sudo certbot --apache -d yourdomain.com -d www.yourdomain.com

Performance Optimization

Optimize your WordPress installation for better performance:

PHP Configuration

Edit PHP configuration for better WordPress performance:

sudo nano /etc/php/8.1/apache2/php.ini

Update these values:

memory_limit = 256M
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 300
max_input_vars = 3000

Enable Apache Modules

sudo a2enmod deflate
sudo a2enmod expires
sudo a2enmod headers
sudo systemctl restart apache2

Common Issues and Troubleshooting

Database Connection Issues

If you see “Error establishing a database connection”:

  • Verify database credentials in wp-config.php
  • Check MySQL service status: sudo systemctl status mysql
  • Test database connection manually: mysql -u wordpress_user -p wordpress_db

Apache Permission Errors

403 Forbidden errors usually indicate permission issues:

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

PHP Not Executing

If PHP files download instead of executing:

sudo a2enmod php8.1
sudo systemctl restart apache2

WordPress White Screen of Death

Enable WordPress debugging by adding these lines to wp-config.php:

define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);

Check error logs:

sudo tail -f /var/log/apache2/wordpress_error.log
sudo tail -f /var/www/html/wp-content/debug.log

Alternative Installation Methods

While manual installation provides maximum control, consider these alternatives for different use cases:

Method Pros Cons Best For
Manual Installation Full control, customization, learning Time-consuming, requires expertise Production servers, custom setups
WP-CLI Command-line efficiency, scriptable Still requires LAMP setup Developers, bulk installations
Docker Consistent environments, easy scaling Container overhead, complexity Development, microservices
Snap Packages One-command installation Less flexibility, newer technology Quick testing, personal blogs

WP-CLI Installation Alternative

For developers who prefer command-line tools, WP-CLI offers powerful WordPress management:

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
wp --info

Download and configure WordPress using WP-CLI:

cd /var/www/html/
wp core download
wp core config --dbname=wordpress_db --dbuser=wordpress_user --dbpass=strong_password_here
wp core install --url=http://yourdomain.com --title="Your Site Title" --admin_user=admin --admin_password=secure_password --admin_email=admin@yourdomain.com

Real-World Use Cases and Examples

This installation method works perfectly for various scenarios:

  • Development Environment: Set up local WordPress development with custom PHP versions and debugging tools
  • Client Websites: Deploy production-ready WordPress sites with full server control and custom security measures
  • Multi-site Networks: Create WordPress multisite installations for managing multiple domains from single dashboard
  • E-commerce Sites: Install WooCommerce-ready WordPress with optimized database settings and SSL certificates
  • High-Traffic Blogs: Configure WordPress with caching, CDN integration, and database optimization for better performance

Integration with Modern DevOps

This manual installation approach integrates well with modern development workflows. You can automate the entire process using configuration management tools like Ansible, Puppet, or Chef. The installation also works seamlessly with CI/CD pipelines for automated WordPress deployments.

For more advanced setups, consider implementing this installation process with Infrastructure as Code tools like Terraform for cloud deployments on AWS, Google Cloud, or Azure platforms.

Monitoring and Maintenance

Set up basic monitoring to ensure your WordPress installation remains healthy:

# Monitor disk usage
df -h

# Check Apache status and performance
sudo systemctl status apache2
sudo apache2ctl status

# Monitor MySQL performance
sudo mysqladmin -u root -p status
sudo mysqladmin -u root -p processlist

# Check PHP error logs
sudo tail -f /var/log/apache2/error.log

Regular maintenance tasks include updating WordPress core, plugins, and themes, monitoring security logs, optimizing the database, and backing up both files and database regularly.

For comprehensive server management and monitoring, consider tools like Nagios, Zabbix, or cloud-based solutions like New Relic or DataDog, especially when running WordPress on production VPS or dedicated server environments.

This complete WordPress installation gives you the foundation for building robust, scalable WordPress sites with full control over every aspect of the server environment. The manual approach might take longer than one-click installers, but the knowledge gained and control achieved make it worthwhile for serious WordPress development and deployment.



This article incorporates information and material from various online sources. We acknowledge and appreciate the work of all original authors, publishers, and websites. While every effort has been made to appropriately credit the source material, any unintentional oversight or omission does not constitute a copyright infringement. All trademarks, logos, and images mentioned are the property of their respective owners. If you believe that any content used in this article infringes upon your copyright, please contact us immediately for review and prompt action.

This article is intended for informational and educational purposes only and does not infringe on the rights of the copyright owners. If any copyrighted material has been used without proper credit or in violation of copyright laws, it is unintentional and we will rectify it promptly upon notification. Please note that the republishing, redistribution, or reproduction of part or all of the contents in any form is prohibited without express written permission from the author and website owner. For permissions or further inquiries, please contact us.

Leave a reply

Your email address will not be published. Required fields are marked