This article by itsmeit will guide you through a simple and easy five-step process for installing WordPress with Nginx on Ubuntu 22.04 or Debian 11, Debian 10, and configuring it with Nginx, PHP, and MySQL.
How to install WordPress with Nginx on Ubuntu 22.04 or Debian Linux
This guide applies to Linux-based operating systems such as Ubuntu or Debian. Additionally, if you are using Apache, we have also provided instructions on how to install WordPress with Apache in a separate article that you can find here.
Step 1. Install PHP and MySQL to install WordPress
Before install WordPress with Nginx on Debian or Ubuntu, 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 Nginx on Ubuntu 22.04, 20.04 or Debian
Nginx is typically pre-installed on Debian, but if it isn’t, you can install it by following the instructions below. First, check if Nginx has already been installed on your system.
nginx -V
If Nginx does not exist on your system, you can run the command below to install it.
sudo apt update sudo apt install nginx -y
After installing Nginx, the command below can be used to stop, start and enable Nginx to always start with the system.
sudo systemctl enable nginx sudo systemctl start nginx
Open your web browser and enter either “localhost” or “127.0.0.1” in the address bar. If the display appears as shown in the image below, it indicates that Nginx has been installed successfully. Now you can start install WordPress with Nginx on Ubuntu 22.04, 20.04, or Debian. Please continue following 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. We will download and install WordPress with Nginx 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, we used the terminal to navigate to the ‘/tmp’ directory, which is a temporary directory. Next, we 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 to install WordPress with Nginx on Ubuntu 22.04 and 20.04.
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 Nginx in the next steps. Finally, we have set permissions for 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. Nginx web server configuration file for WordPress
Having successfully installed and configured Nginx in accordance with the guidelines outlined in this article, proceed to create additional configurations within the “/etc/nginx/sites-available” directory.
sudo nano /etc/nginx/sites-available/dev. itsmeit.co.conf
Edit the domain name (server_name) and path to your source code (root), and fastcgi_pass. Press Ctrl + X
to select Y
to save the file. After saving the above config file, run the commands below to activate and restart NGINX.
sudo service nginx restart
Step 5. Config hosts domain localhost for WordPress
For localhost: Open the file /etc/hosts and add the ip config 127.0.0.1 dev. itsmeit.co www.dev. itsmeit.co at the end.
sudo nano /etc/hosts
127.0.0.1 dev. itsmeit.co www.dev. itsmeit.co
On VPS: the server you need to configure DNS according to the domain name provider
Step 6. Create database and User for Wordpress, grant permissions in MySQL
To establish a connection with the database and start setting up your WordPress 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, rather than the root user.
Login to MySQL:
sudo mysql (Or sudo mysql -u root -p)
CREATE DATABASE database_name; CREATE USER "username"@"localhost" IDENTIFIED BY "password"; GRANT ALL PRIVILEGES ON database_name.* TO username@localhost IDENTIFIED BY "password"; FLUSH PRIVILEGES; \q
Step 7. Install WordPress With Nginx on Ubuntu 22.04 Linux
Now, open a browser and type your domain name, you will get the result as shown below to enter information and create a website Wordpress.
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 install WordPress with Nginx 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 –
Hay quá, tạo được cả ssl trên localhost luôn ạ