Skip to content

Instantly share code, notes, and snippets.

@coucoseth
Last active September 21, 2024 03:25
Show Gist options
  • Select an option

  • Save coucoseth/43b6601a4d3d3db9791eaaadcbc122d8 to your computer and use it in GitHub Desktop.

Select an option

Save coucoseth/43b6601a4d3d3db9791eaaadcbc122d8 to your computer and use it in GitHub Desktop.
setting up a none root user on vps
Step 1 - login to putty with root user
Step 2 - sudo adduser <username> then
sudo usermod -aG sudo <username> to give sudo previlages
Step 3 - test user by switching to it
sudo su - <username>
Installing Node/NPM
Step 1 — curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash -
then
sudo apt-get install -y nodejs
Step 2 — Clone your project from Github
git clone yourproject.git
Step 3 — Install dependencies and test app
sudo npm i
then
npm start
Setting up mysql password
step 1 - login to mysql using root
sudo mysql -u root -p
step 2 - use sql table
USE mysql;
step 3 - ALTER USER 'root'@'localhost' IDENTIFIED WITH 'mysql_native_password' BY 'new_password';
then
FLUSH PRIVILEGES; then
quit; then loginto sql again using the new password set.
Importing sql file into database
mysql -u username -p database_name < file.sql
Step 4 - Setup PM2
sudo npm i pm2 -g
pm2 start app.js (default file)
# Other pm2 commands
pm2 show app
pm2 status
pm2 restart app
pm2 stop app
pm2 logs (Show log stream)
pm2 flush (Clear logs)
# To make sure app starts when reboot
pm2 startup ubuntu
Step 5 — Installing nginx
sudo apt install nginx
Step 6 — Change apache port
sudo nano /etc/apache2/ports.conf
then change port 80 to 8080 and 433 to 4334
then
sudo nano /etc/apache2/sites-enabled/000-default.conf
then <VirtualHost: *:80> to 8080 then restart apache
sudo service apache2 restart
then check if nginx is running
sudo service nginx status
if not then uninstall and reinstall it
sudo apt-get purge nginx nginx-common to uninstall and sudo apt install nginx to install
----to start nginx on boot --- sudo systemctl enable nginx
Step 7 — Installing Certbot
- first install snapd if your ubuntu version doesnt have it by default
sudo apt install snapd
- then install Certbot
sudo snap install --classic certbot
- then prepare certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot
Step 9 — Install Certbot’s Nginx package
sudo apt-get install python3-certbot-nginx
Step 10 — configure nginx
sudo nano /etc/nginx/sites-available/default
then change this line
root -> to point to code folder
server_name _, to server_name yourdomain.com www.yourdomain.com,
then
location / {
proxy_pass http://localhost:5000; #whatever port your app runs on
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
#change nginx request size limit
sudo nano /etc/nginx/nginx.conf then add this line
client_max_body_size 50M; inside http{...}
# then Check NGINX config
sudo nginx -t
# Reload NGINX
sudo systemctl reload nginx
Step 9 — Setup ufw firewall
sudo ufw enable
sudo ufw allow 'Nginx Full'
sudo ufw allow ssh (Port 22)
sudo ufw allow http (Port 80)
sudo ufw allow https (Port 443)
sudo ufw status
Step 9 — Obtain ssl certificate
sudo certbot --nginx -d example.com -d www.example.com
Step 9 — Verifying Certbot Auto-Renewal
sudo certbot renew --dry-run
How to index mysql table-
step 1.. check datatype,
ALTER TABLE <tablename> Modify column <columnname> varchar(10);
step 2 ... create the index
---syntax ====> create index <indexname> on <tablename> (<columnnames>);
create index idx_search on patient (first_name,last_name,fileNo);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment