How to Install WordPress on Ubuntu

How to Install WordPress on Ubuntu: A Comprehensive Guide

WordPress is one of the most popular content management systems (CMS) globally, known for its flexibility and ease of use. If you’re running a website on an Ubuntu server, installing WordPress can be a straightforward process. This guide will walk you through each step, from setting up your server to configuring WordPress.

Prerequisites

Before you start, ensure you have the following:

  1. Ubuntu Server: This guide assumes you’re using Ubuntu 20.04 LTS.
  2. Root or Sudo Privileges: You need to have root access or a user with sudo privileges.
  3. Domain Name: While optional, having a domain name can help in the setup process.
  4. Basic Knowledge of Linux Commands: Familiarity with command-line operations will be helpful.

Step 1: Update Your Server

First, it’s important to update your server’s package index to ensure you’re installing the latest versions of the software. Open your terminal and run:

sudo apt update
sudo apt upgrade -y

Step 2: Install Apache

Apache is a widely-used web server that will serve your WordPress site. Install Apache by running:

sudo apt install apache2 -y

To ensure Apache is running, use the following command:

sudo systemctl status apache2

You should see a status message indicating that Apache is active and running.

Step 3: Install MySQL

WordPress uses MySQL to manage and store your website’s data. Install MySQL by running:

sudo apt install mysql-server -y

Once the installation is complete, secure your MySQL installation:

sudo mysql_secure_installation

Follow the prompts to set a root password and secure your MySQL server.

Step 4: Install PHP

WordPress is written in PHP, so you’ll need to install PHP and its necessary modules:

sudo apt install php libapache2-mod-php php-mysql php-xml php-mbstring php-curl php-zip -y

To confirm PHP is installed correctly, you can create a phpinfo file:

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

Add the following line to the file:

<?php phpinfo(); ?>

Save and exit the file, then open your web browser and navigate to http://your_server_ip/info.php. You should see a page displaying PHP information.

Step 5: Create a MySQL Database and User

Next, you need to create a database and a user for WordPress. Log in to the MySQL shell:

sudo mysql -u root -p

Enter your root password and then run the following commands to create a database and user:

CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'yourpassword';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Replace 'yourpassword' with a strong password.

Step 6: Download WordPress

Now, download the latest version of WordPress:

cd /tmp
curl -O https://wordpress.org/latest.tar.gz
tar xzvf latest.tar.gz

Copy the extracted files to the Apache web root directory:

sudo cp -a /tmp/wordpress/. /var/www/html/

Step 7: Configure WordPress

WordPress comes with a sample configuration file. You need to rename this file and make some changes:

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

Edit the configuration file:

sudo nano wp-config.php

Find the following lines and replace the placeholders with your database information:

define( 'DB_NAME', 'wordpress' );
define( 'DB_USER', 'wordpressuser' );
define( 'DB_PASSWORD', 'yourpassword' );
define( 'DB_HOST', 'localhost' );

Step 8: Set Up Directory Permissions

Set the correct permissions on the WordPress directory:

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 {} \;

Step 9: Configure Apache

Create a new Apache configuration file for your WordPress site:

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

Add the following configuration:

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot /var/www/html
    ServerName yourdomain.com
    ServerAlias www.yourdomain.com

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

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Enable the WordPress site and the rewrite module:

sudo a2ensite wordpress.conf
sudo a2enmod rewrite
sudo systemctl restart apache2

Step 10: Complete the Installation Through the Web Interface

Open your web browser and navigate to your domain name or server IP address. You will be greeted by the WordPress installation wizard. Choose your language and click on “Continue.”

On the next page, fill in the site information:

  • Site Title
  • Username
  • Password
  • Your Email

Click on “Install WordPress.” Once the installation is complete, you will be prompted to log in to your new WordPress site.

Conclusion

Congratulations! You have successfully installed WordPress on your Ubuntu server. You can now start customizing your site, installing themes and plugins, and creating content.

Maintaining a WordPress site involves regular updates, backups, and security checks. Always ensure your server software, WordPress core, themes, and plugins are up to date to keep your site secure and running smoothly.

By following this guide, you’ve set a solid foundation for your WordPress website on Ubuntu, allowing you to leverage the full power and flexibility of this popular CMS.

Leave a Reply

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