- Connect to server
Only first connection to create username and SSH configure:
$ ssh root@domainRecomended (most secure):
$ ssh username@domainTIP: Login with root privileges:
$ sudo -i- Basic security settings
Create user.
# adduser usernameTurn user a sudoer adding:
# adduser username sudoOr turn user a sudoer adding in visudo:
# visudoadd: username ALL=(ALL) NOPASSWD:ALL
Or turn user a sudoer adding:
# usermod -aG sudo usernameNOTE: Replace username to your choice value.
TIP: Change default editor from Nano to Vim:
# update-alternatives --set editor /usr/bin/vim.basic --quietOr interactive:
# update-alternatives --config editorBlock SSH root login.
# sed -i 's/PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config
# sed -i 's/#PubkeyAuthentication yes/PubkeyAuthentication yes/' /etc/ssh/sshd_config
# systemctl restart ssh
Switch to username:
# su - usernameCreate SSH directory.
$ mkdir ~/.ssh && chmod 700 ~/.sshPaste your local key cat ~/.ssh/id_rsa.pub in:
$ editor ~/.ssh/authorized_keys
$ chmod 600 ~/.ssh/authorized_keysTIP: If your key not generate yet:
$ ssh-keygen -t rsaTIP: In MacOS you can paste to clipoard:
$ cat ~/.ssh/id_rsa.pub | pbcopyTIP: In Linux you can paste to clipoard:
$ sudo apt install xclip
$ cat ~/.ssh/id_rsa.pub | xclip -sel clipTIP: Remove host from know:
$ ssh-keygen -R domain- Set timezone and upgrade
# timedatectl set-timezone America/Sao_PauloOr interactive:
# dpkg-reconfigure tzdata# apt update && export DEBIAN_FRONTEND=noninteractive && apt -y dist-upgrade- Install all need packages
# apt update && apt install -y nginx php php-fpm php-mysql php-curl php-dom php-gd php-imagick php-mbstring php-ssh2 mysql-server zip unzip certbot python3-certbot-nginx && apt -y upgradeVerify if you need these extensions:
# apt install php-cli php-json php-pdo php-zip php-mbstring php-xml php-pear php-bcmath- Define hostname
Insert server domain.
# editor /etc/hostname- Configure Nginx
TIP: See webserver header output:
# curl -I http://localhostUncomment server_tokens off; and change user www-data to username:
# sed -i 's/# server_tokens off;/server_tokens off;/' /etc/nginx/nginx.conf
# sed -i 's/www-data/username/' /etc/nginx/nginx.conf
# systemctl stop apache2 && systemctl start nginx
NOTE: Replace username to correct value.
- Setup site
Create a server root directory:
$ mkdir ~/www && chmod 755 ~/wwwCreate a index test phpinfo file:
$ echo -e "<?php\nphpinfo();" > ~/www/index.phpCreate domain configuration:
# editor /etc/nginx/sites-available/domainNOTE: Replace domain to correct value.
server {
listen 80;
listen [::]:80;
server_name domain;
return 301 https://domain$request_uri;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
ssl_certificate /etc/letsencrypt/live/domain/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/domain/privkey.pem;
server_name domain;
root /home/username/www;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
include fastcgi_params;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME /home/username/www$fastcgi_script_name;
}
}
OR copy from default and edit:
# tail /etc/nginx/sites-available/default -n 13 | cut -c 2- | sudo tee /etc/nginx/sites-available/domain 1> /dev/nullChange all www-data user and group to username:
# sed -i 's/www-data/username/' /etc/php/7.4/fpm/pool.d/www.confEnable site.
# ln -s /etc/nginx/sites-available/domain /etc/nginx/sites-enabled/
# rm /etc/nginx/sites-enabled/default
# systemctl restart nginx php7.4-fpmCreate a MySQL user:
# mysql_secure_installation
# mysql -u root -pmysql> CREATE USER 'username'@'localhost' IDENTIFIED BY 'SECUREPASSWORD';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost';
mysql> FLUSH PRIVILEGES;NOTE: Replace SECUREPASSWORD to your choice value.
- Change to HTTPS
Remove TLSSNI01 attribute.
# sed -i 's/, challenges.TLSSNI01//' /usr/lib/python3/dist-packages/certbot_nginx/configurator.pyCreate certificate.
# certbot certonly --nginxNOTE: Replace domain to correct value.
- Install WP-CLI and WordPress
# curl -O -# https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar && chmod +x wp-cli.phar && sudo mv wp-cli.phar /usr/local/bin/wpCheck requirements:
# wp package install git@github.com:johnbillion/ext.git --allow-root
# wp ext check --allow-rootCreate wp-cli.local.yml:
$ editor ~/wp-cli.local.ymlpath: www
url: domain
core download:
locale: en_US
skip-content: true
config create:
dbname: username
dbuser: username
dbpass: SECUREPASSWORD
extra-php: |
define( 'WP_DEBUG', true );
:~$ wp core download && wp config create && wp db create && wp core install --prompt