DevOps: Setup Server di VPS (Virtual Private Server)

iwanna
3 min readMar 24, 2023

--

Nginx Web Server

Step 1 — Updating System

sudo apt update

Step 2 — Installing Nginx

sudo apt install nginx

Database server

Step 1 — Installing MariaDB server

sudo apt install mariadb-server

Step 2 — Configuring MariaDB server

sudo mysql_secure_installation
...
Enter current password for root (enter for none):
...
Set root password? [Y/n] Y
New password:
Re-enter new password:
...
Remove anonymous users? [Y/n] Y
...
Disallow root login remotely? [Y/n] Y
...
Remove test database and access to it? [Y/n] Y
...
Reload privilege tables now? [Y/n] Y
...
All done!

Step 3 — Enable MariaDB server at boot time

sudo systemctl enable mariadb

Step 4 — Check status MariaDB server

sudo systemctl status mariadb

Step 5 — Adjusting User Authentication and Privileges

sudo mysql -p
...
#Add User
CREATE USER 'username'@'%' IDENTIFIED BY 'passwordHere';

GRANT ALL PRIVILEGES ON *.* TO 'username'@'%';

FLUSH PRIVILEGES;

use mysql;

...
#Change user password
ALTER USER 'username'@'%' IDENTIFIED BY 'newPasswordHere';
FLUSH PRIVILEGES;

...
#Show user
SELECT user, host FROM user;

...
#Delete user
DROP USER 'username'@'%';

Step 6 — Login into MySQL server

sudo mysql -u username -p

Step 7 — MySQL server configurations

sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf

...
bind-address = 0.0.0.0

Step 8 — Restart MySQL server

sudo systemctl restart mariadb

PHP Processor

Step 1 — Adding Repository PPA

sudo add-apt-repository ppa:ondrej/php

Step 2 — Updating System

sudo apt update

Step 3 — Installing PHP

sudo apt -y install php7.4
// or
sudo apt -y install php8.2

Step 4 — Installing Additional Package

sudo apt install php7.4-{cli,bcmath,bz2,intl,gd,mbstring,mysql,zip,fpm,curl,xml}
// or
sudo apt install php8.2-{cli,fpm,mysql,xml,mbstring,zip,curl,gd,intl,bz2,bcmath}

Step 5 — Setup to default php

sudo update-alternatives --set php /usr/bin/php7.4

Step 6 — Setup to use nginx

sudo systemctl disable --now apache2

Step 6 — Restarting service

sudo systemctl restart nginx

sudo systemctl restart php7.4-fpm.service
// or
sudo systemctl restart php8.2-fpm

Go-Lang

Step 1 — Install via Binary Distribution

sudo wget https://dl.google.com/go/go1.17.1.linux-amd64.tar.gz
sudo tar -xvf go1.17.1.linux-amd64.tar.gz

...
sudo mv go /usr/local

Step 2 — Set Environments

sudo nano ~/.bashrc
...
# Go Global variables
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH

...
source ~/.bashrc

Step 3 — Check Version

go version

NPM (Node Package Manager)

Step 1 — Install Node

sudo apt install nodejs

Step 2 — Install NPM

sudo apt install npm

Step 3 — Check Version

node -v
npm -v

Composer Package Manager

Step 1 — Downloading composer package

curl -sS https://getcomposer.org/installer | php 
sudo mv composer.phar /usr/bin/composer

Step 2 — Downloading composer version

composer --version

PM2 (Process Manager)

Step 1 — Install PM2

npm install pm2 -g

Step 2 — Run and test PM2

pm2 ls

Step 3 — Run Application

...
cd /app-dir

...
pm2 start npm --name "appName" -- start

Git Version Control

Step 1 — Installing GIT

sudo apt install git

Step 2 — Configuration SSH Key

cd ~/.ssh/

ssh-keygen -t rsa -C "your@email.com" -b 4096

...
Copy public key
Paste to gitlab/github

Firewall via UFW (Uncomplicated Firewall)

Step 1 — Enable Firewall

sudo ufw enable

Step 2 — Check Firewall

sudo ufw status

Step 3 — Allow Port

// for http
sudo ufw allow 80

// for https
sudo ufw allow 443

// for ssh
sudo ufw allow 22

// for mysql
sudo ufw allow 3306

Step 4 — Check Port Allowed

sudo ufw status verbose

...
Status: active
Logging: on (low)
Default: deny (incoming), allow (outgoing), disabled (routed)
New profiles: skip
To Action From
-- ------ ----
22/tcp ALLOW IN Anywhere
80/tcp ALLOW IN Anywhere
443 ALLOW IN Anywhere
3306 ALLOW IN Anywhere
22/tcp (v6) ALLOW IN Anywhere (v6)
80/tcp (v6) ALLOW IN Anywhere (v6)
443 (v6) ALLOW IN Anywhere (v6)
3306 (v6) ALLOW IN Anywhere (v6)

Setting Time Zone

Step 1 — Check available timezones

sudo timedatectl list-timezones

Step 2 — Set Timezone

sudo timedatectl set-timezone Asia/Jakarta

Step 3 — Test Timezone

sudo timedatectl

--

--

iwanna
iwanna

Written by iwanna

Software Engineer | Sharing insights on web development & coding practices.

No responses yet