WordPress is a popular and powerful content management system (CMS) that allows you to create and manage websites and blogs. WordPress is written in PHP and uses a MySQL or MariaDB database to store its data. In this article, we will show you how to install WordPress on Ubuntu 22.04 using Apache, PHP, and MySQL.
Prerequisites
Before you begin, you will need the following:
- A Ubuntu 22.04 server with a sudo user and a firewall configured.
- A domain name pointing to your server’s IP address. You can use Linode’s DNS Manager to set up your domain name.
- A LAMP stack installed on your server. You can follow this guide to install Apache, MySQL, and PHP on Ubuntu 22.04.
- A SSL certificate for your domain name. You can use Let’s Encrypt to obtain a free SSL certificate. You can follow this guide to enable HTTPS on Apache with Let’s Encrypt.
Step 1: Download WordPress
The first step is to download the latest version of WordPress from its official website. You can use the wget command to download the WordPress archive file to your server:
cd /tmp
wget https://wordpress.org/latest.tar.gz
Then, extract the WordPress files from the archive using the tar command:
tar xzf latest.tar.gz
This will create a directory called wordpress in the /tmp directory. You can rename the archive file with the current date for backup purposes:
mv latest.tar.gz wordpress-$(date +%Y-%m-%d).tar.gz
Step 2: Create a Database and User for WordPress
The next step is to create a database and a user for WordPress in MySQL. You can use the mysql command-line tool to access the MySQL server:
sudo mysql
Then, create a database for WordPress using the CREATE DATABASE statement. You can name the database anything you want, but we will use wordpress as an example:
CREATE DATABASE wordpress;
Next, create a user for WordPress using the CREATE USER statement. You can name the user anything you want, but we will use wordpressuser as an example. Replace password with a strong password of your choice:
CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'password';
Then, grant all privileges on the WordPress database to the WordPress user using the GRANT statement:
GRANT ALL ON wordpress.* TO 'wordpressuser'@'localhost';
Finally, flush the privileges to apply the changes and exit the MySQL shell:
FLUSH PRIVILEGES;
EXIT;
Step 3: Configure Apache for WordPress
The next step is to configure Apache to serve the WordPress files. You can use a virtual host file to define the settings for your domain name. You can create a new virtual host file in the /etc/apache2/sites-available directory with the following command:
sudo nano /etc/apache2/sites-available/wordpress.conf
Then, paste the following configuration into the file. Replace example.com with your own domain name:
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/html/wordpress
<Directory /var/www/html/wordpress>
Options FollowSymlinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =example.com [OR]
RewriteCond %{SERVER_NAME} =www.example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
This configuration tells Apache to serve the WordPress files from the /var/www/html/wordpress directory and redirect all HTTP requests to HTTPS using mod_rewrite.
Save and close the file when you are done.
Then, enable the new virtual host file and disable the default one with the following commands:
sudo a2ensite wordpress.conf
sudo a2dissite 000-default.conf
Finally, restart Apache for the changes to take effect:
sudo systemctl restart apache2
Step 4: Copy WordPress Files to Web Root
The next step is to copy the WordPress files from the /tmp directory to the web root directory (/var/www/html) using the rsync command:
sudo rsync -av /tmp/wordpress/ /var/www/html/wordpress/
This will preserve the ownership and permissions of the files.
Then, change the ownership of the WordPress files to www-data, which is the user that Apache runs as:
sudo chown -R www-data:www-data /var/www/html/wordpress/
Step 5: Complete WordPress Installation through Web Interface
The final step is to complete the WordPress installation through its web interface. Open your web browser and navigate to your domain name (e.g., https://tutosquad..com). You should see a language selection screen like this:
Select your preferred language and click Continue.
Then, you should see a screen that asks you for some basic information about your site, such as site title, username, password, and email address:
Fill in the required fields and click Install WordPress.
You should see a success message that confirms that WordPress has been installed:
Click Log In and enter your username and password to access your WordPress dashboard.
Congratulations! You have successfully installed WordPress on Ubuntu 22.04. You can now start creating and managing your website or blog with WordPress.
Leave a Reply