How to Install WordPress with MySQL, Apache2, and PHP 8.3 on Ubuntu:
How to Install WordPress with MySQL, Apache2, and PHP 8.3 on Ubuntu
WordPress is one of the most popular Content Management Systems (CMS) worldwide. In this guide, we will walk through a step-by-step process to install WordPress on an Ubuntu server, along with the Apache2 web server, MySQL as the database management system, and PHP 8.3 as the scripting language.
Prerequisites
Before we begin, ensure that you have:
- A running instance of Ubuntu (either on a physical server, virtual machine, or cloud instance).
- A user with sudo privileges.
- Basic knowledge of Linux command-line operations.
Let’s get started.
Step 1: Update Your Server
Before installing any packages, ensure that your server is up to date. Run the following commands:
sudo apt update
sudo apt upgrade
Step 2: Install Apache2
Apache2 is a powerful and widely used web server. To install Apache2, run:
sudo apt install apache2
Once installed, start the Apache service and ensure it is enabled to start at boot:
sudo systemctl start apache2
sudo systemctl enable apache2
You can check if Apache is running by typing:
sudo systemctl status apache2
Additionally, you can verify by opening your browser and navigating to your server’s IP address (http://your_server_ip). You should see the default Apache2 page.
Step 3: Install MySQL
Next, we will install MySQL to handle the database for WordPress. Run the following command:
sudo apt install mysql-server
Once the installation is complete, start the MySQL service and secure the installation:
sudo systemctl start mysql
sudo systemctl enable mysql
sudo mysql_secure_installation
During the secure installation process, you will be prompted to configure a root password and adjust some security settings. Follow the on-screen instructions to secure your MySQL server.
Create a Database for WordPress
Log in to the MySQL shell:
sudo mysql
Once inside, create a new database and user for WordPress. Replace wp_user, password, and wp_database with your own details.
CREATE DATABASE wp_database;
CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON wp_database.* TO 'wp_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Step 4: Install PHP 8.3
WordPress is written in PHP, so we need to install PHP along with some additional PHP modules required by WordPress. First, add the PPA for PHP 8.3:
sudo add-apt-repository ppa:ondrej/php
sudo apt update
Now install PHP 8.3 and required modules:
sudo apt install php8.3 libapache2-mod-php8.3 php8.3-mysql php8.3-xml php8.3-gd php8.3-curl php8.3-mbstring php8.3-zip php8.3-intl
You can verify the installation by checking the PHP version:
php -v
You should see something like:
PHP 8.3.x (cli) (built: ...)
Step 5: Configure Apache for PHP
By default, Apache2 will look for index.html files to serve as the homepage. We need to prioritize PHP files over HTML files. Open the Apache configuration file:
sudo nano /etc/apache2/mods-enabled/dir.conf
Move index.php to the first position like this:
<IfModule mod_dir.c>
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>
Save and exit the editor (CTRL+X, then Y, and ENTER).
Now, restart Apache to apply the changes:
sudo systemctl restart apache2
Step 6: Download and Configure WordPress
Let’s download the latest version of WordPress from its official site.
Navigate to the /var/www/html/ directory, where the web content is stored:
cd /var/www/html/
sudo rm index.html
Then download WordPress:
sudo wget https://wordpress.org/latest.tar.gz
sudo tar -xvzf latest.tar.gz
sudo mv wordpress/* .
sudo rm -rf wordpress latest.tar.gz
Set the appropriate permissions so Apache can access and manage WordPress files:
sudo chown -R www-data:www-data /var/www/html/
sudo chmod -R 755 /var/www/html/
Step 7: Configure WordPress Database Settings
WordPress needs to know how to connect to your MySQL database. To configure this, create a copy of the sample configuration file:
sudo cp wp-config-sample.php wp-config.php
Now open the configuration file for editing:
sudo nano wp-config.php
Locate the following lines and modify them to match your MySQL settings:
define( 'DB_NAME', 'wp_database' );
define( 'DB_USER', 'wp_user' );
define( 'DB_PASSWORD', 'password' );
define( 'DB_HOST', 'localhost' );
Save and exit the editor.
Step 8: Complete the Installation via Web Browser
Now, open your web browser and navigate to your server’s domain or IP address (e.g., http://your_server_ip). You will be greeted with the WordPress setup screen.
- Select your language.
- Fill out the form with your site title, admin username, password, and email address.
- Click Install WordPress to complete the setup.
Once the setup is complete, you can log in to the WordPress admin dashboard at http://your_server_ip/wp-admin.
Step 9: Enable Apache2 Rewrite Module
To improve the permalinks structure in WordPress, enable the Apache2 rewrite module:
sudo a2enmod rewrite
sudo systemctl restart apache2
Finally, make sure the AllowOverride directive is enabled for the /var/www/html/ directory by editing the Apache configuration file:
sudo nano /etc/apache2/apache2.conf
Look for this block:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
Change AllowOverride None to AllowOverride All, save the file, and restart Apache:
sudo systemctl restart apache2
Conclusion
You have successfully installed WordPress on your Ubuntu server with Apache2, MySQL, and PHP 8.3. Now you can start building your website and customizing it as per your needs!

Leave a comment