thelinuxvault blog

Install WordPress on Ubuntu 18.04 Bionic Beaver Linux

WordPress is the world’s most popular content management system (CMS), powering over 40% of websites globally. It’s flexible, user-friendly, and ideal for building blogs, business sites, e-commerce stores, and more. Ubuntu 18.04 LTS (Bionic Beaver) is a stable, secure, and widely used Linux distribution, making it an excellent choice for hosting WordPress.

In this guide, we’ll walk through the step-by-step process of installing WordPress on Ubuntu 18.04 using the LAMP stack (Linux, Apache, MySQL, PHP)—the foundation required to run WordPress. By the end, you’ll have a fully functional WordPress site ready for customization.

2026-02

Table of Contents#

  1. Prerequisites
  2. Step 1: Update System Packages
  3. Step 2: Install the LAMP Stack
  4. Step 3: Create a MySQL Database and User for WordPress
  5. Step 4: Download and Configure WordPress
  6. Step 5: Configure Apache for WordPress
  7. Step 6: Complete WordPress Installation via Web Interface
  8. Troubleshooting Common Issues
  9. Conclusion
  10. References

Prerequisites#

Before starting, ensure you have:

  • An Ubuntu 18.04 LTS server (physical, virtual, or cloud-based, e.g., AWS EC2, DigitalOcean Droplet).
  • A non-root user with sudo privileges (see Ubuntu’s guide to creating a sudo user).
  • A stable internet connection.
  • (Optional) A registered domain name pointing to your server’s IP address (for production use).

Step 1: Update System Packages#

First, update your system’s package index and upgrade existing packages to their latest versions. This ensures compatibility and security:

sudo apt update && sudo apt upgrade -y

If prompted, confirm package upgrades by pressing Y.

Step 2: Install the LAMP Stack#

WordPress requires a web server (Apache), database (MySQL), and PHP to run. We’ll install these components (the LAMP stack) first.

2.1 Install Apache Web Server#

Apache is the most popular web server. Install it with:

sudo apt install apache2 -y

Verify Apache is running:

sudo systemctl status apache2

You should see active (running) in the output.

Next, configure the firewall (ufw) to allow HTTP (port 80) and HTTPS (port 443) traffic. Ubuntu 18.04 uses ufw by default.

Check firewall status:

sudo ufw status

If inactive, enable it:

sudo ufw enable

Allow Apache traffic:

sudo ufw allow 'Apache Full'  # Allows both HTTP (80) and HTTPS (443)

Verify the rule:

sudo ufw status

You should see Apache Full listed under allowed services.

2.2 Install MySQL Database Server#

MySQL stores WordPress data (posts, users, settings). Install MySQL Server:

sudo apt install mysql-server -y

After installation, secure MySQL with the mysql_secure_installation script. This removes default vulnerabilities:

sudo mysql_secure_installation

Follow the prompts:

  • Set a root password: Choose a strong password and confirm it.
  • Remove anonymous users: Press Y.
  • Disallow root login remotely: Press Y.
  • Remove test database: Press Y.
  • Reload privilege tables: Press Y.

2.3 Install PHP and Extensions#

WordPress is built on PHP. Install PHP and required extensions (e.g., php-mysql for MySQL integration):

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

Verify PHP installation by creating a test file in Apache’s web root (/var/www/html):

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

Add this PHP code:

<?php phpinfo(); ?>

Save (Ctrl+O, Enter) and exit (Ctrl+X).

Test PHP by visiting http://your_server_ip/info.php in a browser. You’ll see a PHP info page with details about your installation.

Important: Delete the test file after verification (it exposes server details):

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

Step 3: Create a MySQL Database and User for WordPress#

WordPress needs a dedicated MySQL database and user. Follow these steps:

  1. Log into MySQL as the root user:

    sudo mysql -u root -p

    Enter the root password you set earlier.

  2. Create a database for WordPress (name it wordpress or your preferred name):

    CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
  3. Create a MySQL user (e.g., wpuser) and grant it full access to the database. Replace your_strong_password with a secure password:

    CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'your_strong_password';
    GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
  4. Flush privileges to apply changes:

    FLUSH PRIVILEGES;
  5. Exit MySQL:

    EXIT;

Step 4: Download and Configure WordPress#

4.1 Download WordPress#

WordPress is updated frequently, so we’ll download the latest version using wget.

First, navigate to Apache’s web root:

cd /var/www/html

Download the latest WordPress tarball:

sudo wget https://wordpress.org/latest.tar.gz

Extract the tarball:

sudo tar -xvzf latest.tar.gz

This creates a wordpress directory in /var/www/html.

4.2 Set File Permissions#

Apache (run by the www-data user) needs read/write access to the WordPress directory. Set ownership:

sudo chown -R www-data:www-data /var/www/html/wordpress/

Set directory permissions (restrictive but functional):

sudo chmod -R 755 /var/www/html/wordpress/

Create an uploads directory for media files (WordPress may auto-create this, but it’s safer to set permissions explicitly):

sudo mkdir /var/www/html/wordpress/wp-content/uploads
sudo chown -R www-data:www-data /var/www/html/wordpress/wp-content/uploads/

4.3 Configure WordPress Settings#

WordPress uses wp-config.php to connect to the database. Copy the sample config file:

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

Edit wp-config.php with your MySQL database details:

sudo nano wp-config.php

Find these lines and replace them with your database credentials (from Step 3):

define( 'DB_NAME', 'wordpress' );         // Your database name
define( 'DB_USER', 'wpuser' );            // Your MySQL user
define( 'DB_PASSWORD', 'your_strong_password' );  // Your MySQL password
define( 'DB_HOST', 'localhost' );         // Leave as localhost

Next, add security keys to protect your site. WordPress provides a tool to generate these. Visit https://api.wordpress.org/secret-key/1.1/salt/ in your browser, copy the generated keys, and replace the AUTH_KEY, SECURE_AUTH_KEY, etc., lines in wp-config.php.

Example keys (do not use these—generate your own):

define( 'AUTH_KEY',         'put your unique phrase here' );
define( 'SECURE_AUTH_KEY',  'put your unique phrase here' );
define( 'LOGGED_IN_KEY',    'put your unique phrase here' );
define( 'NONCE_KEY',        'put your unique phrase here' );
define( 'AUTH_SALT',        'put your unique phrase here' );
define( 'SECURE_AUTH_SALT', 'put your unique phrase here' );
define( 'LOGGED_IN_SALT',   'put your unique phrase here' );
define( 'NONCE_SALT',       'put your unique phrase here' );

Save (Ctrl+O) and exit (Ctrl+X).

Step 5: Configure Apache for WordPress#

5.1 Create an Apache Virtual Host#

A virtual host lets you host multiple sites on one server. If using a domain (e.g., yourdomain.com), create a virtual host file. If not, skip to Step 5.2 (WordPress will be accessible at http://your_server_ip/wordpress).

Create a virtual host file (replace yourdomain.com with your domain):

sudo nano /etc/apache2/sites-available/yourdomain.com.conf

Paste this configuration (update ServerName, ServerAlias, and DocumentRoot):

<VirtualHost *:80>
    ServerName yourdomain.com          # Your domain
    ServerAlias www.yourdomain.com     # Optional: www subdomain
    DocumentRoot /var/www/html/wordpress  # Path to WordPress directory
 
    <Directory /var/www/html/wordpress/>
        Options FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
 
    ErrorLog ${APACHE_LOG_DIR}/yourdomain.com_error.log
    CustomLog ${APACHE_LOG_DIR}/yourdomain.com_access.log combined
</VirtualHost>

AllowOverride All enables WordPress permalinks (pretty URLs).

Save and exit.

5.2 Enable the Virtual Host and Rewrite Module#

Enable the new virtual host:

sudo a2ensite yourdomain.com.conf

Disable the default Apache site (optional but recommended for production):

sudo a2dissite 000-default.conf

Enable the rewrite module (required for permalinks):

sudo a2enmod rewrite

Restart Apache to apply changes:

sudo systemctl restart apache2

Step 6: Complete WordPress Installation via Web Interface#

Now, finalize WordPress setup through your browser.

6.1 Access the Installation Page#

  • If using a domain: Visit http://yourdomain.com.
  • If not using a domain: Visit http://your_server_ip/wordpress.

6.2 Run the Installation Wizard#

  1. Select Language: Choose your preferred language and click Continue.
  2. Site Information:
    • Site Title: Enter your site name (e.g., “My Blog”).
    • Username: Create an admin username (avoid “admin” for security).
    • Password: Use a strong password (WordPress will suggest one).
    • Your Email: Enter a valid email for password resets.
    • Search Engine Visibility: Check “Discourage search engines from indexing this site” if building a test site.
  3. Click Install WordPress.

6.3 Log In#

After installation, click Log In and enter your admin credentials. You’ll be directed to the WordPress dashboard (wp-admin), where you can customize your site.

Troubleshooting Common Issues#

Issue 1: Permissions Errors#

If you see “Permission denied” errors, recheck file ownership:

sudo chown -R www-data:www-data /var/www/html/wordpress/

Issue 2: PHP Extensions Missing#

WordPress may warn about missing extensions (e.g., mbstring). Install them with:

sudo apt install php-mbstring php-xml php-zip -y
sudo systemctl restart apache2

Issue 3: MySQL Connection Error#

If WordPress can’t connect to the database, verify wp-config.php has the correct credentials (DB name, user, password).

If “404 Not Found” errors occur when using permalinks, ensure rewrite module is enabled and AllowOverride All is set in your Apache config (Step 5.1).

Conclusion#

You’ve successfully installed WordPress on Ubuntu 18.04! You now have a functional CMS to build websites, blogs, or e-commerce stores.

Next Steps:

  • Install a theme (Appearance → Themes).
  • Add plugins (Plugins → Add New) for features like SEO (Yoast SEO), security (Wordfence), or e-commerce (WooCommerce).
  • Secure your site with HTTPS (use Let’s Encrypt for free SSL certificates).

References#