How to Install WordPress with Nginx on Ubuntu 22.0.4

Introduction



Prerequisites



Steps to Check and Set Up Prerequisites

1. Update Your System

sudo apt update && sudo apt upgrade -y
2. Create a Non-Root User
sudo adduser yourusername
sudo usermod -aG sudo yourusername
3. Set Up Your Domain Name



Step-by-Step Process to install WordPress, PhP, MySQL and Nginx

sudo apt update && sudo apt upgrade -y
Step 2: Install Nginx
sudo apt install nginx
Once the installation is complete, the Nginx service will start automatically. To know the status of the service, use the below command:
sudo systemctl status nginx

Configure UFW (Optional)

VPS firewall allows us to open ports 80 and 443 for HTTP and HTTPS respectively. You can enable the Nginx full profile which contains rules for both ports. This can be done using:

sudo ufw allow 'Nginx Full' 
sudo ufw enable

Install and Configure MySQL Database

sudo apt install -y mysql-server
systemctl status mysql

Creating the database and a database user

$ mysql -u root -p
mysql> create database wordpress_db;
mysql> CREATE USER 'wordpress_user'@'localhost' IDENTIFIED BY 'P@ssw0rd445';

Make sure that you replace the password with something a bit more secure! We then need to grant privileges to the user on the database:

mysql> GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wordpress_user'@'localhost';

mysql>FLUSH PRIVILEGES;

mysql>exit;



Step 4: Install PHP

sudo apt update && sudo apt install -y software-properties-common 

sudo apt install php-fpm php-mysql mysql-server nginx unzip 
root@vps2964888:~# php -v
PHP 8.3.6 (cli) (built: Dec  2 2024 12:36:18) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.6, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.6, Copyright (c), by Zend Technologies
  • MySQL for connecting to the MySQL database.
  • cURL for making remote requests.
  • Mbstring to handle multibyte strings.
  • ImageMagick to perform actions such as image resizing.
  • XML to provide XML support.
  • Zip to unzip plugins, themes, and WordPress update packages.
  • Finally, type following command in the terminal to check the status. PHP is active and running.
sudo systemctl status php8.3-fpm.service
sudo systemctl restart php8.3-fpm

Step 5: Configure Nginx for WordPress

cd /etc/nginx/sites-available/
sudo cp default.baksudo rm default 
sudo nano a2zeducate
server {
 listen 8080;
 server_name a2zeducate.com www.a2zeducate.com;
index index.php index.html index.htm;
 root /var/www/html/a2zeducate.com/;
 index index.php;

 location / {
 try_files $uri $uri/ /index.php?$args;
 }

 location ~ \.php$ {
 include snippets/fastcgi-php.conf;
 fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
# php7.4-fpm.pid  php7.4-fpm.sock  php-fpm.sock
 
}
 location ~ /\.ht {
 deny all;
 }

}
sudo ln -s /etc/nginx/sites-available/a2zeducate /etc/nginx/sites-enabled/

Restarting Nginx

We need to restart Nginx for the new configuration to take effect

sudo systemctl restart nginx.service

Removing the default index.html page

cd /var/www/html
sudo rm index.nginx-debian.html

Download and Install WordPress with Nginx

cd /var/www/html/ 
wget https://wordpress.org/latest.tar.gz
tar xf latest.tar.gz
sudo cp -a /var/www/html/wordpress/* /var/www/html/a2zeducate.com/
cd    /var/www/html/a2zeducate.com/
sudo cp wp-config-sample.php wp-config.php
sudo chown -R www-data:www-data /var/www/html/a2zeducate.com



6- Setting up WordPress Configuration file 

sudo nano /var/www/html/a2zeducate.com/wp-config.php
...

define('DB_NAME', 'wordpress');

/** MySQL database username */
define('DB_USER', 'wordpressuser');

/** MySQL database password */
define('DB_PASSWORD', 'password');

...

define('FS_METHOD', 'direct');

7- Completing the installation through web interface

In your web browser, navigate to your server’s domain name or public IP address:

http://server_domain_or_IP/wordpress
How to Install WordPress with Nginx on Ubuntu 22.0.4



How to Install WordPress with Nginx on Ubuntu 22.0.4
How to Install WordPress with Nginx on Ubuntu 22.0.4
apt-get install php8.3-imagick
apt-get install php8.3-dom
apt-get install php8.3-curl
apt-get install php8.3-mbstring
apt-get install php8.3-zip
apt-get install php8.3-gd
apt-get install php8.3-intl
wordpress installation - website health final
memory_limit = 512M
max_execution_time = 40000
max_input_time = 6000
upload_max_filesize = 40M 
post_max_size = 128M 



Read Also

Previous Post
Next Post