Skip to content

Instantly share code, notes, and snippets.

@ericamigo
Last active August 25, 2025 13:33
Show Gist options
  • Select an option

  • Save ericamigo/b499b522267b3187dcc594140ccf12c3 to your computer and use it in GitHub Desktop.

Select an option

Save ericamigo/b499b522267b3187dcc594140ccf12c3 to your computer and use it in GitHub Desktop.

setting up do server LEMP stack

  • create droplet and choose root password
  • login to server using the ssh password ssh root@ip
  • upgrade os packages
    • apt update
    • apt list --upgradable
    • apt upgrade
  • add new user
    • adduser username
    • usermod -aG sudo username to add user to the sudo group
    • to test/login user su - username
  • setup local ssh
    • cd ~/.ssh (for mac)
    • ssh-keygen -t ecdsa -b 521
    • enter key starts with id_ then leave the password empty
    • ssh-copy-id username@ip
  • disable root access (from here onward, you can use the new user you created - that's why it has sudo on all of the commands)
    • sudo nano /etc/ssh/sshd_config and set the following values
      • PermitRootLogin no
      • PubkeyAuthentication yes
      • uncomment AuthorizedKeysFile
      • PasswordAuthentication no
      • uncomment PermitEmptyPasswords no
    • restart the ssh server
      • sudo systemctl restart ssh
  • create config file inside ~/.ssh
    • cd ~/.ssh
    • nano config
        User username
        Hostname ip
        IdentityFile ~/.ssh/id_username
  • install php, nginx, mysql, nodejs and certbot

    • sudo add-apt-repository ppa:ondrej/php
    • sudo apt install php8.3-cli
    • sudo apt install php8.3-common php8.3-bcmath php8.3-mbstring php8.3-xml php8.3-curl php8.3-gd php8.3-zip php8.3-mysql php8.3-fpm php8.3-sqlite3 php8.3-intl
    • sudo apt install composer
    • sudo apt install mysql-server
    • sudo mysql_secure_installation
      • answer yes to all and for the password, choose (2 = STRONG)
      • sudo mysql and create a database CREATE DATABASE dbname;
      • CREATE USER 'username'@'localhost' IDENTIFIED BY 'password'; and make sure password is a bit more complex
      • GRANT ALL PRIVILEGES ON dbname.* TO 'username'@'localhost';
      • FLUSH PRIVILEGES;
    • sudo apt install nginx
      • to test, open the ip address in you browser and should see nginx page
    • go to https://github.com/nvm-sh/nvm and copy on of the installation command
      • follow the 2nd instruction for cloning the script for nvm
      • nvm install --lts
  • clone project

    • take ownership of the directory first
      • sudo chown -R username:username /var/www/html/
    • use ssh for cloning
    • generate ssh key pair for github
      • in the server cd ~/.ssh
      • generate a new ssh key as before ssh-keygen -t ecdsa -b 521
      • use id like id_github
      • cat id_github.pub and copy the value shown
      • paste the value in github https://github.com/settings/keys
      • check if ssh agent is running eval "$(ssh-agent -s)"
      • ssh-add ~/.ssh/id_github
      • test connection ssh -T git@github.com
    • clone the project now using SSH :)
  • change ownership of files

    • sudo chown -R $USER:www-data .
    • sudo find . -type f -exec chmod 664 {} \;
    • sudo find . -type d -exec chmod 775 {} \;
    • sudo chgrp -R www-data storage bootstrap/cache
    • sudo chmod -R ug+rwx storage bootstrap/cache
  • setup nginx

    • cd /etc/nginx/sites-available
    • sudo nano domain.com then paste the suggested settings from laravel docs - https://laravel.com/docs/11.x/deployment#nginx
    • enable server block sudo ln -s /etc/nginx/sites-available/domain.com /etc/nginx/sites-enabled
    • go to project folder and run sudo nginx -t to test configuration
    • sudo systemctl restart nginx
    • make user php8.4-fpm is installed if having 502 error
  • if needed to build using vite

    • sudo chmod +x ./node_modules/.bin/vite
    • sudo chmod +x /var/www/html/projectfolder/node_modules/@esbuild/linux-x64/bin/esbuild
    • sudo chown -R your_username:your_username /var/www/html/projectfolder/node_modules
    • rm -rf node_modules && npm i
  • install certbot

    • sudo apt install certbot python3-certbot-nginx
    • sudo certbot --nginx -d domain.com
  • if having problem cloning using git, do this coz agent might stopped working

    • cd ~/.ssh
    • nano config then own the file sudo chown username config
Hostname github.com
IdentityFile ~/.ssh/id_github
TCPKeepAlive yes
IdentitiesOnly yes
ServerAliveInterval 60

done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment