Skip to content
/ server-setup Public template

πŸ’» Server Setup Steps [Ubuntu] - NginX, Apache, MySQL, PHP, phpMyAdmin, NodeJS, MongoDB, Redis, PM2, Lets Encrypt, Certbot, Postgres etc.

License

Notifications You must be signed in to change notification settings

dr5hn/server-setup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

server-setup

List of useful resources & commands i use to setup an ubuntu server

Initial Ubuntu Setup

Ensure which init system is being used

  • Recent versions of Linux tend to use systemd (which uses the systemctl command), while older versions of Linux tend to use System V init (which uses the service command). If you are unsure which init system your platform uses, run the following command:
ps --no-headers -o comm 1

Check Running Processes

netstat -tulpn

Update Server Timezone

dpkg-reconfigure tzdata # Update timezone interactively
service cron restart # need to restart cron service if you've updated timezones
timedatectl # Validate if set properly

LAMP/LEMP

Nginx

Let's Encrypt

Useful Commands

# To obtain a certificate
certbot --nginx -d weoneapp.com -d www.weoneapp.com

# To check renewal
certbot renew --dry-run

# To check all certificates
certbot certificates

# Certbot issues: once the certificate is auto renewed we also have to reload the nginx service.
sudo nano /etc/cron.d/certbot

0 */12 * * * root test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew --renew-hook "sudo systemctl reload nginx"

Composer

composer install --optimize-autoloader --no-dev

Wordpress

NodeJS

PM2 Commands

# start & reload app with conf file
pm2 start ecosystem.config.js
pm2 reload ecosystem.config.js --update-env

# start & repload app without conf file
pm2 start app.js -i max --name example-api
pm2 reload app.js -i max --name example-api --update-env

# to auto start PM2 on System boot
pm2 startup

# to save the current running application state on system boot
pm2 save

# Install pm2-logrotate
pm2 install pm2-logrotate

MongoDB

Useful Commands

Mongo config file : /etc/mongod.conf
Mongo Logs : /var/log/mongodb
Mongo Data Dir : /var/lib/mongodb

sudo systemctl start mongod
systemctl status mongod
mongod --port 27017 --dbpath /var/lib/mongodb

# If (code=exited, status=14)
chown -R mongodb:mongodb /var/lib/mongodb
chown mongodb:mongodb /tmp/mongodb-27017.sock

# Create user
> use admin
> db.createUser({user: "weOadmin",pwd: passwordPrompt(),roles:[{role: "userAdminAnyDatabase", db: "admin" },"readWriteAnyDatabase"]})
> db.createUser({user:'weOapi', pwd: passwordPrompt(), roles:[{db:'movies', role:'readWrite'}]})

# Import a single collection
> mongoimport --db movies --collection beta_users_list beta_users_list.json --username weOapi --password secretPassword

# Import a full dump
> mongorestore dump/ -u=weOapi

# Take DB Backup
> mongodump -d movies -o back_11_aug -u weOapi -p 'secretPassword'
> cd back_11_aug && tar -cvzf movies.tar.gz weone/

Postgres

Redis

Useful Commands

# Manage Service
systemctl status redis.service
systemctl start redis.service
systemctl stop redis.service
systemctl restart redis.service

# Update config
nano /etc/redis/redis.conf

# Use Password
redis-cli
auth <password>

AWS EC2 Extending a Volume

MySQL SSH Tunneling

# DEBUGGING - YOU SHOULD SEE autossh sending a request every ServerAliveInterval seconds.
AUTOSSH_DEBUG=1 autossh -M 0 -N [email protected] -o "ServerAliveInterval 10" -o "ServerAliveCountMax 3" -L 6666:localhost:3306 -vvv

ps aux | grep ssh # Check SSH process is running
ps aux | grep autossh # Check AutoSSH process is running

# Main command
autossh -f -M 0 -N [email protected] -o "ServerAliveInterval 10" -o "ServerAliveCountMax 3" -C -L 3306:localhost:3306

Cronjobs

crontab -l # For listing
crontab -e # For editing

Configure logrotate for custom cron logs

nano /etc/logrotate.d/cronjobs
/var/log/cron-*.log {
    daily
    missingok
    rotate 10
    compress
    notifempty
    size 3M
}

Contributions

Welcoming more setup instructions, resources & commands.

Follow me at

Github @dr5hn Twitter @dr5hn LinkedIn @dr5hn

That's all Folks. Enjoy.

About

πŸ’» Server Setup Steps [Ubuntu] - NginX, Apache, MySQL, PHP, phpMyAdmin, NodeJS, MongoDB, Redis, PM2, Lets Encrypt, Certbot, Postgres etc.

Topics

Resources

License

Stars

Watchers

Forks