<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mohammad Anisur Rahman</title>
    <description>The latest articles on DEV Community by Mohammad Anisur Rahman (@aanis434).</description>
    <link>https://dev.to/aanis434</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1068617%2F3be0a2f1-aa5a-4883-a148-aaba4a73694e.jpg</url>
      <title>DEV Community: Mohammad Anisur Rahman</title>
      <link>https://dev.to/aanis434</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/aanis434"/>
    <language>en</language>
    <item>
      <title>How To Deploy a Django Application with Apache2 on Ubuntu in AWS EC2 instance?</title>
      <dc:creator>Mohammad Anisur Rahman</dc:creator>
      <pubDate>Fri, 21 Apr 2023 14:11:31 +0000</pubDate>
      <link>https://dev.to/aanis434/how-to-deploy-a-django-application-with-apache2-on-ubuntu-in-aws-ec2-instance-25h2</link>
      <guid>https://dev.to/aanis434/how-to-deploy-a-django-application-with-apache2-on-ubuntu-in-aws-ec2-instance-25h2</guid>
      <description>&lt;p&gt;&lt;strong&gt;In this tutorial, you’ll deploy a Django application on Ubuntu EC2 instance running Apache2 step by step.&lt;/strong&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  Prerequisites
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;Install apache2
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~ sudo apt update

~ sudo apt install apache2

~ sudo service apache2 start

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Apache Error watch
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~ watch tail -n 15 /var/log/apache2/error.log 

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Check python version
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~ python3 –version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Install pip
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~ sudo apt install python3-pip

~ sudo apt install python3-venv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Create project directory&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;~ mkdir demo&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Change the ownership to ubuntu. Example:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~ sudo chown -R ubuntu:ubuntu demo

~ sudo chmod 777 demo

~ sudo chmod 755 /home/&amp;lt;user&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Add GitHub Repository. If you need generate SSH key for GitHub, you can visit this &lt;a href="https://dev.to/aanis434/how-to-set-up-ssh-keys-for-github-on-ubuntu-ec2-instance-d2p"&gt;link&lt;/a&gt;.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~ git init

~ git remote add origin repository_link

~ git pull origin main

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Change the ownership of the media directory. Example:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~ sudo chown -R www-data:www-data demo/media
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt; Create virtual env at demo
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~ cd demo

~ python3 -m venv env

~ source env/bin/activate #Activate virtual env

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Install packages&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;~ pip3 install -r requirements.txt&lt;/code&gt;&lt;/p&gt;




&lt;h5&gt;
  
  
  Apache Server Configurations
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;Make a demo.conf file on /etc/apache2/sites-available and configure following way
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;VirtualHost *:80&amp;gt;
    ServerAdmin webmaster@localhost
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /home/ubuntu/demo
    &amp;lt;Directory /home/ubuntu/demo&amp;gt;
        AllowOverride all
        Require all granted
        Options FollowSymlinks
        Allow from all
    &amp;lt;/Directory&amp;gt;

    Alias /media /home/ubuntu/demo/media
    Alias /static /home/ubuntu/demo/static

    &amp;lt;Directory /home/ubuntu/demo/static&amp;gt;
        Require all granted
    &amp;lt;/Directory&amp;gt;

    &amp;lt;Directory /home/ubuntu/demo/media&amp;gt;
    Require all granted
    &amp;lt;/Directory&amp;gt;

    &amp;lt;Directory /home/ubuntu/demo/demo&amp;gt;
        &amp;lt;Files wsgi.py&amp;gt;
            Require all granted
        &amp;lt;/Files&amp;gt;
    &amp;lt;/Directory&amp;gt;


    WSGIDaemonProcess demo python-path=/home/ubuntu/demo python-home=/home/ubuntu/demo/env
    WSGIProcessGroup demo
    WSGIScriptAlias / /home/ubuntu/demo/demo/wsgi.py

&amp;lt;/VirtualHost&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Make migrate and collect static
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~ source env/bin/activate

~ python3 manage.py makemigrations

~ python3 manage.py migrate

~ python3 manage.py collectstatic
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Change permission and ownership
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~ sudo chmod 664 db.sqlite3

~ sudo chown :www-data db.sqlite3

~ sudo chown :www-data demo

~ sudo chown :www-data demo/demo

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Enable apache site configuration file
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~ sudo a2ensite demo.conf

~ sudo a2dissite default.conf

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Install wsgi mod in apache
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~ sudo apt-get install libapache2-mod-wsgi-py3

~ sudo a2enmod wsgi

~ sudo service apache2 restart

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Apache Server log
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~ watch tail -n 15 /var/log/apache2/error.log 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;em&gt;Done! Now you can browse your application with the domain name.&lt;/em&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to Set Up SSH Keys for GitHub on Ubuntu EC2 Instance</title>
      <dc:creator>Mohammad Anisur Rahman</dc:creator>
      <pubDate>Thu, 20 Apr 2023 18:57:03 +0000</pubDate>
      <link>https://dev.to/aanis434/how-to-set-up-ssh-keys-for-github-on-ubuntu-ec2-instance-d2p</link>
      <guid>https://dev.to/aanis434/how-to-set-up-ssh-keys-for-github-on-ubuntu-ec2-instance-d2p</guid>
      <description>&lt;p&gt;&lt;strong&gt;In this tutorial, you learn how to generate SSH key for GitHub and clone your GitHub repository in AWS ubuntu server with SSH command.&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Generate SSH key and add the SSH key
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~ ssh-keygen -t ed25519 -C "your_email@example.com"

~ eval "$(ssh-agent -s)"

~ ssh-add ~/.ssh/id_ed25519

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Copy the newly generated SSH Key and add the SSH key to your GitHub account.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~ cat ~/.ssh/id_ed25519.pub

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;em&gt;Now you can initialize git in your project directory and add GitHub repository with SSH command. And you can manage the code with git command.&lt;/em&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How To Deploy a React / Next.js Application with Apache2 on Ubuntu in AWS EC2 instance?</title>
      <dc:creator>Mohammad Anisur Rahman</dc:creator>
      <pubDate>Thu, 20 Apr 2023 18:32:47 +0000</pubDate>
      <link>https://dev.to/aanis434/how-to-deploy-a-react-nextjs-application-with-apache2-on-ubuntu-in-aws-ec2-instance-221o</link>
      <guid>https://dev.to/aanis434/how-to-deploy-a-react-nextjs-application-with-apache2-on-ubuntu-in-aws-ec2-instance-221o</guid>
      <description>&lt;p&gt;&lt;strong&gt;In this tutorial, you’ll deploy a React / Next.js application on Ubuntu EC2 instance running Apache2. You’ll deploy an application using GitHub repository, use an Apache2 config file to determine where to deploy files, and securely run with apache2 proxy server. By the end of this tutorial, you’ll be able to build and deploy a React application.&lt;/strong&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  Prerequisites
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;You need a ubuntu ec2 instance in AWS server &lt;/li&gt;
&lt;li&gt;First Install nvm and start to Install Node with nvm
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~ sudo apt-get update

~ sudo curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Activate the nvm
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~ . ~/.nvm/nvm.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Install Node.js with nvm and check the version.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~ nvm install node

~ node -v
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Install PM2 to manage proxy server
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~ npm i -g pm2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;em&gt;&lt;strong&gt;Now you need to create a project directory and change the ownership to ubuntu and give permission to initialize a git repository.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Make a directory and change the ownership to ubuntu
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  ~ sudo mkdir project_name 

  ~ sudo chown -R ubuntu:ubuntu directory_name

  ~ sudo chmod 777 DIR_NAME cd DIR_NAME  # change permission

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Add your Github Repository in your project. If you want to generate SSH key for GitHub check the &lt;a href="https://dev.to/aanis434/how-to-set-up-ssh-keys-for-github-on-ubuntu-ec2-instance-d2p"&gt;link&lt;/a&gt;.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~ cd project_directory #go to your project directory

~ git init

~ git remote add origin repository_path #add your repo path

~ git pull origin main 

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;em&gt;&lt;strong&gt;Finally, you are ready to build the project and run it with proxy server.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For development mode with next.js application
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
~ pm2 start npm --name "project_name" -- run dev 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;For production mode [React / Next.js] - Start or Run node server with pm2
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
~ npm run build

~ pm2 start npm --name "project_name" -- start 

~ pm2 start npm --name "project_name" -- start -- --port=3001 #Start project with specific port if needed

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;See logs at
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~ nano /.pm2/logs/XXX-err.log 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;For watching file changes, add below flag with start command
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;--watch Synchronous 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Save the proxy server
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
~ pm2 save ***

~ pm2 startup
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;em&gt;&lt;strong&gt;At the end, to deploy the application, you need to configure the Apache server.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Apache Server Configuration
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;First enable the Proxy Server
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~ sudo a2enmod proxy

~ sudo a2enmod proxy_http
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Restart the Apache server
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~ sudo service apache2 restart
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Error log command
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~ tail -10 /var/log/apache2/error.log
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Make .conf file and configure with your domain on /etc/apache2/sites-available/
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~ sudo nano example.conf

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Paste the following configurations and update with your own way.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;VirtualHost *:80&amp;gt;
    ServerName domain.com
    ServerAlias www.domain.com
    ProxyRequests Off
    ProxyPreserveHost On
    ProxyVia Full
    &amp;lt;Proxy *&amp;gt;
        Require all granted
    &amp;lt;/Proxy&amp;gt;
    ProxyPass / http://127.0.0.1:3000/
    ProxyPassReverse / http://127.0.0.1:3000/ 
&amp;lt;/VirtualHost&amp;gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Enable the newly created .conf file and disable the default one.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~ sudo a2ensite example.conf

~ Sudo a2dissite default.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Restart the server
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;~ sudo service apache2 restart
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;em&gt;Done! Now you can browse your application with the domain name.&lt;/em&gt;&lt;/p&gt;




</description>
    </item>
  </channel>
</rss>
