Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

sudo apt update

sudo apt upgrade


sudo apt install nginx

sudo systemctl status nginx

sudo ufw allow 'Nginx Full'

sudo ufw status

sudo apt install mysql-server

sudo systemctl status mysql

mysql -u root -p

mysql> CREATE DATABASE WordPress CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

mysql> GRANT ALL ON WordPress.* TO WordPressUser @'localhost' IDENTIFIED BY 'your


password';

mysql> FLUSH PRIVILEGES;

mysql> EXIT;

sudo apt install php7.2-cli php7.2-fpm php7.2-mysql php7.2-json php7.2-opcache php7.2-


mbstring php7.2-xml php7.2-gd php7.2-curl
sudo mkdir -p /var/www/html/sample.com

cd /tmp

wget https://wordpress.org/latest.tar.gz

tar xf latest.tar.gz

sudo mv /tmp/wordpress/* /var/www/html/sample.com/

sudo chown -R www-data: /var/www/html/sample.com

Add this code to the newly created file:

# Redirect HTTP -> HTTPS


server {
listen 80;
server_name www.sample.com sample.com;

include snippets/letsencrypt.conf;
return 301 https://sample.com$request_uri;
}

# Redirect WWW -> NON-WWW


server {
listen 443 ssl http2;
server_name www.sample.com;

ssl_certificate /etc/letsencrypt/live/sample.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/sample.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/sample.com/chain.pem;
include snippets/ssl.conf;

return 301 https://sample.com$request_uri;


}
}

server {
listen 443 ssl http2;
server_name sample.com;

root /var/www/html/sample.com;
index index.php;

# SSL parameters
ssl_certificate /etc/letsencrypt/live/sample.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/sample.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/sample.com/chain.pem;
include snippets/ssl.conf;
include snippets/letsencrypt.conf;

# log files
access_log /var/log/nginx/sample.com.access.log;
error_log /var/log/nginx/sample.com.error.log;

location = /favicon.ico {
log_not_found off;
access_log off;
}

location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}

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

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}

location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
expires max;
log_not_found off;
}
}

sudo ln -s /etc/nginx/sites-available/sample.com /etc/nginx/sites-enabled/

sudo nginx -t

sudo systemctl restart nginx

You might also like