This WordPress installation guide helps you to install and configure the latest WordPress on an Ubuntu Linux box. It covers Apache, MariaDB, PHP, and Wordpress configurations.
Wordpress Installation On Ubuntu Server
This installation guide covers the following.
- Installation and configuration of Apache2
- Installation and configuration for MariaDB
- Installation and configuration of PHP and Apache modules.
- WordPress Apache configurations with a domain name.
- Accessing the WordPress dashboard.
How to install Wordpress on Ubuntu Server?
Follow the steps given below for the complete WordPress setup on Ubuntu 23.04
Install and Configure Apache 2
Step 1: Login to the server and update the package repos.
sudo apt-get update -yStep 2: Install Apache2,
sudo apt-get install apache2 -yStep 3: Execute the following command to disable anonymous directory listing.
sudo sed -i "s/Options Indexes FollowSymLinks/Options FollowSymLinks/" /etc/apache2/apache2.confStep 4: Start, enable, and check the status of Apache2
sudo systemctl stop apache2
sudo systemctl enable apache2
sudo systemctl start apache2Install and Configure MariaDB
Step 1: Install the Marais DB database server and client
sudo apt-get install mariadb-server mariadb-client -yStep 2: Use the following commands to start, stop, enable, and check the status of the MariaDB service.
sudo systemctl stop mysql
sudo systemctl start mysql
sudo systemctl enable mysql
sudo systemctl status mysqlStep 3: Setup the root admin password for the database using mysql_secure_installation command. It will prompt you to set up the new password.
sudo mysql_secure_installationUse the following options for the prompt.
Enter current password for root (enter for none): Just press the Enter
Set root password? [Y/n]: Y
New password: Enter password
Re-enter new password: Repeat password
Remove anonymous users? [Y/n]: Y
Disallow root login remotely? [Y/n]: Y
Remove test database and access to it? [Y/n]: Y
Reload privilege tables now? [Y/n]: YStep 4: Restart the database server for the changes to take effect.
sudo systemctl restart mysqlSetup and Configure PHP
Step 1: Install PHP 8 and its related modules.
sudo apt-get install php8.2 php8.2-mysql libapache2-mod-php8.2 php8.2-cli php8.2-cgi php8.2-gdStep 2: Open /etc/php/8.2/apache2/php.ini file
sudo vi /etc/php/8.2/apache2/php.iniAdd the following contents to the file.
file_uploads = On
allow_url_fopen = On
memory_limit = 256M
upload_max_filesize = 150M
max_execution_time = 350
date.timezone = America/ChicagoConfigure Database For Wordpress
Step 1: Login to the database using the password you set for root.
sudo mysql -u root -pStep 2: Create a database named "wordpress-db"
CREATE DATABASE wordpress_db;Step 3: Create a new database user named "wordpress-admin" and set a custom password. This user will be used in the WordPress configuration.
CREATE USER 'wordpress-admin'@'localhost' IDENTIFIED BY 'your_password_here';Step 4: Grant all privileged on wordpress-db for wordpress-admin user. Replace the password you set for wordpress-admin.
GRANT ALL ON wordpress_db.* TO 'wordpress-admin'@'localhost' IDENTIFIED BY 'your-password-here' WITH GRANT OPTION;Step 5: Flush all privileges and exit the db shell.
FLUSH PRIVILEGES; exitSetup and Configure Wordpress
Step 1: Download the latest WordPress
wget https://wordpress.org/latest.tar.gzStep 2: Untar the WordPress files
tar -xvf latest.tar.gzStep 3: Move the WordPress folder to /var/www/html folder.
sudo mv wordpress /var/www/html/wordpressStep 4: Change the ownership of the wordpress folder to www-data
sudo chown -R www-data:www-data /var/www/html/wordpress/Step 5: Change the folder and file permissions using the following command. Folders should have 755 permission, and files should have 644 permission.
find /var/www/html/ -type d -print0 | xargs -0 chmod 0755
find /var/www/html/ -type f -print0 | xargs -0 chmod 0644You can check if the permissions have been applied using the following command.
stat -c "%a %n" /var/www/html/wordpress/*Configure Apache For Wordpress
Step 1: Create a new Apache configuration named wp-site.conf for the WordPress site.
sudo vi /etc/apache2/sites-available/wp-site.confAdd the following configuration to the file and save it. Replace yourdomain with your custom domain name.
<VirtualHost *:80>
ServerAdmin admin@yourdomain.com
DocumentRoot /var/www/html/wordpress/
ServerName yourdomain.com
ServerAlias www.yourdomain.com
<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
</VirtualHost>Step 2: Enable wp-site.conf
sudo a2ensite wp-site.confStep 3: Enable the Apache rewrite module.
sudo a2enmod rewriteStep 4: Restart the Apache server.
sudo systemctl restart apache2Configure Wordpress Application
Step 1: Rename the default wp-config-sample.php to wp-config.php
sudo mv /var/www/html/wordpress/wp-config-sample.php /var/www/html/wordpress/wp-config.phpStep 2: Open the wp-config.php file
sudo vi /var/www/html/wordpress/wp-config.phpReplace the values highlighted in the image below with the database, user, and password generated in the previous steps.

Step 3: Now you have configured your site details on the wp-site.conf file, try to access WordPress by browsing the domain name you used on the wp-site.conf file.
Make sure your server is mapped to the domain name you configured in the wp-site.conf file.
http://your-domain-name.comIf you haven't configured a domain name, you can access the installed WordPress with
http://<your-server-ip>/wordpress Step 4: Select the preferred language and fill up the details in the configuration wizard.

Step 5: Once WordPress is installed, you can access the dashboard using the username and password.
