How to install WordPress on ubuntu 22.04 or 20.04 with apache2, config guide WordPress with apache2, Php, and Mysql. In this way, you can also install it on any Linux operating system like Debian or VPS server.
Install WordPress on Ubuntu 22.04 and 20.04 Linux using Apache2
This tutorial applies to Linux-based operating systems like Ubuntu or Debian. Additionally, if you are using Nginx, we have also provided a guide on how to install WordPress with Nginx in a separate article, which you can find here.
Step 1. Install PHP and MySQL to install WordPress
Before installing WordPress on Ubuntu with Apache, make sure your computer meets the following requirements:
- PHP: WordPress requires PHP to operate, so you need to install PHP.
- MySQL: You need to install the MySQL database to store WordPress data.
Step 2. Install Apache 2 on Ubuntu 22.04, 20.04 or Debian
On Ubuntu, there is usually Apache 2 available, but if you don’t have it, you can install Apache as instructed below. First, check if Apache 2 is installed on the system or not.
apache2 -version
Check apache 2 operational status.
sudo service apache2 status
If Apache 2 does not exist on your system, you can run the command below to install it.
sudo apt update sudo apt install apache2
After installing Apache, the command below can be used to stop, start and enable Apache to always start with the system.
sudo systemctl stop apache2.service sudo systemctl start apache2.service sudo systemctl enable apache2.service
Open your web browser and enter either ‘localhost’ or ‘127.0.0.1’ into the address bar. If the display appears as shown in the image below, it indicates that Apache has been successfully installed. Now you can start with installing WordPress on Ubuntu 22.04, 20.04, or Debian. Please continue to follow itsmeit for the next steps.
Step 3. Download the WordPress source code
At this step, you need to create a directory to store the source and download the WordPress zip file. ItsmeIT will do it as follows:
cd /tmp wget https://wordpress.org/latest.tar.gz tar -xvzf latest.tar.gz sudo mkdir -p /var/www/vhosts/dev. itsmeit.co/httpdocs cd wordpress && sudo mv * /var/www/vhosts/dev. itsmeit.co/httpdocs sudo chown -R $USER:www-data /var/www/vhosts/
Using the commands above, ItsmeIT utilized the terminal to navigate to the /tmp directory, which is a temporary directory. Next, ItsmeIT created a directory at the path “/var/www/vhosts/dev. itsmeit.co/httpdocs” and unzipped the file, before moving the source to the httpdocs folder.
Note:
The name of the directory can be set as desired (it is recommended to name it according to the project). The directory path will be configured in Apache in the next steps. Finally, ItsmeIT has granted permission to the directory at /vhosts.
To understand more about the permissions of directories and files in Linux when install WordPress on Ubuntu 22.04, 20.04 or Debian, you may refer to the article.
Step 4. Apache web server configuration file for WordPress
Create a new “dev. itsmeit.co.conf” configuration file in the /etc/apache2/sites-available/ directory for your site by running the command, should name the file the domain name and paste the content below.
sudo nano /etc/apache2/sites-available/dev. itsmeit.co.conf
Edit the domain name (ServerName, ServerAlias) and path to your source code (DocumentRoot), and press Ctrl + X
to select Y
to save the file. After saving the above config file, run the commands below to activate and restart apache2.
sudo a2ensite dev. itsmeit.co.conf sudo systemctl restart apache2.service
If there is any error message then run the below command to check and fix the config.
sudo apachectl configtest
Continue to run the command to set permission for the directory
sudo chown -R $USER:www-data /var/www/
Step 5. Config hosts domain localhost for WordPress
If you install WordPress on a localhost running Ubuntu, you’ll need to take an additional step to set up the IP address 127.0.0.1 for the domain. To do this, open the “hosts” file and add the following information.
sudo nano /etc/hosts
With the hosts
the configuration above, when you run the domain dev. itsmeit.co on your browser, it will point to the IP localhost 127.0.0.1 like a real domain without having to run localhost/project.
For the server or hosting, skip this step and have to transfer the domain pointing to the IP of the provider. Please contact the provider.
Now, open your web browser and enter the URL “dev. itsmeit.co.” If the result displayed is successful, proceed to the next step, which is installing and setting up the website.
Step 6. Create Users and database for Wordpress, grant permissions in MySQL
To establish a connection with the database and start configuring the website, it’s necessary to create a database. In this case, a database will be created and utilized with a MySQL user who has PRIVILEGES privileges, rather than the root user.
Login to MySQL
sudo mysql (or) sudo mysql -u root -p
The following commands will create a MySQL database and user that you can use to install WordPress with Apache2 on Ubuntu. Remember to change the “user” and “database” to your own information.
CREATE DATABASE dev_itsmeit; CREATE USER 'dev_itsmeit'@'localhost' IDENTIFIED BY 'Password123#'; GRANT ALL PRIVILEGES ON dev_itsmeit.* TO dev_itsmeit@localhost IDENTIFIED BY 'Password123#'; FLUSH PRIVILEGES;
Step 7. Install WordPress on Ubuntu 22.04, 20.04 or Debian
Open the browser running the domain that you configured in the steps above, click Let’s go!, and start setting up.
Enter the database, user, and password information that you created in step 5 and configure it as shown in the image above, then click the “submit” button.
Continue, press “Ctrl + A” in the frame as shown below, and copy the all content.
Next, run the command to create wp-config.php
the file and paste the copied content here. (The path to your wp-config.php file).
nano /var/www/vhosts/dev. itsmeit.co/httpdocs/wp-config.php
Press “Ctrl + X” and select “Y” to save the changes. Then return to your web browser and click on “Run the Installation” to continue the install WordPress on Ubuntu 22.04, 20.04.
Done! Now you can log in to the “wp-admin” using the account you created and start building your website. There are many themes and plugins available for WordPress, feel free to explore and download them to enhance your site.
Above are the steps for installing WordPress with Apache 2 on Ubuntu 22.04, 20.04, or Debian. You can also try creating an SSL to use “https” on your localhost for your website. Hopefully, it will help you!
– Advertising –