<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Esinniobiwa Quareeb on Medium]]></title>
        <description><![CDATA[Stories by Esinniobiwa Quareeb on Medium]]></description>
        <link>https://medium.com/@muftyoftech?source=rss-79155028b8a0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*88QvUELdf4KPggWaXXqNZA.png</url>
            <title>Stories by Esinniobiwa Quareeb on Medium</title>
            <link>https://medium.com/@muftyoftech?source=rss-79155028b8a0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 11:04:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@muftyoftech/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Setting Up a Persistent NGROK Tunnel on Ubuntu to enable a Secure access to your Applications/APIs…]]></title>
            <link>https://medium.com/@muftyoftech/setting-up-a-persistent-ngrok-tunnel-on-ubuntu-to-enable-a-secure-access-to-your-applications-apis-7dd352f49c31?source=rss-79155028b8a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/7dd352f49c31</guid>
            <category><![CDATA[https]]></category>
            <category><![CDATA[ngrok]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[tunnelling]]></category>
            <dc:creator><![CDATA[Esinniobiwa Quareeb]]></dc:creator>
            <pubDate>Sat, 13 Jul 2024 10:00:43 GMT</pubDate>
            <atom:updated>2024-07-13T10:24:50.598Z</atom:updated>
            <content:encoded><![CDATA[<h3>Setting Up a Persistent NGROK Tunnel on <strong>Ubuntu</strong> to enable a Secure access to your Applications/APIs over HTTPS</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*5igBVApXVCVYPBHM.png" /></figure><h3>Introduction</h3><p>You’ve probably heard of NGROK and even used it on your local machine to tunnel your port. This article focused on setting it up on your server so that your application will keep running on HTTPs while you focus on something else.</p><p>Let’s get into it 🚀</p><p>In the world of web development, testing and sharing local applications can be challenging, especially when they need to be accessed remotely. <strong>NGROK</strong> is a tool that creates secure tunnels to your local server, making it accessible over the internet. This guide will walk you through the process of setting up a persistent NGROK tunnel on your Ubuntu server, enabling secure access to your applications over HTTPS even if you do not have domain name yet.</p><h3>What is NGROK?</h3><p><strong>NGROK</strong> is a service that exposes local servers behind NATs and firewalls to the public internet over secure tunnels. This allows developers to share their work with clients, test webhooks, or even run live demos without deploying their applications to a public server. It’s particularly useful for:</p><ul><li><strong>Webhooks</strong>: When developing applications that rely on webhook callbacks (like Stripe or GitHub), you need a publicly accessible URL to receive those requests.</li><li><strong>Collaborative Development</strong>: If you want to share your local development work with teammates or clients, NGROK provides a quick way to do so.</li><li><strong>Testing</strong>: You can test your APIs or applications from external devices without the hassle of deployment.</li></ul><h3>Prerequisites</h3><ul><li><strong>Ubuntu Server:</strong> Ensure you have an Ubuntu server up and running. This can be a local machine or a cloud-based server.</li><li><strong>NGROK Account:</strong> Sign up for a free NGROK account at <a href="https://ngrok.com/">ngrok.com</a>.</li><li><strong>NGROK Authtoken:</strong> Get your NGROK authtoken from the NGROK dashboard.</li><li><strong>SSH Access:</strong> Ensure you have SSH access to your Ubuntu server.</li><li><strong>NGROK Version 3:</strong> Free users need to upgrade to NGROK version 3, while premium users can use version 2.</li></ul><h3>Step 1: SSH to your server</h3><p>Establish connection to your server using this command:</p><pre>ssh username@your-server-ip</pre><h3>Step 2: Install NGROK</h3><ol><li><strong>Download NGROK</strong>:</li></ol><p>Visit the <a href="https://ngrok.com/download">NGROK download page</a> and download the latest version for Linux. Alternatively, you can use the command below to download it directly:</p><ul><li>For premium users, run the following command:</li></ul><pre>wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip<br>tar -xvzf ngrok-stable-linux-amd64.tgz<br>sudo mv ngrok /usr/local/bin</pre><ul><li>For free users, ensure you are using NGROK version 3, as older versions may not work. Download using this command:</li></ul><pre>wget https://bin.equinox.io/c/bNyj1mQVY4c/ngrok-v3-stable-linux-amd64.tgz<br>tar -xvzf ngrok-v3-stable-linux-amd64.tgz<br>sudo mv ngrok /usr/local/bin</pre><blockquote>Note: the difference between the 2 commands above is version number: v3</blockquote><ul><li>Verify the version number</li></ul><pre>ngrok --version</pre><h3>Step 3: <strong>Obtain NGROK Authtoken</strong></h3><ul><li>Go to the <a href="https://ngrok.com/">NGROK website</a> and sign up or log in.</li><li>Get your authtoken from the <a href="https://dashboard.ngrok.com/">NGROK dashboard</a>.</li></ul><pre>ngrok authtoken YOUR_AUTH_TOKEN</pre><p>It creates ngrok config file in this directory and save the auth token into it</p><blockquote>/root/.ngrok2/ngrok.yml</blockquote><ul><li>Add the remaining configuration to the .yml file by opening it:</li></ul><pre>sudo nano /root/.ngrok2/ngrok.yml</pre><p>It should look similar to this at first:</p><pre>authtoken: YOUR_AUTH_TOKEN</pre><p>Now append the remaining configuration:</p><pre>tunnels:<br>  nestjs-app:<br>    addr: 3000  # Replace with the port your application is running on<br>    proto: http<br>    hostname: your-subdomain.ngrok.io</pre><p>The resulting .yml should look like this:</p><pre>authtoken: YOUR_AUTH_TOKEN<br>tunnels:<br>  nestjs-app:<br>    addr: 3000  # Replace with the port your application is running on<br>    proto: http<br>    hostname: your-subdomain.ngrok.io</pre><p>Replace YOUR_AUTH_TOKEN, addr, proto, and hostname with your specific NGROK configuration details.</p><blockquote>addr is the port your application is running on</blockquote><blockquote>proto is the protocol</blockquote><blockquote>hostname is the ngrok url created in nginx dashboard</blockquote><pre>ngrok start --all --config /root/.ngrok2/ngrok.yml</pre><h3>Step 4: Automate Startup (Optional)</h3><p>Create a Systemd service file to start NGROK automatically on system startup.</p><pre>sudo nano /etc/systemd/system/ngrok.service</pre><ul><li>Add the following configuration:</li></ul><pre>[Unit]<br>Description=NGROK Tunnel Service<br><br>[Service]<br>ExecStart=/usr/local/bin/ngrok start --all --config /root/.ngrok2/ngrok.yml<br>Restart=always<br>User=root<br><br>[Install]<br>WantedBy=multi-user.target</pre><h4><strong>Enable and Start the Service</strong>:</h4><p>Enable and start the NGROK service:</p><pre>sudo systemctl enable ngrok<br>sudo systemctl start ngrok</pre><h4><strong>Check NGROK Service Status</strong></h4><p>Verify that the NGROK service is running:</p><pre>sudo systemctl status ngrok</pre><ul><li>You should see an active (running) status.</li></ul><h4>Access Your Application Securely</h4><p>Visit the NGROK dashboard or use the command ngrok status to find the public URL of your tunnel. You can now access your application securely over HTTPS using this URL.</p><h4>Conclusion</h4><p>By following these steps, you’ve set up a persistent NGROK tunnel on your Ubuntu server, enabling secure access to your applications and APIs over HTTPS. This setup ensures that your tunnel remains active even after reboots, providing a reliable way to expose local services to the internet.</p><p>NGROK is a powerful tool for developers, offering both simplicity and flexibility. Whether you’re developing webhooks, testing APIs, or accessing local applications remotely, NGROK can streamline your workflow and enhance your development process.</p><p>Feel free to share your experiences and any additional tips in the comments. Happy tunnelling!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7dd352f49c31" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Effortless Deployment of Next.js and React.js Frontend Projects with GitHub Actions]]></title>
            <link>https://medium.com/@muftyoftech/effortless-deployment-of-next-js-and-react-js-frontend-projects-with-github-actions-a5f9588cf41f?source=rss-79155028b8a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/a5f9588cf41f</guid>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Esinniobiwa Quareeb]]></dc:creator>
            <pubDate>Fri, 21 Jun 2024 00:07:47 GMT</pubDate>
            <atom:updated>2024-06-21T00:07:47.458Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sST9c_eU0deoPXRD.png" /></figure><p>Deploying frontend applications like Next.js and React.js to cloud servers can greatly enhance scalability and reliability. In this guide, we’ll walk through setting up a GitHub Actions workflow to automate deployment, ensuring your application is always up-to-date and accessible.</p><h4>Setting Up GitHub Actions for Next.js and React.js</h4><p>GitHub Actions provides a powerful platform for automating CI/CD workflows directly from your repository. We’ll leverage this to build and deploy your frontend application whenever changes are pushed to a specific branch.</p><h4>Step 1: Creating the GitHub Actions Workflow</h4><p>First, create a .github/workflows/main.yml file in your repository with the following contents:</p><pre>name: Build &amp; Deploy Frontend<br>on:<br>  push:<br>    branches:<br>      - main # Adjust branch name as needed<br><br>jobs:<br>  deploy:<br>    runs-on: ubuntu-latest<br><br>    steps:<br>      - name: Checkout code<br>        uses: actions/checkout@v2<br><br>      - name: Set up Node.js<br>        uses: actions/setup-node@v2<br>        with:<br>          node-version: &#39;14&#39; # Replace with your Node.js version<br><br>      - name: Install dependencies<br>        run: npm install<br><br>      - name: Build the project<br>        run: npm run build<br><br>      - name: Deploy to Server<br>        uses: appleboy/ssh-action@v0.1.2<br>        with:<br>          host: ${{ secrets.SSH_HOST }}<br>          username: ${{ secrets.SSH_USERNAME }}<br>          key: ${{ secrets.SSH_KEY }}<br>          port: ${{ secrets.SSH_PORT }}<br>          script: |<br>            export GIT_SSH_COMMAND=&quot;ssh -o StrictHostKeyChecking=no&quot;<br><br>            # Create the project directory if it doesn&#39;t exist<br>            PROJECT_DIR=~/frontend-app<br><br>            if [ ! -d &quot;$PROJECT_DIR&quot; ]; then<br>              mkdir -p $PROJECT_DIR<br>            fi<br><br>            # Go into the directory<br>            cd $PROJECT_DIR<br><br>            # if there is no deployment there, clone the repository, but if there is, pull latest changes<br>            if [ ! -d &quot;.git&quot; ]; then<br>              git clone --branch main git@github.com:username/frontend-project.git .<br>            else<br>              git pull origin main<br>            fi<br><br>            # Install Node.js and npm if not already installed<br>            if ! command -v node &amp;&gt; /dev/null; then<br>              curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -<br>              sudo apt-get install -y nodejs<br>            fi<br><br>            if ! command -v npm &amp;&gt; /dev/null; then<br>              sudo apt-get install -y npm<br>            fi<br><br>            # This part is optional to remove node_modules and install it each time<br>            rm -rf node_modules package-lock.json<br>            npm cache clean --force<br>            npm install<br>            npm run build<br><br>            # Use pm2 or serve to start your Next.js or React.js application<br>            # Example for Next.js<br>            # npm install -g pm2<br>            # pm2 start npm --name &quot;next-app&quot; -- start<br>            # pm2 save<br><br>            # Example for React.js (if using serve)<br>            # npm install -g serve<br>            # serve -s build<br><br>            echo &#39;Deployment successful&#39;</pre><p>Step 2: Customize for your Project</p><ul><li><strong>Node.js Version</strong>: Adjust node-version under setup-node@v2 to match your project&#39;s Node.js requirement.</li><li><strong>GitHub Secrets</strong>: Ensure SSH_HOST, SSH_USERNAME, SSH_KEY, and SSH_PORT are set up as repository secrets in your GitHub repository settings.</li><li><strong>Deployment Path</strong>: Modify PROJECT_DIR and the repository URL (git@github.com:username/frontend-project.git) to match your setup.</li></ul><h4>Step 3: Deploying Next.js or React.js Application</h4><ul><li>For Next.js, use pm2 to manage the server.</li><li>For React.js, consider using serve or any other server for static file hosting.</li></ul><h4>By implementing this GitHub Actions workflow, you’ve streamlined the deployment process for your Next.js or React.js frontend application. Now, any push to the specified branch will trigger an automatic build and deployment, ensuring your application is always current and accessible to your users.</h4><p>if you are looking for backend deployment guide, you can check this out:</p><p><a href="https://medium.com/@muftyoftech/deploying-yournestjs-application-to-a-cloud-server-aws-azure-digital-ocean-with-github-actions-ef4e1d78500e">https://medium.com/@muftyoftech/deploying-yournestjs-application-to-a-cloud-server-aws-azure-digital-ocean-with-github-actions-ef4e1d78500e</a></p><p>Go forth and deploy smarter with GitHub Actions today 👍!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a5f9588cf41f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying Your Laravel Application to a Cloud Server: A Step-by-Step Guide — The Manual Method]]></title>
            <link>https://medium.com/@muftyoftech/deploying-your-laravel-application-to-a-cloud-server-a-step-by-step-guide-db3c184c0f76?source=rss-79155028b8a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/db3c184c0f76</guid>
            <dc:creator><![CDATA[Esinniobiwa Quareeb]]></dc:creator>
            <pubDate>Fri, 07 Jun 2024 16:06:04 GMT</pubDate>
            <atom:updated>2024-06-30T14:48:42.748Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TdB1npZKRM-z3SbE.jpg" /></figure><p>Deploying a Laravel application to a cloud server can seem daunting, but with the right steps, it can be a smooth and efficient process. In this guide, I’ll walk you through deploying a Laravel application on a cloud server, using Ubuntu as the operating system.</p><h3>Prerequisites</h3><ul><li>An active cloud server (e.g., AWS, Azure, DigitalOcean).</li><li>Basic knowledge of SSH and server management.</li><li>A GitHub repository for your Laravel project.</li></ul><h3>Step 1: Initial Server Setup</h3><p>First, ensure you are logged in as the root user for all processes.</p><pre>ssh username@your-server-ip</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o7apcxUf9UHGaYVlrru6MQ.png" /></figure><h3>Update and Upgrade Your Server</h3><p>Begin by updating and upgrading your server to ensure you have the latest packages:</p><pre>lsb_release -a<br>sudo apt update<br>sudo apt upgrade</pre><h3>Install Nginx</h3><p>Nginx will serve your Laravel application:</p><pre>sudo apt install nginx</pre><h3>Retrieve Your Server’s IP Address</h3><p>To find your server’s public IP address, run:</p><pre>curl -4 icanhazip.com</pre><h3>Step 2: Install PHP</h3><h3>Install PHP and Necessary Extensions</h3><p>Install PHP along with the necessary extensions for Laravel:</p><pre>sudo apt install php-fpm php-mysql<br>sudo apt install php-xml php-mbstring php8.2-gd php8.2-zip php8.2-curl php8.2-intl</pre><p>(Optional: Install PHP 8.2)</p><pre>sudo apt install php8.2-fpm</pre><h3>Step 3: Clone Your Repository</h3><p>Navigate to your home directory and clone your Laravel project:</p><pre>cd ~<br>cd /var/www/html/<br>git clone https://github.com/your-username/your-laravel-repo.git</pre><h3>Step 4: Configure Nginx</h3><p>Set the correct permissions for your project directory:</p><pre>sudo chown -R $USER:$USER /var/www/html/your-laravel-folder</pre><p>Set correct permission for logs directory</p><pre>cd /var/www/html/your-laravel-folder<br>cd storage<br>sudo chmod -R 777 logs</pre><p>Create an Nginx configuration file for your site:</p><pre>sudo nano /etc/nginx/sites-available/example.com.conf</pre><p>Paste the following configuration, replacing placeholders with your actual values:</p><pre>server {<br>    listen 80;<br>    server_name your_domain_or_IP;<br>    root /var/www/html/your-laravel-folder/public;<br><br>    add_header X-Frame-Options &quot;SAMEORIGIN&quot;;<br>    add_header X-XSS-Protection &quot;1; mode=block&quot;;<br>    add_header X-Content-Type-Options &quot;nosniff&quot;;<br><br>    index index.html index.htm index.php;<br><br>    charset utf-8;<br><br>    location / {<br>        try_files $uri $uri/ /index.php?$query_string;<br>    }<br><br>    location = /favicon.ico { access_log off; log_not_found off; }<br>    location = /robots.txt  { access_log off; log_not_found off; }<br><br>    error_page 404 /index.php;<br><br>    location ~ \.php$ {<br>        fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;<br>        fastcgi_index index.php;<br>        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;<br>        include fastcgi_params;<br>    }<br><br>    location ~ /\.(?!well-known).* {<br>        deny all;<br>    }<br>}</pre><p>Save the file, ensure you replace <strong>your-laravel-folder </strong>with your actual project directory and ensure it you point to <strong>public </strong>folder, the index.php in public directory is the entry point of your application.</p><blockquote><em>php8.2-fpm.sock </em>can as well be <em>php8.0-fpm.sock</em>, <em>php8.1-fpm.sock</em>, <em>php7.4-fpm.sock</em> or any depending on the php version installed on the server.</blockquote><p># Link your configuration file and test Nginx:</p><pre>sudo ln -s /etc/nginx/sites-available/example.com.conf /etc/nginx/sites-enabled/</pre><pre>sudo nginx -t</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*01kq74nT8Z132PQ0CfJe5g.png" /></figure><blockquote><em>You can replace </em><strong><em>example.com.conf</em></strong><em> with whatever name you like, like </em><strong><em>yourprojecturl.com.conf</em></strong></blockquote><p>If the configuration test is successful, reload Nginx:</p><pre>sudo systemctl reload nginx</pre><h3>Step 5: Install Composer</h3><p>Install Composer, the dependency manager for PHP:</p><pre>cd ~<br>curl -sS https://getcomposer.org/installer -o composer-setup.php<br>HASH=$(curl -sS https://composer.github.io/installer.sig)</pre><pre>php -r &quot;if (hash_file(&#39;SHA384&#39;, &#39;composer-setup.php&#39;) === &#39;$HASH&#39;) { echo &#39;Installer verified&#39;; } else { echo &#39;Installer corrupt&#39;; unlink(&#39;composer-setup.php&#39;); } echo PHP_EOL;&quot;</pre><p># Install Composer</p><pre>sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer</pre><p>Create .env file for your project</p><pre>cd ~<br>cd /var/www/html/your-laravel-folder</pre><pre>sudo nano .env</pre><pre>APP_NAME=Laravel<br>APP_ENV=local<br>APP_KEY=<br>APP_DEBUG=true<br>APP_TIMEZONE=UTC<br>APP_URL=http://localhost<br><br>APP_LOCALE=en<br>APP_FALLBACK_LOCALE=en<br>APP_FAKER_LOCALE=en_US<br><br>APP_MAINTENANCE_DRIVER=file<br>APP_MAINTENANCE_STORE=database<br><br>BCRYPT_ROUNDS=12<br><br>LOG_CHANNEL=stack<br>LOG_STACK=single<br>LOG_DEPRECATIONS_CHANNEL=null<br>LOG_LEVEL=debug<br><br>DB_CONNECTION=mysql<br>DB_HOST=127.0.0.1<br>DB_PORT=3306<br>DB_DATABASE=your_laravel_project<br>DB_USERNAME=root<br>DB_PASSWORD=</pre><p>Enter correct credentials and Save the .env file and reload configuration</p><pre>php artisan optimize</pre><h3>Step 5: (Optional) Set Up MySQL Database</h3><p>Log into MySQL and create a new database and user:</p><pre>sudo mysql<br>CREATE DATABASE example_database;<br>CREATE USER &#39;example_user&#39;@&#39;%&#39; IDENTIFIED WITH mysql_native_password BY &#39;password&#39;;<br>GRANT ALL ON example_database.* TO &#39;example_user&#39;@&#39;%&#39;;<br>exit;</pre><p>To verify, log in with the new user:</p><pre>mysql -u example_user -p</pre><p>Install <strong>phpmyadmin</strong></p><pre>sudo apt update<br><br>sudo apt install phpmyadmin</pre><p>Follow the prompt to the end</p><p># To create a directory for your phpmyadmin</p><pre>cd ~<br>sudo ln -s /usr/share/phpmyadmin /var/www/html/your-laravel-project/public/phpmyadmin</pre><p>So that you can access it via ip_address/phpmyadmin e.g</p><pre>http://ip_address/phpmyadmin</pre><p>When you are done with the above configurations and setups, you should be able to access your project by putting the ip on your web browser:</p><pre>http://ip_address</pre><p>Congratulations 👏, your website is up and running.</p><p><em>If you run into any issue, you can check </em><strong><em>nginx</em></strong><em> log:</em></p><pre>tail -f /var/log/nginx/error.log</pre><p>You can as well check out:</p><p><a href="https://medium.com/@muftyoftech/deploying-yournestjs-application-to-a-cloud-server-aws-azure-digital-ocean-with-github-actions-ef4e1d78500e">Deploying Your NestJS Application to a Cloud Server (AWS, Azure, Digital Ocean)with GitHub Actions…</a></p><p>Cheers and happy coding !!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=db3c184c0f76" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying Your NestJS Application to a Cloud Server (AWS, Azure, Digital Ocean)with GitHub Actions…]]></title>
            <link>https://medium.com/@muftyoftech/deploying-yournestjs-application-to-a-cloud-server-aws-azure-digital-ocean-with-github-actions-ef4e1d78500e?source=rss-79155028b8a0------2</link>
            <guid isPermaLink="false">https://medium.com/p/ef4e1d78500e</guid>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Esinniobiwa Quareeb]]></dc:creator>
            <pubDate>Fri, 31 May 2024 12:09:55 GMT</pubDate>
            <atom:updated>2024-05-31T12:19:44.640Z</atom:updated>
            <content:encoded><![CDATA[<h3>Deploying Your NestJS Application to a Cloud Server (AWS, Azure, Digital Ocean)with GitHub Actions — The Easy and Saving Cost Way.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z6FgnGFwcZfAlYxJzI8vYQ.jpeg" /><figcaption>*************</figcaption></figure><p>Deploying a NestJS application can seem daunting, but with the help of GitHub Actions, the process becomes streamlined and automated. In this guide, I will walk you through the steps to set up continuous deployment for your NestJS application to a cloud server using GitHub Actions. Follow these steps to seamlessly deploy your application whenever you push updates to your repository.</p><h3>Prerequisites:</h3><ol><li>A Digital Ocean, Azure or AWS account where you will create your server on a droplet</li><li>A GitHub account where your repository is Hosted</li><li>Basic knowledge of Git, GitHub and GitHub Actions</li><li>Basic knowledge of Linux commands</li></ol><h3>Step 1: SSH into Your Linux Server</h3><p>First, establish a secure connection to your cloud server using SSH:</p><pre>ssh username@your-server-ip</pre><h3>Step 2: Generate and Configure SSH Keys</h3><p>Generate SSH keys to securely connect from GitHub to your server.</p><pre>ssh-keygen</pre><p><em>Alternatively, </em><strong><em>ed25519</em></strong><em> keys are accepted by default in OpenSSH. You could use this instead of </em><strong><em>rsa</em></strong><em> if needed:</em></p><p>After generating the keys, perform the following steps:</p><ol><li>Display the public SSH key:</li></ol><pre>cat ~/.ssh/id_rsa.pub</pre><p>2. Add the public key to the authorized_keys file:</p><pre>echo &quot;your-public-ssh-key&quot; &gt;&gt; ~/.ssh/authorized_keys</pre><p>3. Set appropriate permissions:</p><pre>chmod 600 ~/.ssh/id_rsa<br>chmod 700 ~/.ssh<br>chmod 600 ~/.ssh/authorized_keys</pre><p>4. Open OpenSSH daemon file:</p><pre>nano /etc/ssh/sshd_config</pre><p>Add this to the end of the file:</p><pre>HostbasedAcceptedKeyTypes +ssh-rsa<br>HostKeyAlgorithms +ssh-rsa<br>PubkeyAcceptedKeyTypes +ssh-rsa</pre><p>Restart ssh daemon :</p><pre>sudo systemctl restart ssh</pre><p>Restart the server :</p><pre>sudo reboot</pre><h3>Step 3: Configure GitHub Secrets and Deploy Keys</h3><h3>Add SSH Keys as GitHub Secrets</h3><p>Navigate to project repository-&gt; Settings -&gt; Secrets and variables -&gt; Actions and add the following keys and values from <strong>Step 2</strong>. Ensure you grant write access.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RWVW3uU38DpF3ZYpW40YJg.png" /></figure><p>Navigate to your GitHub repository and add the following secrets:</p><ul><li>SSH_KEY: Paste the private key content here.</li><li>SSH_USERNAME: The username for your server (e.g: root).</li><li>SSH_PORT: The SSH port (default is 22).</li><li>SSH_HOST: Your server IP address.</li></ul><p>You can get your server ip address with:</p><pre>curl -4 icanhazip.com </pre><p><strong>Add Deploy Keys:</strong></p><p>Navigate to Settings -&gt; Deploy keys in your GitHub repository and add the public key from <strong>Step 2</strong>. Ensure you grant write access.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DiKTVdRikhy4pddQ6QkFWg.png" /></figure><h3>Step 4: Set Up Your GitHub Action</h3><p>Create a GitHub Actions workflow file (.github/workflows/main.yml) in your project repository:</p><pre>name: Build &amp; Deploy API<br>on:<br>  push:<br>    branches: [staging] # staging or any other branch you intend to set CI/CD for<br><br>jobs:<br>  deploy:<br>    runs-on: ubuntu-latest<br><br>    steps:<br>      - name: Checkout code<br>        uses: actions/checkout@v2<br><br>      - name: Set up Node.js<br>        uses: actions/setup-node@v2<br>        with:<br>          node-version: &#39;21&#39;<br><br>      - name: Install dependencies<br>        run: npm install<br><br>      - name: Build the project<br>        run: npm run build<br><br>      - name: Deploy to Server<br>        uses: appleboy/ssh-action@v0.1.2<br>        # Connect to the server using credentials created<br>        with:<br>          host: ${{ secrets.SSH_HOST }}<br>          username: ${{ secrets.SSH_USERNAME }}<br>          key: ${{ secrets.SSH_KEY }}<br>          port: ${{ secrets.SSH_PORT }}<br>          script: |<br>            export GIT_SSH_COMMAND=&quot;ssh -o StrictHostKeyChecking=no&quot;<br><br>            # Create the project directory if it doesn&#39;t exist<br>            PROJECT_DIR=~/my-app<br><br>            if [ ! -d &quot;$PROJECT_DIR&quot; ]; then<br>              mkdir -p $PROJECT_DIR<br>            fi<br><br>            # Go into the directory<br>            cd $PROJECT_DIR<br><br>            # if there is no deployment their, clone the repository, but if there is, pull latest changes<br>            if [ ! -d &quot;.git&quot; ]; then<br>              git clone --branch develop git@github.com:username/project-name.git .<br>            else<br>              git pull origin staging<br>            fi<br><br>            # Install Node<br>            if ! command -v node &amp;&gt; /dev/null; then<br>              curl -sL https://deb.nodesource.com/setup_21.x | sudo -E bash -<br>              sudo apt-get install -y nodejs<br>            fi<br><br>            # Install npm<br>            if ! command -v npm &amp;&gt; /dev/null; then<br>              sudo apt-get install -y npm<br>            fi<br><br>            # Install pm2<br>            if ! command -v pm2 &amp;&gt; /dev/null; then<br>              sudo npm install -g pm2<br>            fi<br><br>            # This part is optional to remove node_modules and install it each time<br>            rm -rf node_modules package-lock.json<br>            npm cache clean --force<br>            npm install<br>            npm run build<br><br>            # Use pm2 to keep your application started<br>            if pm2 list | grep -q &quot;my-app&quot;; then<br>              pm2 restart my-app<br>            else<br>              # the directory of nestjs app can either be dist/src/main.js or dist/main.js<br>              pm2 start dist/src/main.js --name &quot;my-app&quot;<br>            fi<br><br>            pm2 save<br>            echo &#39;Deployment successful&#39;</pre><h3>Step 5: Configure Nginx</h3><p>To view your application on the browser, install and configure Nginx.</p><h3>Install and Start Nginx</h3><pre>sudo apt update<br>sudo apt install nginx<br>sudo systemctl start nginx</pre><h3>Update Nginx Configuration</h3><p>Edit the Nginx configuration file:</p><pre>sudo nano /etc/nginx/sites-enabled/default</pre><p>Replace the content of the location / block with:</p><pre>location / {<br>    proxy_pass http://localhost:3001;<br>    proxy_http_version 1.1;<br>    proxy_set_header Upgrade $http_upgrade;<br>    proxy_set_header Connection &#39;upgrade&#39;;<br>    proxy_set_header Host $host;<br>    proxy_cache_bypass $http_upgrade;<br>}</pre><h3>Test and Reload Nginx</h3><pre>sudo nginx -t<br>sudo systemctl reload nginx</pre><h3>Access Your Application</h3><p>Open a web browser and navigate to your server’s IP address followed by /api, such as:</p><pre>http://123.4.5.6/api</pre><h3>Conclusion</h3><p>Congratulations! You’ve successfully set up continuous deployment for your NestJS application using GitHub Actions. This process ensures that your application is always up-to-date and running smoothly on your cloud server. Feel free to adjust and expand upon this workflow to fit your specific needs. Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ef4e1d78500e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>