Step 1: Install Required Packages Update the package list and install the necessary packages by running the following commands:
sudo apt update
sudo apt install nginx mysql-server php-fpm php-mysql php-curl php-gd php-mbstring php-xml php-xmlrpc
Step 2: Configure MySQL Secure your MySQL installation and create a new database and user for WordPress by running the following commands:
sudo mysql_secure_installation
sudo mysql -u root -p
mysql> CREATE DATABASE wordpress;
mysql> CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'password';
mysql> GRANT ALL ON wordpress.* TO 'wordpressuser'@'localhost';
mysql> FLUSH PRIVILEGES;
mysql> EXIT;
Step 3: Configure NGINX Create a new server block configuration for NGINX to serve WordPress by running the following command:
sudo nano /etc/nginx/sites-available/wordpress
Add the following configuration to the file, replacing example.com
with your own domain name or IP address:
server {
listen 80;
server_name example.com;
root /usr/share/nginx/html/wordpress;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
log_not_found off;
access_log off;
}
location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
expires max;
log_not_found off;
}
}
Save and close the file.
Step 4: Create WordPress Directory Create a new directory for the WordPress files by running the following command:
sudo mkdir -p /usr/share/nginx/html/wordpress
Step 5: Download WordPress Download the latest version of WordPress by running the following command:
cd /tmp
curl -LO https://wordpress.org/latest.tar.gz
Extract the downloaded file and move it to the document root:
tar xzvf latest.tar.gz
sudo cp -a /tmp/wordpress/. /usr/share/nginx/html/wordpress
Step 6: Set Permissions Set the correct permissions for the WordPress files:
sudo chown -R www-data: /usr/share/nginx/html/wordpress
sudo chmod -R 755 /usr/share/nginx/html/wordpress
Step 7: Configure PHP-FPM Edit the PHP-FPM configuration file to use the correct user and group and to listen on a Unix socket. Run the following command to open the file in the nano text editor:
sudo nano /etc/php/7.4/fpm/pool.d/www.conf
Change the following values in the file:
user = www-data
group = www-data
listen = /run/php/php7.4-fpm.sock
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
Save and close the file.
Step 8: Start and enable PHP-FPM service Start and enable the PHP-FPM service by running the following commands:
sudo systemctl start php7.4-fpm
sudo systemctl enable php7.4-fpm
Step 9: Test the configuration Test the configuration by restarting NGINX and PHP-FPM and checking for any errors:
sudo systemctl restart nginx php7.4-fpm
sudo systemctl status nginx php7.4-fpm
Step 10: Complete WordPress Installation Finally, you can complete the WordPress installation process by visiting your domain name or IP address in a web browser. Follow the on-screen instructions to set up your WordPress site.
And that’s it! You now have WordPress up and running on your Ubuntu Linux system using NGINX.