How to Install WordPress and Deploy Your Website on Ubuntu 22.04

Learn how to set up and deploy your own WordPress website on Ubuntu 22.04 using a simple step-by-step guide.

Ali Hamza

Ali Hamza

·

Follow

4 min read

·

Sep 28, 2024

110

3

Installing WordPress on Ubuntu 22.04

WordPress is one of the most popular content management systems (CMS), powering over 40% of all websites worldwide. It’s known for its flexibility, ease of use, and the extensive library of themes and plugins that make it possible to create everything from simple blogs to complex e-commerce sites. If you’re using Ubuntu 22.04 as your server operating system, you’re in good company — Ubuntu’s stability, security, and performance make it a preferred choice for hosting websites, especially when combined with the LAMP stack (Linux, Apache, MySQL, PHP).

In this guide, we’ll guide you through the process of installing WordPress on Ubuntu 22.04. We’ll cover everything from setting up your server environment to configuring WordPress and deploying your website live.

Understanding the Basics: Why WordPress on Ubuntu?

WordPress is favored by many due to its ease of use, scalability, and extensive customization options. Whether you’re building a blog or a corporate site, WordPress can handle it all.

Ubuntu 22.04 is an excellent choice for hosting WordPress because it is open-source, regularly updated, and highly secure. Additionally, it supports the LAMP stack, a commonly used platform that ensures reliable performance for web hosting.

Prerequisites

Before we begin, ensure you have the following:

  • A server running Ubuntu 22.04 with access to the terminal.
  • An SSH connection to your server (or direct terminal access).
  • Root or sudo privileges for installing and configuring software.
  • domain name (optional but recommended if you want your site to be public).
  • Basic knowledge of Linux terminal commands.

Step-by-Step Guide to Install WordPress on Ubuntu 22.04

Step 1: Update the Server and Install Apache

The first step in setting up your WordPress site is ensuring your server is up to date and installing Apache, the web server that will host your WordPress site.

  • Update the package index:
sudo apt update
  • Install Apache:
sudo apt install apache2
  • Start and enable Apache to run on startup:
sudo systemctl start apache2
sudo systemctl enable apache2

Once Apache is installed, you can verify it by visiting your server’s IP address in a web browser. If installed correctly, you should see the Apache default page.

Step 2: Install MySQL and Set Up a Database

WordPress uses MySQL to manage its database. You need to install MySQL and configure a database for WordPress.

  • Install MySQL:
sudo apt install mysql-server
  • Secure the MySQL installation:
sudo mysql_secure_installation

Follow the prompts to set a root password, remove anonymous users, and secure the MySQL server.

  • Log in to MySQL:
sudo mysql -u root -p
  • Create a new database and user for WordPress:
CREATE DATABASE wordpress;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Step 3: Install PHP and Required Extensions

WordPress is built using PHP, so we need to install PHP and the necessary extensions.

  • Install PHP and extensions:
sudo apt install php libapache2-mod-php php-mysql php-xml php-mbstring php-curl php-zip
  • Restart Apache to load PHP:
sudo systemctl restart apache2

Step 4: Download and Configure WordPress

Next, we will download WordPress, extract the files, and set the necessary permissions.

  • Download the latest version of WordPress:
wget https://wordpress.org/latest.tar.gz
  • Extract the downloaded file:
tar -xvf latest.tar.gz
  • Move the WordPress files to the web root:
sudo mv wordpress /var/www/html/wordpress
  • Set the correct permissions for the WordPress directory:
sudo chown -R www-data:www-data /var/www/html/wordpress
sudo chmod -R 755 /var/www/html/wordpress

Step 5: Configure Apache for WordPress

Now, we need to configure Apache to serve the WordPress site.

  • Create a new Apache configuration file for WordPress:
sudo nano /etc/apache2/sites-available/wordpress.conf
  • Add the following configuration:
<VirtualHost *:80>
ServerAdmin admin@yourdomain.com
DocumentRoot /var/www/html/wordpress
ServerName yourdomain.com
ServerAlias www.yourdomain.com

<Directory /var/www/html/wordpress/>
AllowOverride All
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
  • Enable the new site and the rewrite module:
sudo a2ensite wordpress.conf
sudo a2enmod rewrite
  • Restart Apache:
sudo systemctl restart apache2

Step 6: Complete the WordPress Installation

  • Open a web browser and visit your server’s IP address or domain name:
http://your-server-ip/wordpress
  • Follow the on-screen instructions to complete the WordPress setup, including configuring your site title, creating an admin user, and setting up your database connection using the credentials you created in Step 2.

Configuring Your WordPress Site

Once the installation is complete, you can log in to your WordPress admin panel at:

http://your-server-ip/wordpress/wp-admin

Here, you can begin customizing your site by selecting a theme, installing plugins, and configuring other settings. WordPress offers extensive features to help you tailor your site to your needs, whether you’re building a blog, business site, or online store.

Conclusion

Installing WordPress on Ubuntu 22.04 is a straightforward process that involves setting up the LAMP stack, configuring Apache, and installing WordPress. With this guide, you should now have a fully functional WordPress website deployed on a secure, stable platform.

Remember, the key to a successful WordPress site lies in regular updates and security maintenance. Now that your site is live, explore the wide variety of themes and plugins available to customize and enhance your website’s functionality.

Posted in Blog

Leave a Comment

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

*
*