Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save junaidulqayyumqureshi/914cd104fd2f9cc1c222f2836f4141e1 to your computer and use it in GitHub Desktop.
Save junaidulqayyumqureshi/914cd104fd2f9cc1c222f2836f4141e1 to your computer and use it in GitHub Desktop.
Research & Findings on CLOUD based website deployments, Development snippets & more
@junaidulqayyumqureshi
Copy link
Author

Angular Cache Reset for deployment

For Ang 10:
ng build --prod --aot --outputHashing=all

For <Ang 10:
ng build --prod --aot --output-hashing=all

@junaidulqayyumqureshi
Copy link
Author

Recursively Search String in files/folders

grep -Rw stringToSearch /var/www/project/*;

Recursively Replace string in files/folders

find /var/www/project/ -name \*.php -exec sed -i "s/stringToFind/stringToReplace/g" {} \;

@junaidulqayyumqureshi
Copy link
Author

junaidulqayyumqureshi commented Aug 18, 2021

Timezone Change

To change timezone
timedatectl set-timezone Asia/Karachi

To get timezone info:
timedatectl

systemctl restart mysql
systemctl reload apache2
systemctl restart apache2

@junaidulqayyumqureshi
Copy link
Author

junaidulqayyumqureshi commented Aug 18, 2021

Disable MYSQL ONLY FULL GROUP BY

Goto /etc/mysql & search for my.cnf whether shortcut of file, open terminal and type:

nano /etc/mysql/my.cnf
& append below includedirs:

[mysqld]  
sql_mode = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"

@junaidulqayyumqureshi
Copy link
Author

junaidulqayyumqureshi commented Oct 1, 2021

Source

PAID SSL (GoDaddy etc) - Not Lets Encrypt

Create a directory & adjust rights:

mkdir /etc/nginx/ssl
sudo chmod -R 600 /etc/nginx/ssl

Generate 2 keys, 1 example.com.key & 2 for example.com.csr

openssl req -newkey rsa:2048 -nodes -keyout example.com.key -out example.com.csr

Fill in the informations or skip by pressing enter, except Common Name FQDN etc. Provide your website name i.e example.com

2 files will be generated:

1- example.com.key
2- example.com.csr

Provide content of this csr file by copying > cat example.com.csr and provide to SSL provider.
Once SSL zip file is downloaded from SSL Provider. Unzip it and rename with following:

1- randomnumber.crt to example.com.crt
2- xxxbundle.crt to intermediate.crt

Copy both the files to /etc/nginx/ssl

run command:

cat example.com.crt intermediate.crt > example.com.chained.crt

Then change sites-available/site to following:


server {
    root /var/www/site;
    index index.php index.html index.htm;
    client_max_body_size 120M;

    server_name example.com www.example.com;
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        fastcgi_pass unix:/run/php/php7.4-fpm.sock;
        include snippets/fastcgi-php.conf;
    }



    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/nginx/ssl/example.com.chained.crt;
    ssl_certificate_key /etc/nginx/ssl/example.com.key;
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

server {
    if ($host = www.example.com) {
        return 301 https://$host$request_uri;
    }


    if ($host = example.com) {
        return 301 https://$host$request_uri;
    }
    server_name example.com www.example.com;
    listen 80;
    return 404; # managed by Certbot
}

Test nginx & restart by:

nginx -t
systemctl restart nginx

@junaidulqayyumqureshi
Copy link
Author

Check processes running linux:

ps -eo pid,ppid,%mem,%cpu,cmd --sort=-%cpu | head

@junaidulqayyumqureshi
Copy link
Author

@junaidulqayyumqureshi
Copy link
Author

junaidulqayyumqureshi commented Sep 1, 2022

Setting up another website in a subdirectory

server {
    root /var/www/example.com;
    index index.php index.html index.htm;
    client_max_body_size 120M;

    server_name example.com www.example.com;
    location / {
        try_files $uri $uri/ /index.html?$query_string;
    }

    location /blog {
        root /var/www/; //Make sure that project directory is named exactly as "location /blog" i.e. /var/www/blog
        
        try_files $uri $uri/ /blog/index.php?$args;
 
        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/run/php/php8.1-fpm.sock;
        }
    }

}

@junaidulqayyumqureshi
Copy link
Author

Deployment on DigitalOcean Apps Platform of a docker react app

1- Create file named "Dockerfile" (Without any extension)
2- Create folder called .docker on root and create a file in it with name "prod.Dockerfile"

Copy below content in both the files

# Use an official Node.js runtime as a parent image
FROM node:14-alpine

# Set the working directory to /app
WORKDIR /build

# Copy the package.json and package-lock.json files to the container
COPY package*.json ./

# Install the dependencies
RUN npm install

# Install the dependencies
RUN npm install -g serve

# Copy the remaining application files to the container
COPY . .

# Build the application
RUN npm run build

# Set the production environment variable
ENV NODE_ENV=production

# Expose port 3000
EXPOSE 3000

# Start the application
CMD ["serve", "-s", "build"]

3- After that, create an app on app platform and choose this repo

4- Remove extra webservice instances, if any, other than Docker WebService.

5- Define a port i.e. 3000 in settings

6- Define start and build scripts in package.json i.e. react-scripts start

Voila!!!

@junaidulqayyumqureshi
Copy link
Author

Recover EC2 instance & Connect without key pair

https://www.youtube.com/watch?v=5btWXn4yWzQ

@junaidulqayyumqureshi
Copy link
Author

Permission Denied EC2 CodeCommit

sudo chown -R ubuntu .git/

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