Skip to content

Instantly share code, notes, and snippets.

@naagaraa
Last active February 3, 2024 12:17
Show Gist options
  • Save naagaraa/7c94708bcb7caca0bb806f346fca1cda to your computer and use it in GitHub Desktop.
Save naagaraa/7c94708bcb7caca0bb806f346fca1cda to your computer and use it in GitHub Desktop.
Setup Laravel and Nodejs Nginx Ubuntu Server

Server Prepare for Development testing

  • nodejs
  • nginx
  • laravel

setup for nodejs

you need install pm2 in your server, by the way used ubuntu 22

run nodejs with pm2 in your project

sudo pm2 start npm --name "nexjs-example" -- start --max-memory-restart 100M

stop service background nodejs

pm2 stop <nama-service>

stop service background nodejs

pm2 delete <nama-service>

restart nginx

sudo systemctl restart nginx

update size upload and file in laravel development ubuntu

cd /etc/php/8.2/cli
After updating the upload_max_filesize and post_max_size values in the correct php.ini

setup config for nginx laravel

this example config for laravel nginx http edit or put script at /etc/nginx/site-available

server {
    listen 80;
    server_name example.com www.example.com;
    root /var/www/html/example.com/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

setup config for nginx nodejs pm2

this example config for nextjs edit or put script at /etc/nginx/site-available

server {
        listen 80;
        listen [::]:80;

        root /var/www/html/project.com;
        index index.html index.htm;

        server_name project.com www.project.com;

        location / {
                proxy_pass             http://127.0.0.1:3000;
                proxy_read_timeout     60;
                proxy_connect_timeout  60;
                proxy_redirect         off;

                # Allow the use of websockets
                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;
        }

        # simple headers
        add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
        add_header X-XSS-Protection          "1; mode=block" always;
        add_header X-Frame-Options DENY always;
}

install SSL certbot

sudo apt update && sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx
sudo certbot renew --dry-run

pull another branch to current local git

# git fetch origin <branch>

git fetch origin dev
git checkout -b dev origin/dev

git problem

while pull and have this message

hint: You have divergent branches and need to specify how to reconcile them.
hint: You can do so by running one of the following commands sometime before
hint: your next pull:
hint: 
hint:   git config pull.rebase false  # merge (the default strategy)
hint:   git config pull.rebase true   # rebase
hint:   git config pull.ff only       # fast-forward only
hint: 
hint: You can replace "git config" with "git config --global" to set a default
hint: preference for all repositories. You can also pass --rebase, --no-rebase,
hint: or --ff-only on the command line to override the configured default per
hint: invocation.

do it like this

Update 1:

If you have Git 2.29 or above, you can now set pull.ff to false, true or only to get rid of the warning.

git config pull.ff true
true - This is the default behaviour. Pull is fast-forwarded if possible, otherwise it's merged.

git config pull.ff false
false - Pull is never fast-forwarded, and a merge is always created.

git config pull.ff only
only - Pull is fast-forwarded if possible, otherwise operation is aborted with an error message.

git pull and ignore problem

"error: Your local changes to the following files would be overwritten by merge: vendor/composer/autoload_classmap.php vendor/composer/autoload_files.php vendor/composer/autoload_static.php Please commit your changes or stash them before you merge. Aborting``` "

git reset --hard && git clean -df
echo "/vendor" >> .gitignore
git rm -r --cached ./vendor

rename existing branch

https://www.freecodecamp.org/news/git-rename-branch-how-to-change-a-local-branch-name/

permission denied laravel

sudo chmod -R 777 bootstrap/cache/
sudo chmod -R 775 storage
sudo chmod -R ugo+rw storage

config ip table

comming soon

bash

directory

sudo chown www-data:www-data <appsnya> | /var/www/html
sudo  usermod -g www-data <appsnya> 

freescout guide

https://github.com/freescout-helpdesk/freescout/wiki/Installation-Guide#5-downloading-the-application

check firewall

  • comming soon

restart service

  • comming soon

memory check

# alternative 1
free -m

# alternative 2
sudo apt install htop
htop -t

nginx log dan access

sudo nano /var/log/nginx/access.log;
sudo nano /var/log/nginx/error.log 

create link server block

sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo ln -s /etc/nginx/sites-available/test.com /etc/nginx/sites-enabled/

php extention check

php -m

git log to csv

git log --date=local --pretty=format:'%h, %an, %ad, "%s"' >> log.csv
  1. open file log.csv
  2. data tab
  3. text to colum
  4. separate by delimeter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment