<?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 Farhaz Alam on Medium]]></title>
        <description><![CDATA[Stories by Farhaz Alam on Medium]]></description>
        <link>https://medium.com/@farhazalam?source=rss-e15d00ddd51------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*qZ0dUREebKbug_q8yQ5c4Q.jpeg</url>
            <title>Stories by Farhaz Alam on Medium</title>
            <link>https://medium.com/@farhazalam?source=rss-e15d00ddd51------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 19:06:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@farhazalam/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[Deploy Nest JS App With Postgres in VPS]]></title>
            <link>https://medium.com/swlh/deploy-nest-js-app-with-postgres-in-vps-e1ce4abd2cad?source=rss-e15d00ddd51------2</link>
            <guid isPermaLink="false">https://medium.com/p/e1ce4abd2cad</guid>
            <category><![CDATA[node]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[vps]]></category>
            <category><![CDATA[nestjs]]></category>
            <category><![CDATA[postgres]]></category>
            <dc:creator><![CDATA[Farhaz Alam]]></dc:creator>
            <pubDate>Mon, 09 Nov 2020 10:44:07 GMT</pubDate>
            <atom:updated>2020-11-28T05:37:24.776Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, will show you how to deploy a REST API made using Nest JS along with Postgres in Ubuntu 20.04 LTS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PHzLqUBknTAZk2bb1KrTpA.jpeg" /></figure><h3><strong>STEP 1 (SETUP POSTGRES)</strong></h3><p>Install Postgres by typing in the terminal:</p><pre>$ sudo apt-get update<br>$ sudo apt-get install postgresql postgresql-contrib</pre><p>Now that Postgres is installed in your system, you can switch to Postgres user by:</p><pre>$ su - postgres</pre><p>Now logged in as Postgres user, you can easily switch to the Postgres shell by typing</p><pre>$ psql</pre><p>You will see something like this:</p><pre>root@testapi:~# su — postgres</pre><pre>postgres@testapi:~# psql</pre><pre>..</pre><pre>postgres=#</pre><p><strong>CREATE USER</strong></p><p>Exit from the Postgres shell by typing <strong>‘ \q ’. </strong>Don&#39;t change the user now. Now when logged in as Postgres user, type the below command to create a new user.</p><pre>$ createuser --interactive --pwprompt</pre><p>It will ask you for the name and password for the new user that you want to set. Then ask if you want to give Superuser Privileges to the user or not. It will look something like this.</p><pre>postgres@testapi:~$ createuser --interactive --pwprompt<br>Enter name of role to add: admin<br>Enter password for new role:<br>Enter it again:<br>Shall the new role be a superuser? (y/n) y</pre><p>Now let us create a database and assign the user to it by typing:</p><pre>$ createdb -O admin jugaad</pre><p>Here the name of the Database is jugaad and the user assigned to it is admin.</p><p><strong>Accessing Postgres Outside VPS (OPTIONAL)</strong></p><p>Now if you want to access your database from outside the VPS Server using PG Admin or any other tool, you can follow the below steps:</p><pre>$ nano /etc/postgresql/12/main/postgresql.conf</pre><p>In the above file, search for <strong><em>listen_addresses = ‘localhost’</em></strong><em>, </em>uncomment it and change it to <strong><em>listen_addresses = ‘*’ </em></strong>then save and exit it. The output will look like:</p><pre>...<br>listen_addresses = &#39;*&#39;          # what IP address(es) to listen on;<br>...</pre><p>Now again, open the below config file by typing:</p><pre>$ nano /etc/postgresql/12/main/pg_hba.conf</pre><p>Again run the above command and search for <strong>‘<em>IPv4 local connections’ </em></strong>section and change the IP-address from 127.0.0.1/32 to 0.0.0.0/0</p><p>The final output will look like this:</p><pre>...<br># IPv4 local connections:<br>host    all             all             0.0.0.0/0            md5<br>...</pre><p>Now after all that is complete, Exit from the Postgres user by typing <strong><em>‘exit’.</em></strong></p><p>Now allow the incoming connection on port 5432(Default Port of Postgres) then restart the Postgres Service.</p><pre>$ sudo ufw allow 5432/tcp<br>$ sudo systemctl restart postgresql</pre><p>After completing all the steps, you will be able to access your database outside the Server via PG Admin or any other tools that you need.</p><h3>STEP 2(SETUP NODE)</h3><p>Now the database configuration is done, all we have to do now is set up the Node JS. The below commands will install node, npm, pm2 and Nest JS(Obviously):</p><blockquote>Remember to exit from the Postgres user(if you haven&#39;t) by typing exit.</blockquote><pre>$ curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -<br>$ sudo apt-get install -y nodejs<br>$ sudo npm install pm2@latest -g<br>$ sudo npm i -g @nestjs/cli</pre><p>Now I already have a Nest JS app that uses Postgres Database in my repo to use for this tutorial, you can obviously use your own as the procedure will be the same.</p><p>Assuming you cloned or copied your Folder in the home, navigate to the folder and create a .env file in the root of the folder for storing all the database credentials(assuming you don&#39;t want to compromise on it).</p><p>The .env file will store the credentials that will be used by the Nest JS when establishing a database connection.</p><p>For reference the contents of the .env file will look like this where the host refers to the localhost and the rest is self-explanatory:</p><pre>DB_HOST=127.0.0.1<br>DB_PORT=5432<br>DB_USERNAME=admin<br>DB_PASSWORD=admin<br>DB_NAME=jugaad</pre><p>Now install the project dependencies and build the nest js app by typing:</p><pre>$ npm i<br>$ nest build</pre><p><strong>PM2 SETUP</strong></p><p>Now all that we have to do is use the PM2 to run our Nest JS App:</p><pre>$ pm2 start dist/main.js --name jugaadapi</pre><p>The above command executes the app and the name of the process will be jugaadapi. You can see the log by using <strong><em>pm2 log</em>.</strong></p><p>If you didn&#39;t get any errors, then you are good to go.</p><p>Now make sure pm2 restarts after system restart by:</p><pre>$ pm2 startup systemd<br>$ pm2 save</pre><p>If you followed all the above steps correctly then your Nest JS app is running in the server. But wait, it&#39;s not a very realistic approach to access your API using IP addresses. So the only thing left is to Setup a domain or a Subdomain and connect to your API.</p><h3>STEP 3(SETUP DOMAIN/SUBDOMAIN)</h3><p>Install Nginx and configure firewall settings with the below command:</p><pre>$ sudo apt-get install nginx<br>$ sudo ufw allow &#39;Nginx Full&#39;<br>$ sudo ufw allow ssh<br>$ sudo ufw enable</pre><blockquote>Note: Point the IP of the server to <strong>‘A’ </strong>record of your Domain Provider DNS Settings. In my case it will be the middle one from the below image</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/1*8C-1ys4FFzl_RXbreXTStA.png" /></figure><p>Now that Nginx is installed, let&#39;s make a server block to access our API:</p><pre>$ sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/api.jugaadapp.me<br>$ sudo nano /etc/nginx/sites-available/api.jugaadapp.me</pre><p>I will be using <em>api.jugaadapp.me</em> to access my API. Remember, you must own the domain in order to access it, or else it won&#39;t work.</p><p>Now in the editor, remove the <em>default_server </em>word in the server block, but the server name that you are going to access the URL in the server_name portion and lastly make some changes in the location block inside the server as below, the final File will look something like this.</p><pre>server {<br>        listen 80;<br>        listen [::]:80;<br><br>        root /var/www/html;<br>        index index.html index.htm index.nginx-debian.html;<br><br>        server_name api.jugaadapp.me;<br><br>        location / {<br>               proxy_pass http://localhost:3000;<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>               # try_files $uri $uri/ =404;<br>        }<br>}</pre><p>Now that your server block is ready, we will need to enable the block by typing:</p><pre>$ sudo ln -s /etc/nginx/sites-available/api.jugaadapp.me /etc/nginx/sites-enabled/</pre><p><strong>Additional Step</strong></p><pre>$ sudo nano /etc/nginx/nginx.conf</pre><p>Go to the above file and uncomment the Line server_names_hash_bucket_size 64;</p><p>Check for any syntax errors in the Nginx then restart the server:</p><pre>$ sudo nginx -t<br>$ sudo systemctl restart nginx</pre><p>Your NEST JS with Postgres Database is now successfully deployed in the desired URL in Ubuntu.</p><p>ENJOY!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e1ce4abd2cad" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/deploy-nest-js-app-with-postgres-in-vps-e1ce4abd2cad">Deploy Nest JS App With Postgres in VPS</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Run a Node JS app in VPS]]></title>
            <link>https://farhazalam.medium.com/run-a-node-js-app-in-vps-f1b1dd9a35dd?source=rss-e15d00ddd51------2</link>
            <guid isPermaLink="false">https://medium.com/p/f1b1dd9a35dd</guid>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[npm]]></category>
            <category><![CDATA[vps]]></category>
            <category><![CDATA[servers]]></category>
            <category><![CDATA[node]]></category>
            <dc:creator><![CDATA[Farhaz Alam]]></dc:creator>
            <pubDate>Tue, 13 Oct 2020 06:26:08 GMT</pubDate>
            <atom:updated>2020-10-13T06:26:08.992Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OYwJoSGNcCqClf0enL0m3g.png" /><figcaption>Image from <a href="https://www.codementor.io/">https://www.codementor.io/</a></figcaption></figure><p>In this article, I will be discussing how we can run a Node Js app inside a VPS so that we can access it from anywhere.</p><p>I have a basic VPS with Ubuntu and a subdomain setup where I will be setting up my node application. If you don&#39;t know how to set up a subdomain, you can check my previous article. First of all login into your VPS by using putty or Powershell by using the command ssh username@host.</p><h3>Step 1- Installing Node</h3><p>Install Node JS and NPM by using the command:</p><pre>$ curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -<br>$ sudo apt-get install -y nodejs</pre><p>You can always verify the installation by checking their version numbers:</p><pre>$ node -v<br>$ npm -v</pre><h3>Step 2- Setting up PM2</h3><p>Now our Node js is installed, now all you have to do is to take any sample code that you want to run and navigate to that folder. My Node app is configured to run at port 2121. Run the app to check if it is running.</p><p>Install the PM2 package using the command:</p><pre>$ sudo npm install pm2@latest -g</pre><p>Now we will run our Node App using the PM2 command, make sure you are inside your Node project Folder:</p><pre>$ pm2 start index.js</pre><p>After this, you could see something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/719/1*iYX9dsl0U9iHtYlit66rCw.png" /></figure><p>Now that our app is running by PM2, we will make sure that the app runs even after a server restart, we can do so by:</p><pre>$ pm2 startup systemd</pre><p>The above command’s output will generate another command to be run, it will look something like this:</p><pre>sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u farhazalam --hp /home/farhazalam</pre><p>Just run that command by copying and pasting in your own terminal.</p><p>Save the process by using the command:</p><pre>$ pm2 save</pre><blockquote>Now take a break and restart your VPS.</blockquote><p>After your machine has successfully restarted, ssh into it and start the service with systemctl:</p><pre>$ sudo systemctl start pm2-farhazalam</pre><blockquote>Dont forget to use your username instead of farhazalam.</blockquote><p>Now, you can check the status by typing:</p><pre>$ systemctl status pm2-farhazalam</pre><p>Stop, start, restart, or check your pm2 instance by running:</p><pre>$ pm2 stop <em>name_of_process<br></em>$ pm2 start <em>name_of_process<br></em>$ pm2 restart <em>name_of_process<br>$ pm2 status</em></pre><h3>Step 3- Set up Nginx Server Block</h3><p>Open the server block in which you want to configure your node app, I will be using my subdomain for this. You can also use the default server block to set up. Open the server block by typing:</p><pre>$ sudo nano /etc/nginx/sites-available/api.jugaadapp.me</pre><p>Search for the location block inside the server block and paste the following lines.</p><blockquote>Note: Don’t forget to change the localhost port to the port which you have set for your node js app.</blockquote><blockquote>Note: Comment the line try_files $uri $uri/ =404; by adding a # before it.</blockquote><p>The final block will look something like this:</p><pre>server {<br>...<br>    location / {<br>        proxy_pass http://localhost:2121;<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>        # try_files $uri $uri/ =404;</pre><pre>    }<br>...<br>}</pre><blockquote><strong>Optional</strong></blockquote><blockquote>You can also add another location block if you want to run some other node js with different ports but on the same domain. you can do it by adding like this:</blockquote><pre>server {<br>...<br>    location /api2 {<br>        proxy_pass http://localhost:3131;<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>    }<br>...<br>}</pre><blockquote>You can access the second location by www.domain.com/api2.</blockquote><p><strong>Now </strong>all that is left is to check for syntax errors and then restart your Nginx server:</p><pre>$ sudo nginx -t<br>$ sudo systemctl restart nginx</pre><p>Voila, you have now your node js app running in your server which can be accessed from anywhere.</p><p>ENJOY!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f1b1dd9a35dd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Add an SSL Certificate to any VPS.]]></title>
            <link>https://farhazalam.medium.com/add-an-ssl-certificate-to-any-vps-12b72f498869?source=rss-e15d00ddd51------2</link>
            <guid isPermaLink="false">https://medium.com/p/12b72f498869</guid>
            <category><![CDATA[vps]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[secure]]></category>
            <category><![CDATA[ssl]]></category>
            <category><![CDATA[azure]]></category>
            <dc:creator><![CDATA[Farhaz Alam]]></dc:creator>
            <pubDate>Wed, 07 Oct 2020 06:58:08 GMT</pubDate>
            <atom:updated>2021-08-04T13:02:28.638Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*NrqUu0KUcgAnwE0ZYt8gfA.jpeg" /><figcaption>Image from <a href="http://www.zepo.in/">www.zepo.in</a></figcaption></figure><p>This article will show how you can add an SSL certificate to your Domains in VPS.</p><p>If you followed my last story, I have shown how you can add multiple domains/subdomains to your VPS. I strongly recommend checking it out as I will continue that story to add certificates to the domain.</p><p>So as for now, you have already added domains/subdomains to your VPS by pointing ‘A’ record to your IP Address to the Domain Provider. Let’s continue adding SSL to the Domains.</p><p>In this tutorial, I have 2 websites, jugaadapp.me and api.jugaadapp.me .</p><h3>Step 1- Installing Certbot</h3><p>Add the Certbot repository so that we can install it.</p><pre>$ sudo add-apt-repository ppa:certbot/certbot</pre><p>Install the Certbot package</p><pre>$ sudo apt install python3-certbot-nginx</pre><h3>Step 2- Configuration</h3><p>As in the previous post, we have already set up the Server blocks to the respective domain. I have 2 server blocks that direct to my domain.</p><p>I can check my server block by typing:</p><pre>$ sudo nano /etc/nginx/sites-available/jugaadapp.me</pre><p>There you can find the server names that you have used. Remember the names and exit from the file.</p><p>If you have made any changes to the configuration file, you can use the below commands to check the syntax and restart the server.</p><pre>$ sudo nginx -t<br>$ sudo systemctl reload nginx</pre><p>Now, I assume you have already configured the Firewall as suggested in my previous article, you can check it by typing:</p><pre>$ sudo ufw status</pre><h3>Step 3- Getting SSL Certificate</h3><p>Now run the below command to run the Certbot, and it will automatically configure your domains to obtain an SSL certificate. Just put all the domains that you have configured inside the server block.</p><pre>$ sudo certbot --nginx -d jugaadapp.me -d www.jugaadapp.me -d api.jugaadapp.me</pre><p>It might ask you for your Email Address, give the required field, and you are good to go.</p><p>After accepting the terms and conditions, it will ask you if you want to redirect all your HTTP traffic to HTTPS, select the option you want, and be greeted with congratulation.</p><p><strong>BONUS</strong></p><p>Now the only thing left is to test the renewal process as these scripts only last for 90 days. But thankfully, the Certbot take care of all the things. Run the below command to test your renewal process:</p><pre>$ sudo certbot renew --dry-run</pre><p>If ever Certbot fails to renew, you will receive an email from Let’s Encrypt informing you about it.</p><p>Voila, your websites are now secured with SSL certificates—no more warning from Google Chrome.</p><p>ENJOY!!😀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=12b72f498869" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Install WordPress in any VPS]]></title>
            <link>https://farhazalam.medium.com/install-wordpress-in-any-vps-675dcd5ac730?source=rss-e15d00ddd51------2</link>
            <guid isPermaLink="false">https://medium.com/p/675dcd5ac730</guid>
            <category><![CDATA[vps]]></category>
            <category><![CDATA[wordpress]]></category>
            <category><![CDATA[ssl]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Farhaz Alam]]></dc:creator>
            <pubDate>Sun, 27 Sep 2020 05:46:13 GMT</pubDate>
            <atom:updated>2020-09-27T05:46:13.872Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, I will be showing you how you can install WordPress in any VPS using LEMP(Linux, Nginx, MySQL, PHP) stack.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y3jpHRQKUp5feCaWD1FFAw.jpeg" /><figcaption>Image from <a href="https://makeawebsitehub.com/">https://makeawebsitehub.com/</a></figcaption></figure><h3>Step 1(Install a LEMP Stack)</h3><p><strong>Install Nginx Server</strong></p><pre>$ sudo apt-get update<br>$ sudo apt-get install nginx</pre><p>The above 2 commands will install the Nginx server to your VPS. To configure it more, you can check out my 1st article which shows how to configure Nginx and add multiple domains.</p><p><strong>Installing MySQL</strong></p><p>Use the below commands to install the MySQL server and configure it:</p><pre>$ sudo apt-get install mysql-server<br>$ sudo mysql_secure_installation</pre><p>After running the second command, you will be asked to validate the password plugin, in this case, I will be choosing ‘No’.</p><p>Next, you will be asked to choose a password, set a password of your choice. After that, you press ‘y’ or ‘Y’ for every prompt till the setup is complete.</p><p><strong>Installing PHP and configuring Nginx</strong></p><p>Use the below command to install the required components:</p><pre>$ sudo apt install php-fpm php-mysql<br>$ sudo apt install php-curl php-gd php-intl php-mbstring php-soap php-xml php-xmlrpc php-zip</pre><blockquote><strong>Optional</strong></blockquote><blockquote>If there is any kind of problem executing the above command, simply install the repository by typing:</blockquote><pre>$ sudo add-apt-repository universe</pre><p>Now, your basic LEMP Stack is set up, all that is left to configure the server blocks of your Nginx Server.</p><p>I will be using my previously created custom Domain server block, if you have not created any server block, you can use the default one just by removing jugaadapp.me to default in the following command.</p><pre>$ sudo nano /etc/nginx/sites-available/jugaadapp.me</pre><p>After the file opens up, make some changes to it, and the final file will look something like this:</p><pre>server {<br>       - - -<br>        index index.php index.html index.htm index.nginx-debian.html;<br>        server_name jugaadapp.me www.jugaadapp.me;<br><br>        location / {<br>                try_files $uri $uri/ =404;<br>        }<br><br>        location ~ \.php$ {<br>                include snippets/fastcgi-php.conf;<br>                fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;<br>        }<br><br>        location ~ /\.ht {<br>                deny all;<br>        }<br>}</pre><p>Now test and reload the server by running the commands:</p><pre>$ sudo nginx -t<br>$ sudo systemctl restart nginx</pre><p><strong>Creating sample PHP to test</strong></p><p>Create a file in your domain directory by:</p><pre>$ sudo nano /var/www/jugaadapp.me/html/info.php</pre><p>After the file opens, add the following lines and save it.</p><pre>&lt;?php<br>phpinfo();</pre><p>Now access your domain by typing jugaadapp.me/info.php</p><blockquote><strong>IMPORTANT NOTE</strong></blockquote><blockquote>If the above URL shows gateway error 502, then there might be some permission issue. You can easy fix that by using the command:</blockquote><pre>$ sudo nano /etc/php/7.2/fpm/pool.d/www.conf</pre><p>and uncomment the lines</p><pre>listen.owner = www-data<br>listen.group = www-data<br>listen.mode = 0660</pre><p>You can always check your error log by typing</p><pre>$ sudo nano /var/log/nginx/error.log</pre><p>Save that file and exit. All that is left to restart fpm and Nginx server by typing:</p><pre>$ sudo systemctl restart nginx<br>$ sudo systemctl restart php7.2-fpm</pre><p>Your LEMP stack is Successfully Installed.</p><h3>Step 2- (Create Database)</h3><p>Enter the following command to access MySQL:</p><pre>$ sudo mysql</pre><p>Create a database with the name of your choice which is going to be used by your WordPress website.</p><pre>mysql&gt; CREATE DATABASE jugaadwordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;</pre><p>Now, we will create a new SQL user account which will exclusively access this database and set a password.</p><pre>mysql&gt; GRANT ALL ON jugaadwordpress.* TO &#39;jugaaduser&#39;@&#39;localhost&#39; IDENTIFIED BY &#39;password&#39;;</pre><p>All that is left is to flush the privileges and exit:</p><pre>mysql&gt; FLUSH PRIVILEGES;<br>mysql&gt; EXIT;</pre><h3>Step 3- (Configure Server Block)</h3><p>Open your domain server block, in my case it is:</p><pre>$ sudo nano /etc/nginx/sites-available/jugaadapp.me</pre><p>Add the following lines inside the server block which will mark them as cacheable as they are resource-heavy. Also, make changes to the location block which handover the controls to index.php. The final file will look something like this:</p><pre>server {<br>    . . .<br><br>    location = /favicon.ico { log_not_found off; access_log off; }<br>    location = /robots.txt { log_not_found off; access_log off; allow all; }<br>    location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {<br>        expires max;<br>        log_not_found off;<br>    }<br>    location / {<br>        #try_files $uri $uri/ =404;<br>        try_files $uri $uri/ /index.php$is_args$args;<br>    }</pre><pre>    . . .<br>}</pre><p>Save the files and exit, don&#39;t forget to check for syntax errors and then restart the server.</p><pre>$ sudo nginx -t<br>$ sudo systemctl reload nginx</pre><blockquote><strong>Optional</strong></blockquote><blockquote>If you get any syntax errors after running the above commands, you can simply comment these lines from the server block of the config file you just opened:</blockquote><pre># location = /favicon.ico { log_not_found off; access_log off; }<br># location = /robots.txt { log_not_found off; access_log off; allow all; }</pre><h3>Step 4- (Setting up WordPress)</h3><p>Change your directory into a writable directory and download WordPress and then extract it.</p><pre>$ cd /tmp<br>$ curl -LO https://wordpress.org/latest.tar.gz<br>$ tar xzvf latest.tar.gz</pre><p>Copy the sample config file provided by WordPress to the actual config file by :</p><pre>$ cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php</pre><p>Now copy all the contents of the WordPress folder to the Domain root that we want to use, in my case it is jugaadapp.me and assign ownership.</p><pre>$ sudo cp -a /tmp/wordpress/. /var/www/jugaadapp.me/html<br>$ sudo chown -R www-data:www-data /var/www/jugaadapp.me/html</pre><p><strong>WordPress Configuration</strong></p><p>Grab secure values for your WordPress website by typing:</p><pre>$ curl -s https://api.wordpress.org/secret-key/1.1/salt/</pre><p>Copy the output as we will need it then open WordPress Config File:</p><pre>$ sudo nano /var/www/jugaadapp.me/html/wp-config.php</pre><p>Find the section which looks something like this:</p><pre>. . .<br><br>define(&#39;AUTH_KEY&#39;,         &#39;put your unique phrase here&#39;);<br>define(&#39;SECURE_AUTH_KEY&#39;,  &#39;put your unique phrase here&#39;);<br>define(&#39;LOGGED_IN_KEY&#39;,    &#39;put your unique phrase here&#39;);<br>define(&#39;NONCE_KEY&#39;,        &#39;put your unique phrase here&#39;);<br>define(&#39;AUTH_SALT&#39;,        &#39;put your unique phrase here&#39;);<br>define(&#39;SECURE_AUTH_SALT&#39;, &#39;put your unique phrase here&#39;);<br>define(&#39;LOGGED_IN_SALT&#39;,   &#39;put your unique phrase here&#39;);<br>define(&#39;NONCE_SALT&#39;,       &#39;put your unique phrase here&#39;);<br><br>. . .</pre><p>Replace those with the values that you have copied.</p><p>Now in that same config file, find another section that looks something like this:</p><pre>. . .<br><br>define(&#39;DB_NAME&#39;, &#39;jugaadwordpress&#39;);<br><br>/** MySQL database username */<br>define(&#39;DB_USER&#39;, &#39;jugaaduser&#39;);<br><br>/** MySQL database password */<br>define(&#39;DB_PASSWORD&#39;, &#39;password&#39;);<br><br>. . .<br><br>define(&#39;FS_METHOD&#39;, &#39;direct&#39;);</pre><p>and change the database name, username, and password to that we have set earlier and also add the last line define(&#39;FS_METHOD&#39;,&#39;direct&#39;); if it is not present.</p><p>Save the file and exit.</p><p>Now open your website URL in the web browser and you could now see the WordPress installation page shows up. Just follow the steps and you will have your WordPress website ready to go.</p><p>The WordPress Installation page will look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HW5pGhzTCvjRS2mp19ICkA.png" /></figure><h3>BONUS</h3><p>If you want some of your folder to be able to access publicly, Place your folder to the root of your Domain Directory. When you try to access it, it will say 403 Forbidden. Dont worry, open your server block config file by typing:</p><pre>$ sudo nano /etc/nginx/sites-available/jugaadapp.me</pre><p>Here I want to add a folder named TestItems. Simply type this inside the server block:</p><pre>server {<br>    . . .<br><br>    location /TestItems {<br>        autoindex on;<br>    }</pre><pre>. . .<br>}</pre><p>Save the file and restart the server by typing:</p><pre>$ sudo systemctl reload nginx</pre><p>Now you can access your folder publicly via a web browser.</p><p>ENJOY!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=675dcd5ac730" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setup Domains/Subdomains on VPS in Ubuntu]]></title>
            <link>https://farhazalam.medium.com/setup-domains-subdomains-on-vps-in-ubuntu-36495b37da66?source=rss-e15d00ddd51------2</link>
            <guid isPermaLink="false">https://medium.com/p/36495b37da66</guid>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[domains]]></category>
            <category><![CDATA[vps]]></category>
            <dc:creator><![CDATA[Farhaz Alam]]></dc:creator>
            <pubDate>Tue, 15 Sep 2020 15:21:52 GMT</pubDate>
            <atom:updated>2020-09-15T15:21:52.690Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*7mHC1SWe_DtIU3GU0ixVtA.jpeg" /><figcaption>Image from depositphotos.com</figcaption></figure><p>So in this article, I will be discussing how to set up Nginx Server with multiple Domains or Subdomains.</p><h3><strong>Prerequisites</strong></h3><ul><li>Setup a VPS of your requirements. In this tutorial, I will be using Azure to set up a VPS with 1GB RAM, 1vcpu, and Ubuntu 18.04.</li><li>Connect to your newly created server using an ssh client like <a href="https://www.putty.org/"><strong>Putty</strong></a>.</li><li>Must have a Domain and have access to it. I will be using Namecheap for the Domain.</li></ul><p>Okay, so now all the things are setup. We will start with the Actual Process.</p><h3>Step 1- Connect your VPS with Domain</h3><p>Connect your domain with the server so that you don&#39;t have to access your server by typing IP Addresses.</p><p>First of all, find your public IP Address from the VPS dashboard that your provider has given you. Then head over to the Domain Dashboard settings( In my case, it is <a href="https://www.namecheap.com/"><strong>Namecheap</strong></a>). In your domain settings, head over to the DNS section and point an ‘A’ record to your public IP Address. It would look something like this below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IT9TfR7i2pXpoh-lnlIqqQ.png" /><figcaption>NameCheap Advanced DNS Options</figcaption></figure><p>I have added 3 DNS, the host @ and www denotes the default domain, and the host ‘API’ denotes the subdomain that I will be using in this tutorial.</p><p>So the two domains that I will be using here as a demonstration is</p><ul><li>jugaadapp.me</li><li>API.jugaadapp.me</li></ul><p>After this step, your domain and subdomain are pointed to your server’s IP Address.</p><h3>Step 2- Set up Nginx Server</h3><p>So, after all the setup is over, I will be connecting to my server using the Public IP or my domain name along with my username and password in any ssh client.</p><p>Now Comes the Interesting part</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgfycat.com%2Fifr%2Funpleasantsillycarpenterant&amp;display_name=Gfycat&amp;url=https%3A%2F%2Fgfycat.com%2Funpleasantsillycarpenterant-eurotrip-good&amp;image=https%3A%2F%2Fthumbs.gfycat.com%2FUnpleasantSillyCarpenterant-size_restricted.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=gfycat" width="960" height="720" frameborder="0" scrolling="no"><a href="https://medium.com/media/bc0bb2eeacb1e931e9efbb66cbf5c6c0/href">https://medium.com/media/bc0bb2eeacb1e931e9efbb66cbf5c6c0/href</a></iframe><p><strong>Installing Nginx</strong></p><pre>$ sudo apt-get update<br>$ sudo apt-get install nginx</pre><p>Now your Nginx server is basically installed, You can check it at by typing your default domain in your web browser address bar. I will show you that Nginx Server is successfully installed. Now we just need to adjust some firewall settings.</p><p><strong>Adjusting More Settings</strong></p><pre>$ sudo ufw app list</pre><pre><em>Output<br></em>Available applications:<br>  Nginx Full<br>  Nginx HTTP<br>  Nginx HTTPS<br>  OpenSSH</pre><p>The above command shows us different firewall options available. After that just follow the commands below</p><pre>$ sudo ufw allow &#39;Nginx Full&#39;<br>$ sudo ufw allow ssh<br>$ sudo ufw enable </pre><p>If everything goes well, You could type <em>‘sudo ufw status’ </em>and see the status of your settings.</p><p><strong>More Web Server Settings</strong></p><p>Now that the server is installed, you can now check the status of your server by typing the code below.</p><pre>$ systemctl status nginx</pre><p>To stop, start or restart your server, you can use the below commands respectively</p><pre>$ sudo systemctl stop nginx<br>$ sudo systemctl start nginx<br>$ sudo systemctl restart nginx</pre><h3>Step 3- Create Domain Directory</h3><p>Now that our server is installed, we can now create our directory for our domain routes.</p><pre>$ sudo mkdir -p /var/www/jugaadapp.me/html<br>$ sudo mkdir -p /var/www/api.jugaadapp.me/html</pre><p>Now assign Ownership to the directory we just made to the current logged in user.</p><pre>$ sudo chown -R $USER:$USER /var/www/jugaadapp.me/html<br>$ sudo chown -R $USER:$USER /var/www/api.jugaadapp.me/html</pre><p>Now we will give permission to the web roots by:</p><pre>$ sudo chmod -R 755 /var/www</pre><h3>Step 4- Creating a Sample Webpage</h3><p>We have successfully created the directory for our domain routes. Now let us just make a sample page for each website so that we will have something to display.</p><pre>$ nano /var/www/jugaadapp.me/html/index.html</pre><p>After the above command, an editor will open up. We will write a simple HTML code.</p><pre>&lt;html&gt;<br> &lt;body&gt;<br>  This is Domain 1<br> &lt;/body&gt;<br>&lt;/html&gt;</pre><blockquote>To save this file, press (CTRL + O) and it will prompt a confirmation, Just press enter</blockquote><blockquote>To exit, press (CTRL + X).</blockquote><p>Now your HTML code is written in Domain 1(jugaadapp.me) Directory. We will perform the same steps to change our Domain 2(api.jugaadapp.me).</p><pre>$ nano /var/www/api.jugaadapp.me/html/index.html</pre><p>Then write the same HTML code we used earlier and save it.</p><pre>&lt;html&gt;<br> &lt;body&gt;<br>  This is Domain 2<br> &lt;/body&gt;<br>&lt;/html&gt;</pre><h3>Step 5- Configure Server Block</h3><p>Till now, we have created the directory and the HTML files for both the directory to show. But now we will have to create and configure the server block files for each Domain.</p><p>The default server block is called ‘default’. We will use that server block file to copy and rename and make some changes to make the block for our domain</p><p><strong>Server Block for Domain 1(jugaadapp.me)</strong></p><pre>$ sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/jugaadapp.me</pre><pre>$ sudo nano /etc/nginx/sites-available/jugaadapp.me</pre><p>Now our server block file for Domain 1(jugaadapp.me) is opened. If we ignore the comments, the file will look similar to this:</p><pre>server {<br>        listen 80 default_server;<br>        listen [::]:80 default_server;<br><br>        root /var/www/html;<br>        index index.html index.htm index.nginx-debian.html;<br><br>        server_name _;<br><br>        location / {<br>                try_files $uri $uri/ =404;<br>        }<br>}</pre><blockquote>First of all, we will remove the default_server word from the first two lines as there can be only one default_server and that is present is the default server block.</blockquote><blockquote>Secondly, we will change the root location /var/www/html to our custom made domain directory /var/www/jugaadapp.me/html.</blockquote><blockquote>Third, we will put a server name that is similar to our domain that we are going to use, it will look something like this server_name jugaadapp.me www.jugaadapp.me;</blockquote><p>The final file will look something like this:</p><pre>server {<br>        listen 80;<br>        listen [::]:80;<br><br>        root /var/www/jugaadapp.me/html;<br>        index index.html index.htm index.nginx-debian.html;<br><br>        server_name jugaadapp.me www.jugaadapp.me;<br><br>        location / {<br>                try_files $uri $uri/ =404;<br>        }<br>}</pre><p><strong>Server Block for Domain 2(api.jugaadapp.me)</strong></p><p>Now our domain 1 configuration is done, we will copy that and make some changes to match the second Domain.</p><pre>$ sudo cp /etc/nginx/sites-available/jugaadapp.me /etc/nginx/sites-available/api.jugaadapp.me</pre><pre>$ sudo nano /etc/nginx/sites-available/api.jugaadapp.me</pre><p>Again repeat the previous steps and change the root and the server_name relevant to this Domain. The final file will look something like this.</p><pre>server {<br>        listen 80;<br>        listen [::]:80;<br><br>        root /var/www/api.jugaadapp.me/html;<br>        index index.html index.htm index.nginx-debian.html;<br><br>        server_name api.jugaadapp.me www.api.jugaadapp.me;<br><br>        location / {<br>                try_files $uri $uri/ =404;<br>        }<br>}</pre><h3>Step 6- Finishing Steps</h3><p>Now, all that left is to enable the server blocks that we just created and restart our server.</p><p>Enable the server blocks by typing the command below:</p><pre>$ sudo ln -s /etc/nginx/sites-available/jugaadapp.me /etc/nginx/sites-enabled/<br>$ sudo ln -s /etc/nginx/sites-available/api.jugaadapp.me /etc/nginx/sites-enabled/</pre><p>We have now in a total of 3 server blocks, the two that we created will respond to the respective domains and the remaining default block will execute when the request doesn&#39;t match from the above two.</p><p>The only step is left to add additional server names to avoid a possible hash bucket memory problem. We can do this by:</p><pre>$ sudo nano /etc/nginx/nginx.conf</pre><p>And uncomment the Line server_names_hash_bucket_size 64;</p><p>Save the file and exit from it.</p><p>Now test if there are any no errors on your Nginx server by typing the commands below:</p><pre>$ sudo nginx -t</pre><p>If you reached up to this line then you are ready to go. Now all that is left to restart your Nginx server by typing the command below:</p><pre>$ sudo systemctl restart nginx</pre><p>Your server is now ready and you can check your websites in any web browser.</p><p>ENJOY!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=36495b37da66" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>