Are you looking for a detailed guide on how to install WordPress with Nginx on Ubuntu 22.04? This article will provide you with all the information you need to set up your own WordPress website quickly and easily.
Step-by-Step WordPress Installation with Nginx on Ubuntu 22.04
Step 1. Install PHP and MySQL
Before install WordPress with Nginx on Ubuntu 22.04, 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
You can install it by following the command 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 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.
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/arriveddev.com/httpdocs cd wordpress && sudo mv * /var/www/vhosts/arriveddev.com/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/arriveddev.com/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 using chmod to manage permissions for directories and files in Linux when installing WordPress, you can refer to the article.
Step 4. Nginx web server configuration file for WordPress
Continue running the command to create a domain configuration file and add its contents as shown below:
sudo nano /etc/nginx/sites-available/arriveddev.com.conf
Note:
- In the code snippet, the
fastcgi_pass
part is using the socket path for PHP-FPM version 8.1. If you are using a different PHP version, you need to adjust the socket path accordingly. - Note that you need to change
server_name
androot
in the configuration file according to your actual domain name and directory path.
After that, restart Nginx.
sudo service nginx restart
Step 5. Config hosts domain localhost for WordPress
This step is necessary if you’re installing WordPress on a VPS; you’ll need to configure DNS according to your domain provider. If you’re installing on an Ubuntu 22.04 computer (localhost), do the following:
Open the /etc/hosts file and add the IP config 127.0.0.1 arriveddev.com at the end.
sudo nano /etc/hosts
127.0.0.1 arriveddev.com www.arriveddev.com
Step 6. Create database and User
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
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, You can now log in to the admin account you created and start building your website. In case you encounter 404 errors with your URLs after installation, you can refer to the article [Fix 404 Errors] for guidance.
Hay quá, tạo được cả ssl trên localhost luôn ạ