How to Install and Configure WordPress on Ubuntu 22.04

Written by

in

TL;DR: Install WordPress on Ubuntu 22.04 by first setting up the LAMP stack (Linux, Apache, MySQL, and PHP) to provide the necessary server environment. Next, download the WordPress files, configure the database credentials, and complete the web-based installation wizard to finalize your setup.

Prerequisites and Initial Setup

Before diving into the installation, ensure you have a non-root user with sudo privileges on your Ubuntu 22.04 server. This guide assumes you are starting from a clean slate. The first critical step is installing the Apache web server, which will serve your WordPress site to visitors. Open your terminal and run the command: sudo apt update && sudo apt install apache2 -y. Once installed, you must configure the firewall to allow web traffic. Execute sudo ufw allow 'Apache Full' to ensure ports 80 and 443 are open. Verify Apache is running by visiting your server’s IP address in a web browser; you should see the default Apache landing page.

Installing MySQL and PHP

WordPress requires a database to store content and settings. Install MySQL using sudo apt install mysql-server -y. After installation, run sudo mysql_secure_installation to secure your database by setting a root password and removing anonymous users. Next, install PHP and essential modules with sudo apt install php libapache2-mod-php php-mysql php-curl php-gd php-intl php-mbstring php-xmlrpc php-zip php-xml php-soap -y. This ensures WordPress has all the necessary extensions to function correctly. Restart Apache to apply changes using sudo systemctl restart apache2.

Creating the WordPress Database

Log into MySQL as root with sudo mysql. Create a new database named wordpress using CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;. Create a new user and grant permissions with: CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'strong_password'; GRANT ALL ON wordpress.* TO 'wpuser'@'localhost'; FLUSH PRIVILEGES; EXIT;. Replace ‘strong_password’ with a secure password of your choice.

Downloading and Configuring WordPress

Download the latest WordPress package using sudo apt install wordpress -y or download it directly from wordpress.org. For the most current version, it is often better to download the tarball. Move the files to the web root: sudo cp -r ~/wordpress/* /var/www/html/. Change the ownership to the Apache user: sudo chown -R www-data:www-data /var/www/html.

Copy the sample configuration file: sudo cp /var/www/html/wp-config-sample.php /var/www/html/wp-config.php. Edit this file to insert your database name, user, and password. Specifically, update the DB_NAME, DB_USER, and DB_PASSWORD constants. Also, add unique authentication keys found at the WordPress.org secret key service to enhance security.

Completing the Installation

Navigate to your server’s IP address in your browser. You will see the WordPress setup wizard. Enter your site title, admin username, password, and email address. Click “Install WordPress.” Once complete, log in to the dashboard at /wp-admin.

FAQ

Q: How do I update WordPress core files?<

Related Articles

Comments

Leave a Reply

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