Prerequisites
- Recommended OS: Ubuntu 20.04.
- User account: A user account with sudo or root access.
sudo apt update && sudo apt upgrade -y
Open firewall ports.
sudo ufw allow http
sudo ufw allow https
Remove Apache.
sudo apt remove apache2 -y
Install Nginx, MariaDB and php.
sudo apt install nginx mariadb-server php7.4-imagick php7.4-bcmath php php7.4-curl php7.4-cli php7.4-mysql php7.4-gd php7.4-intl php7.4-mbstring php7.4-soap php7.4-xml php7.4-xmlrpc php7.4-zip php7.4-fpm php7.4-json php7.4-common -y
Start Nginx and MariaDB.
systemctl start nginx
systemctl start mariadb
Configure MariaDB.
mysql_secure_installation
Login into MariaDB and create databases.
mysql -u root -p
CREATE DATABASE wp;
CREATE USER wpadmin@localhost IDENTIFIED BY '123@Pass';
GRANT ALL ON wp.* TO wpadmin@localhost;
FLUSH PRIVILEGES;
EXIT;
Create a directory for your site.
Note
In all below commands, please replace bim.leoguides.com by your site domain.
sudo mkdir -p /var/www/html/bim.leoguides.com
Download latest wordpress built to temp folder.
wget https://wordpress.org/latest.tar.gz -P /tmp
Extract downloaded file.
tar xf /tmp/latest.tar.gz -C /tmp
Move extracted things to the root of your site location.
sudo mv /tmp/wordpress/* /var/www/html/bim.leoguides.com/
Grant permission.
sudo chown -R www-data:www-data /var/www/html/bim.leoguides.com/
sudo chmod -R 775 /var/www/html/bim.leoguides.com/
Navigate to the site directory.
cd /var/www/html/bim.leoguides.com/
Backup configuration file then edit it.
sudo mv wp-config-sample.php wp-config.php
sudo nano wp-config.php
Remove default settings.
sudo rm /etc/nginx/sites-enabled/default
sudo rm /etc/nginx/sites-available/default
Create a virtual host configuration file.
sudo nano /etc/nginx/conf.d/bim.leoguides.com.conf
server {
listen 80;
listen [::]:80;
server_name www.bim.leoguides.com bim.leoguides.com;
root /var/www/html/bim.leoguides.com/;
index index.php index.html index.htm index.nginx-debian.html;
client_max_body_size 20M;
location ~ \.php$ {
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
include snippets/fastcgi-php.conf;
}
#enable gzip compression
gzip on;
gzip_vary on;
gzip_min_length 1000;
gzip_comp_level 5;
gzip_types application/json text/css application/x-javascript application/javascript image/svg+xml;
gzip_proxied any;
# A long browser cache lifetime can speed up repeat visits to your page
location ~* \.(jpg|jpeg|gif|png|webp|svg|woff|woff2|ttf|css|js|ico|xml)$ {
access_log off;
log_not_found off;
expires 360d;
}
# disable access to hidden files
location ~ /\.ht {
access_log off;
log_not_found off;
deny all;
}
}
Check Nginx configuration file then restart Nginx.
sudo nginx -t
sudo systemctl restart nginx
Enabling HTTPS
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx --agree-tos --redirect --hsts --staple-ocsp --email admin@leoguides.com -d bim.leoguides.com
5/5 - (4 votes)