Skip to content

Instantly share code, notes, and snippets.

@rutcreate
Last active October 1, 2022 18:34
Show Gist options
  • Save rutcreate/a71ab8a947c11e459aa2bcd28848ea19 to your computer and use it in GitHub Desktop.
Save rutcreate/a71ab8a947c11e459aa2bcd28848ea19 to your computer and use it in GitHub Desktop.
Ubuntu for WordPress setup

Update package list

sudo apt update

Add new user

sudo adduser newuser
sudo usermod -aG sudo newuser
sudo usermod -aG www-data newuser
sudo usermod -aG staff newuser

Install Nginx

sudo apt install nginx-full

Setup Firewall

sudo ufw allow 'Nginx HTTP'
sudo ufw allow 'Nginx HTTPS'
sudo ufw allow OpenSSH
sudo ufw enable
sudo ufw status

Setup MySQL Server

sudo apt install mysql-server
sudo mysql_secure_installation

when it asks for "Do you wish to continue with the password provided?" => says "No"

Create Database User

CREATE DATABASE db_name;
CREATE USER 'john'@'localhost' IDENTIFIED WITH mysql_native_password BY 'johnpassword';
GRANT ALL PRIVILEGES ON db_name.* TO 'john'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;

Setup PHP

sudo apt install php-fpm php-mysql php-gd php-zip php-bcmath php-tokenizer

Update upload size

sudo vi /etc/php/7.4/fpm/php.ini

# find upload_max_filesize and post_max_size

Add site to Nginx

server {
        listen 80;
        server_name your-domain-name.com;
        root /sites/your-domain/wordpress;
        index index.php index.html;

        client_max_body_size 100M;

        # prevent call direct php file.
        location = /wp-includes/js/tinymce/wp-tinymce.php {
                try_files $uri $uri/ =404;
        }

        # prevent call direct php file.
        location ~* /wp-content/.*.php {
                deny all;
                access_log off;
                log_not_found off;
                return 404;
        }

        # prevent call direct php file.
        location ~* /wp-includes/.*.php {
                deny all;
                access_log off;
                log_not_found off;
                return 404;
        }

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

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment