{"id":20000313,"url":"https://github.com/dr5hn/server-setup","last_synced_at":"2025-05-04T15:32:18.107Z","repository":{"id":110828488,"uuid":"283459115","full_name":"dr5hn/server-setup","owner":"dr5hn","description":"💻 Server Setup Steps [Ubuntu] - NginX, Apache, MySQL, PHP, phpMyAdmin, NodeJS, MongoDB, Redis, PM2, Lets Encrypt, Certbot, Postgres etc.","archived":false,"fork":false,"pushed_at":"2022-06-08T08:12:45.000Z","size":36,"stargazers_count":12,"open_issues_count":0,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-29T16:25:37.537Z","etag":null,"topics":["certbot","hacktoberfest","lemp","letsencrypt","linux","mongodb","mysql","nginx","nodejs","pm2","postgresql","redis","server-setup","ubuntu","wordpress"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dr5hn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null},"funding":{"github":"dr5hn","ko_fi":"dr5hn"}},"created_at":"2020-07-29T09:42:49.000Z","updated_at":"2024-11-11T23:21:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"dd3dd33e-6c07-4101-bf2c-3416099af272","html_url":"https://github.com/dr5hn/server-setup","commit_stats":{"total_commits":3,"total_committers":1,"mean_commits":3.0,"dds":0.0,"last_synced_commit":"65ae5a3ccf51b94bbfc45b51aa1f6dd6962a8c37"},"previous_names":[],"tags_count":0,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dr5hn%2Fserver-setup","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dr5hn%2Fserver-setup/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dr5hn%2Fserver-setup/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dr5hn%2Fserver-setup/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dr5hn","download_url":"https://codeload.github.com/dr5hn/server-setup/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252277810,"owners_count":21722601,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["certbot","hacktoberfest","lemp","letsencrypt","linux","mongodb","mysql","nginx","nodejs","pm2","postgresql","redis","server-setup","ubuntu","wordpress"],"created_at":"2024-11-13T05:14:24.387Z","updated_at":"2025-05-04T15:32:18.062Z","avatar_url":"https://github.com/dr5hn.png","language":null,"funding_links":["https://github.com/sponsors/dr5hn","https://ko-fi.com/dr5hn"],"categories":[],"sub_categories":[],"readme":"# server-setup\nList of useful resources \u0026 commands i use to setup an ubuntu server\n\n\u003cimg src=\"images/server-setup.png\"\u003e\n\n## Initial Ubuntu Setup\n* [Initial Server Setup with Ubuntu 18.04](https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-18-04)\n* [How to Set Up SSH Keys on Ubuntu 18.04](https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys-on-ubuntu-1804)\n\n## Ensure which init system is being used\n* 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).\nIf you are unsure which init system your platform uses, run the following command:\n```\nps --no-headers -o comm 1\n```\n\n## Check Running Processes\n```bash\nnetstat -tulpn\n```\n\n## Update Server Timezone\n```bash\ndpkg-reconfigure tzdata # Update timezone interactively\nservice cron restart # need to restart cron service if you've updated timezones\ntimedatectl # Validate if set properly\n```\n\n## LAMP/LEMP\n* [How To Install Linux, Nginx, MySQL, PHP (LEMP stack) on Ubuntu 18.04](https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-ubuntu-18-04)\n\n## Nginx\n* [How To Install Nginx on Ubuntu 18.04](https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-18-04)\n* [Add Brotli support to Nginx on Ubuntu 18.04](https://www.vultr.com/docs/add-brotli-support-to-nginx-on-ubuntu-18-04)\n* [How To Set Up Password Authentication with Nginx on Ubuntu 14.04](https://www.digitalocean.com/community/tutorials/how-to-set-up-password-authentication-with-nginx-on-ubuntu-14-04)\n\n## Let's Encrypt\n* [How To Secure Nginx with Let's Encrypt on Ubuntu 18.04](https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-18-04)\n* [Secure Nginx with Let's Encrypt on Ubuntu 18.04](https://linuxize.com/post/secure-nginx-with-let-s-encrypt-on-ubuntu-18-04/)\n\nUseful Commands\n```bash\n# To obtain a certificate\ncertbot --nginx -d weoneapp.com -d www.weoneapp.com\n\n# To check renewal\ncertbot renew --dry-run\n\n# To check all certificates\ncertbot certificates\n\n# Certbot issues: once the certificate is auto renewed we also have to reload the nginx service.\nsudo nano /etc/cron.d/certbot\n\n0 */12 * * * root test -x /usr/bin/certbot -a \\! -d /run/systemd/system \u0026\u0026 perl -e 'sleep int(rand(43200))' \u0026\u0026 certbot -q renew --renew-hook \"sudo systemctl reload nginx\"\n```\n\n## Composer\n* [How To Install and Use Composer on Ubuntu 18.04](https://www.digitalocean.com/community/tutorials/how-to-install-and-use-composer-on-ubuntu-18-04)\n```bash\ncomposer install --optimize-autoloader --no-dev\n```\n\n## Wordpress\n* [How To Install WordPress with LEMP on Ubuntu 18.04](https://www.digitalocean.com/community/tutorials/how-to-install-wordpress-with-lemp-on-ubuntu-18-04)\n* [Integrating AWS S3 \u0026 Cloudfront With Wordpress](https://blog.lawrencemcdaniel.com/integrating-aws-s3-cloudfront-with-wordpress-2/)\n* [Install WordPress with Ubuntu 18.04, NGINX, MariaDB and PHP 7.4](https://gulshankumar.net/install-wordpress-with-lemp-on-ubuntu-18-04/)\n* [Setup Your Wordpress Site The Right Way](https://blog.lawrencemcdaniel.com/wordpress-enhancements/)\n\n## NodeJS\n* [Setting up an HTTPS site using Nodejs, AWS EC2, Nginx, Let's Encrypt, and Namecheap - Zeevo](https://shaneoneill.io/2018/10/21/setting-up-an-https-site-using-nodejs-aws-ec2-nginx-lets-encrypt-and-namecheap/)\n* [How To Set Up a Node.js App for Production on Ubuntu 18.04](https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-18-04)\n\n## PM2 Commands\n```bash\n# start \u0026 reload app with conf file\npm2 start ecosystem.config.js\npm2 reload ecosystem.config.js --update-env\n\n# start \u0026 repload app without conf file\npm2 start app.js -i max --name example-api\npm2 reload app.js -i max --name example-api --update-env\n\n# to auto start PM2 on System boot\npm2 startup\n\n# to save the current running application state on system boot\npm2 save\n\n# Install pm2-logrotate\npm2 install pm2-logrotate\n```\n\n## MongoDB\n* [Install MongoDB Community Edition on Ubuntu — MongoDB Manual](https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/)\n\nUseful Commands\n```bash\nMongo config file : /etc/mongod.conf\nMongo Logs : /var/log/mongodb\nMongo Data Dir : /var/lib/mongodb\n\nsudo systemctl start mongod\nsystemctl status mongod\nmongod --port 27017 --dbpath /var/lib/mongodb\n\n# If (code=exited, status=14)\nchown -R mongodb:mongodb /var/lib/mongodb\nchown mongodb:mongodb /tmp/mongodb-27017.sock\n\n# Create user\n\u003e use admin\n\u003e db.createUser({user: \"weOadmin\",pwd: passwordPrompt(),roles:[{role: \"userAdminAnyDatabase\", db: \"admin\" },\"readWriteAnyDatabase\"]})\n\u003e db.createUser({user:'weOapi', pwd: passwordPrompt(), roles:[{db:'movies', role:'readWrite'}]})\n\n# Import a single collection\n\u003e mongoimport --db movies --collection beta_users_list beta_users_list.json --username weOapi --password secretPassword\n\n# Import a full dump\n\u003e mongorestore dump/ -u=weOapi\n\n# Take DB Backup\n\u003e mongodump -d movies -o back_11_aug -u weOapi -p 'secretPassword'\n\u003e cd back_11_aug \u0026\u0026 tar -cvzf movies.tar.gz weone/\n```\n\n## Postgres\n* [How To Install PostgreSQL on Ubuntu 20.04 [Quickstart]](https://www.digitalocean.com/community/tutorials/how-to-install-postgresql-on-ubuntu-20-04-quickstart)\n\n## Redis\n* [How To Install and Secure Redis on Ubuntu 18.04](https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-redis-on-ubuntu-18-04)\n\nUseful Commands\n```bash\n# Manage Service\nsystemctl status redis.service\nsystemctl start redis.service\nsystemctl stop redis.service\nsystemctl restart redis.service\n\n# Update config\nnano /etc/redis/redis.conf\n\n# Use Password\nredis-cli\nauth \u003cpassword\u003e\n```\n\n## AWS EC2 Extending a Volume\n* [Extending a Linux file system after resizing a volume - Amazon Elastic Compute Cloud](https://docs.amazonaws.cn/en_us/AWSEC2/latest/UserGuide/recognize-expanded-volume-linux.html)\n\n## MySQL SSH Tunneling\n* [Connecting to MySQL Remotely Using AutoSSH and SSH Tunneling](https://www.amplitudedesign.com/2018/11/connecting-to-mysql-remotely-using-autossh-and-ssh-tunneling/)\n```bash\n# DEBUGGING - YOU SHOULD SEE autossh sending a request every ServerAliveInterval seconds.\nAUTOSSH_DEBUG=1 autossh -M 0 -N ubuntu@15.123.456.52 -o \"ServerAliveInterval 10\" -o \"ServerAliveCountMax 3\" -L 6666:localhost:3306 -vvv\n\nps aux | grep ssh # Check SSH process is running\nps aux | grep autossh # Check AutoSSH process is running\n\n# Main command\nautossh -f -M 0 -N ubuntu@15.123.456.52 -o \"ServerAliveInterval 10\" -o \"ServerAliveCountMax 3\" -C -L 3306:localhost:3306\n```\n\n## Cronjobs\n```bash\ncrontab -l # For listing\ncrontab -e # For editing\n```\n\n## Configure logrotate for custom cron logs\n```bash\nnano /etc/logrotate.d/cronjobs\n/var/log/cron-*.log {\n    daily\n    missingok\n    rotate 10\n    compress\n    notifempty\n    size 3M\n}\n```\n\n## Contributions\nWelcoming more setup instructions, resources \u0026 commands.\n\n## Follow me at\n\u003ca href=\"https://github.com/dr5hn/\"\u003e\u003cimg alt=\"Github @dr5hn\" src=\"https://img.shields.io/static/v1?logo=github\u0026message=Github\u0026color=black\u0026style=flat-square\u0026label=\" /\u003e\u003c/a\u003e \u003ca href=\"https://twitter.com/dr5hn/\"\u003e\u003cimg alt=\"Twitter @dr5hn\" src=\"https://img.shields.io/static/v1?logo=twitter\u0026message=Twitter\u0026color=black\u0026style=flat-square\u0026label=\" /\u003e\u003c/a\u003e \u003ca href=\"https://www.linkedin.com/in/dr5hn/\"\u003e\u003cimg alt=\"LinkedIn @dr5hn\" src=\"https://img.shields.io/static/v1?logo=linkedin\u0026message=LinkedIn\u0026color=black\u0026style=flat-square\u0026label=\u0026link=https://twitter.com/dr5hn\" /\u003e\u003c/a\u003e\n\nThat's all Folks. Enjoy.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdr5hn%2Fserver-setup","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdr5hn%2Fserver-setup","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdr5hn%2Fserver-setup/lists"}