<?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 Rabib Galib on Medium]]></title>
        <description><![CDATA[Stories by Rabib Galib on Medium]]></description>
        <link>https://medium.com/@galib-rabib?source=rss-ac13a096b42c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*lfSaVxRc2unuZLMaRMVWng.jpeg</url>
            <title>Stories by Rabib Galib on Medium</title>
            <link>https://medium.com/@galib-rabib?source=rss-ac13a096b42c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 14:24:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@galib-rabib/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[When to use HTTP PUT vs PATCH? How PUT and PATCH methods work in HTTP explained.]]></title>
            <link>https://galib-rabib.medium.com/when-to-use-http-put-vs-patch-how-put-and-patch-methods-work-in-http-explained-d5823ae5d4f0?source=rss-ac13a096b42c------2</link>
            <guid isPermaLink="false">https://medium.com/p/d5823ae5d4f0</guid>
            <category><![CDATA[rest-api]]></category>
            <category><![CDATA[http-put-vs-post]]></category>
            <category><![CDATA[http-request]]></category>
            <category><![CDATA[rest]]></category>
            <dc:creator><![CDATA[Rabib Galib]]></dc:creator>
            <pubDate>Thu, 03 Oct 2024 20:11:18 GMT</pubDate>
            <atom:updated>2024-10-03T20:15:18.658Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*i3KnvtxQfQXGb8k8g7UwLA.gif" /><figcaption>HTTP PUT vs PATCH comparison</figcaption></figure><h3><strong>𝗣𝗨𝗧 𝗠𝗲𝘁𝗵𝗼𝗱:</strong></h3><p><em>🟢 The PUT method is used to update an existing resource or create a new one if it doesn’t exist.</em></p><p><em>🔁 It’s idempotent, meaning the same request can be made multiple times with the same outcome.</em></p><p><em>📝 When using PUT, you must provide the entire resource. If any attributes are left out, they are removed or reset.</em></p><p><em>🍦 For example, using PUT to update an ice cream object means replacing everything — the scoop, cone, and toppings.</em></p><h3><strong>𝗣𝗔𝗧𝗖𝗛 𝗠𝗲𝘁𝗵𝗼𝗱:</strong></h3><p><em>🟡 The PATCH method is for making partial updates or tweaks to a resource, not replacing it entirely.</em></p><p><em>⚠️ It’s not guaranteed to be idempotent, but it can be implemented that way.</em></p><p><em>✏️ With PATCH, you only send the specific changes you want, and attributes not mentioned remain unchanged.</em></p><p><em>🍨 For example, using PATCH to update just the scoop of the ice cream keeps the cone and toppings the same.</em></p><p>Happy coding! Have fun 🔥 💪. Find me on <a href="https://github.com/RabibHossain/">Github</a>, <a href="https://www.linkedin.com/in/rabibgalib/">LinkedIn</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d5823ae5d4f0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting Up a MySQL Docker Container for Development: A Comprehensive Guide]]></title>
            <link>https://galib-rabib.medium.com/setting-up-a-mysql-docker-container-for-development-a-comprehensive-guide-52f04eb73e07?source=rss-ac13a096b42c------2</link>
            <guid isPermaLink="false">https://medium.com/p/52f04eb73e07</guid>
            <category><![CDATA[docker-container-vs-image]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[mysql]]></category>
            <dc:creator><![CDATA[Rabib Galib]]></dc:creator>
            <pubDate>Sat, 13 Apr 2024 14:50:18 GMT</pubDate>
            <atom:updated>2024-04-13T14:50:18.628Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aQMGiIcjagJ2R2_vPagNFw.png" /><figcaption>Setting Up a MySQL Docker Container for Development: A Comprehensive Guide</figcaption></figure><p><strong>Why Docker? </strong>Docker, a powerful tool for creating, deploying, and running applications by using containers, offers a solution. This article guides you through efficiently setting up a single MySQL container, importing a database schema, and establishing a secure connection using environment variables within your application.</p><blockquote><strong><em>Setting Up Your MySQL Container</em></strong></blockquote><p>Our journey begins by fetching the official MySQL image from Docker Hub.</p><pre>docker pull mysql</pre><blockquote><strong><em>Run MySQL Container</em></strong></blockquote><p>Next, we create a MySQL container with a predefined root password. For persistence beyond the lifetime of the container, we mount a volume from the host to the container’s data directory</p><pre>docker run --name mysqlContainer -e MYSQL_ROOT_PASSWORD=secretpassword -d mysql<br># Or with volume for data persistence<br>docker run --name mysqlContainer -e MYSQL_ROOT_PASSWORD=secretpassword -v /path/to/host/directory:/var/lib/mysql -d mysql</pre><ul><li><strong>docker run</strong>: This command instructs Docker to create and run a new container.</li><li><strong>— name mysqlContainer</strong>: This assigns a name (mysqlContainer) to the container for easier identification and management.</li><li><strong>-e MYSQL_ROOT_PASSWORD=secretpassword</strong>: This sets an environment variable named MYSQL_ROOT_PASSWORD within the container, defining the root password for MySQL access.</li><li><strong>-d</strong>: This flag runs the container in detached mode, allowing the container to operate in the background even after the terminal command finishes execution.</li><li><strong>mysql</strong>: This specifies the image to use for the container</li><li>The <strong>-v</strong> flag instructs Docker to mount a volume. The format is &lt;host directory&gt;:&lt;container directory&gt;, specifying the locations on both the host machine and the container.</li></ul><blockquote><strong><em>Accessing the MySQL Shell</em></strong></blockquote><p>To interact with your MySQL instance, access the shell as follow</p><pre>docker exec -it mysqlContainer mysql -u root -p</pre><ul><li><strong>docker exec</strong>: This command allows us to execute commands within a running container.</li><li><strong>-it</strong>: This flag provides an interactive shell, essentially giving us a terminal session inside the container.</li></ul><p>After entering the password, you can explore your MySQL server. Remember to <strong>exit;</strong> once done.</p><blockquote><strong><em>Importing Your Database</em></strong></blockquote><p>Often, you’ll need to import a pre-existing database. After copying your SQL dump into the container:</p><pre>docker cp /path/to/directory/dump.sql mysqlContainer:/tmp/database.sql</pre><ul><li><strong>docker cp</strong>: The Docker command used for copying files.</li><li><strong>/path/to/directory/dump.sql</strong>: The full path to the SQL file on your host machine that you want to copy.</li><li><strong>mysqlContainer</strong>: The name of the running Docker container where you want to copy the file.</li><li><strong>/tmp/database.sql</strong>: The destination path within the container where the file will be placed. In this case, it’s copied to the /tmp directory and renamed to database.sql.</li></ul><p>You can import it using as</p><pre>#Option A<br>docker exec -it mysqlContainer bash<br>mysql -u root -p&lt;secretpassword&gt; &lt; /tmp/database.sql</pre><ul><li><strong>bash</strong>: This tells docker exec to run the /bin/bash shell within the container.</li><li><strong>&lt;</strong>: This is the redirection operator. It tells the mysql command to read the SQL statements from the specified file instead of standard input.</li></ul><pre>#Option B<br>docker exec -it mysqlContainer bash<br>mysql -u root -p&lt;secretpassword&gt;<br>source /tmp/database.sql</pre><blockquote><strong><em>Find the Container’s IP Address</em></strong></blockquote><p>After populating database, the next step is to connect your application. You’ll need the container’s IP address.</p><pre>docker inspect container_id | grep IPAddress<br># Or<br>docker inspect -f &#39;{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}&#39; container_id</pre><p>With the IP address, configure your application’s database connection as follows:</p><pre>DB_CONNECTION=mysql<br>DB_HOST=CONTAINER_IP<br>DB_PORT=3306<br>DB_DATABASE=DB_NAME<br>DB_USERNAME=root<br>DB_PASSWORD=secretpassword</pre><p>Replace <strong>CONTAINER_IP</strong>, <strong>DB_NAME</strong>, and <strong>secretpassword</strong> with your container’s IP, your database name, and the root password you set earlier.</p><p>Remember, while the root account and simple passwords are convenient for development, always use more secure settings for production environments. Happy coding! Have fun 🔥 💪. Find me on <a href="https://github.com/RabibHossain/">Github</a>, <a href="https://galib-rabib.medium.com/">Medium</a>.</p><p>Have you tried using Docker for managing your MySQL databases? Share your experiences and tips in the comments below!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=52f04eb73e07" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[RESOLVED] Upload base64 data url file to AWS S3 in Laravel]]></title>
            <link>https://galib-rabib.medium.com/resolved-upload-base64-data-url-file-to-aws-s3-in-laravel-3ef87afbd551?source=rss-ac13a096b42c------2</link>
            <guid isPermaLink="false">https://medium.com/p/3ef87afbd551</guid>
            <category><![CDATA[cloud-storage]]></category>
            <category><![CDATA[base64]]></category>
            <category><![CDATA[base64-to-image]]></category>
            <category><![CDATA[aws-s3]]></category>
            <category><![CDATA[laravel]]></category>
            <dc:creator><![CDATA[Rabib Galib]]></dc:creator>
            <pubDate>Mon, 16 Oct 2023 10:16:07 GMT</pubDate>
            <atom:updated>2023-10-16T12:09:58.792Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Step 1: configure S3 Driver</blockquote><p>Install the Flysystem S3 package via the Composer package manager</p><pre>composer require league/flysystem-aws-s3-v3 &quot;^3.0&quot;</pre><blockquote>Step 2: Laravel end configuration</blockquote><p>In laravel end, there’s two options to configure credentials for S3.</p><pre>1. .env<br>2. config/filesystem.php // If we check this file, this mainly calls the .env variables.</pre><p>We’ll set values in the .env file</p><pre>AWS_ACCESS_KEY_ID=XXXXXX<br>AWS_SECRET_ACCESS_KEY=XXXXXXXX<br>AWS_DEFAULT_REGION=us-east-2<br>AWS_BUCKET=MY_AWS_BUCKET<br>AWS_USE_PATH_STYLE_ENDPOINT=false<br>AWS_URL=MY_AWS_URL</pre><p>The config/filesystem.php file be like</p><pre>return [<br>    &#39;disks&#39; =&gt; [<br>        &#39;local&#39; =&gt; [<br>          // local configuration here<br>        ],<br>       &#39;public&#39; =&gt; [<br>          // public configuration here<br>        ],<br>        &#39;s3&#39; =&gt; [<br>            &#39;driver&#39; =&gt; &#39;s3&#39;,<br>            &#39;key&#39; =&gt; env(&#39;AWS_ACCESS_KEY_ID&#39;),<br>            &#39;secret&#39; =&gt; env(&#39;AWS_SECRET_ACCESS_KEY&#39;),<br>            &#39;region&#39; =&gt; env(&#39;AWS_DEFAULT_REGION&#39;),<br>            &#39;bucket&#39; =&gt; env(&#39;AWS_BUCKET&#39;),<br>            &#39;url&#39; =&gt; env(&#39;AWS_URL&#39;),<br>            &#39;endpoint&#39; =&gt; env(&#39;AWS_ENDPOINT&#39;),<br>            &#39;use_path_style_endpoint&#39; =&gt; env(&#39;AWS_USE_PATH_STYLE_ENDPOINT&#39;, false),<br>            &#39;throw&#39; =&gt; false,<br>        ],<br>    ],<br>];</pre><blockquote>Step 3: Now put below code to your functionality</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1f248d9e08fb53ddf4f07525f3b0a1b9/href">https://medium.com/media/1f248d9e08fb53ddf4f07525f3b0a1b9/href</a></iframe><p>That’s All. Have fun 🔥 💪</p><p>If you have any query, please put in below. Find me on <a href="https://github.com/RabibHossain/">Github</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3ef87afbd551" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Customize 403 Page with Spatie Laravel-Permission?]]></title>
            <link>https://galib-rabib.medium.com/how-to-customize-403-page-with-spatie-laravel-permission-e15113bcc5cc?source=rss-ac13a096b42c------2</link>
            <guid isPermaLink="false">https://medium.com/p/e15113bcc5cc</guid>
            <category><![CDATA[403]]></category>
            <category><![CDATA[spatie]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[custom-page-template]]></category>
            <category><![CDATA[laravel-permission]]></category>
            <dc:creator><![CDATA[Rabib Galib]]></dc:creator>
            <pubDate>Sun, 19 Mar 2023 20:58:11 GMT</pubDate>
            <atom:updated>2023-03-20T11:30:07.345Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*RiCbqtCXKJUvpJ4NdKalXA.jpeg" /><figcaption>Customize a 403 page for spatie in laravel permission.</figcaption></figure><p><a href="https://spatie.be/docs/laravel-permission/v5/introduction">Spatie</a> is an open source software used in all Laravel projects. Spatie Laravel-Permission package allows to manage user permissions &amp; roles in a service. It provides multiple guards. Each guard will have its own set of permissions &amp; roles that can be assigned to the guard’s users. Spatie helps to allow users access control in services.</p><p>Basically after installing this package &amp; assigning roles with/or permissions to users, while operating any service or functionality if that part of task is not assigned to certain users then by default those users will see a laravel page view mentioning those users that they do not have any right roles/permission.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PuUpjTgbJp6sRmJANWhTJg.png" /><figcaption>User does not have any right roles on specific request.</figcaption></figure><p>Let’s presume, a functional block of controller code is defined in the route within a group where a user requires an admin role to access that service.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6a0567fc1d78cde49be83a782e3ba1a2/href">https://medium.com/media/6a0567fc1d78cde49be83a782e3ba1a2/href</a></iframe><p>If the role is not assigned to that user then <strong>domain.com/consumers/1</strong> route will render a default laravel page view by the exception handler.</p><p>Now, to customize &amp; render a new page view for unauthorized user access, we do need to do following steps.</p><blockquote><strong>Step 1 (Good to know):</strong> In laravel, if we understand the <a href="https://laravel.com/docs/9.x/lifecycle">request life cycle</a> in depth. We came to know that actually in <strong>App\Exceptions\Handler</strong> class, error and exception handling is configured. This class is accountable for all exceptions thrown by the application are logged and then rendered to the user.</blockquote><p>Here the code part 👇</p><blockquote><strong>Step 2 (Put custom code):</strong> Put below codebase in <strong>App\Exceptions\Handler</strong> class. And add <strong>use Spatie\Permission\Exceptions\UnauthorizedException;</strong> after namespace.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3f9d06fbecc2bbc53a7e3bd3818d2eb3/href">https://medium.com/media/3f9d06fbecc2bbc53a7e3bd3818d2eb3/href</a></iframe><blockquote><strong>Step 3 (Design 403 page view):</strong> Now create a file names <strong>errors/403.blade.php</strong> under resources/views. Then inside the 403.blade.php write the below code.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5747755c69439ca2ba1065dfa6f9ac7b/href">https://medium.com/media/5747755c69439ca2ba1065dfa6f9ac7b/href</a></iframe><p>Now, we are good to go with new 403 page view.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yT2ys1Yvv2cdSAk6FfpKfw.png" /><figcaption>Custom 403 page view for unauthorized user access.</figcaption></figure><p>That’s All. Have fun 🔥 💪</p><p>If you have any query, please put in below. Find me on <a href="https://github.com/RabibHossain/">Github</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e15113bcc5cc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Securing NGINX & Serving Let’s Encrypt SSL for single domain with multiple root ports on Ubuntu]]></title>
            <link>https://galib-rabib.medium.com/securing-nginx-serving-lets-encrypt-ssl-for-single-domain-with-multiple-root-ports-on-ubuntu-af501a893e64?source=rss-ac13a096b42c------2</link>
            <guid isPermaLink="false">https://medium.com/p/af501a893e64</guid>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[lets-encrypt]]></category>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[multi-port]]></category>
            <category><![CDATA[ssl-certificate]]></category>
            <dc:creator><![CDATA[Rabib Galib]]></dc:creator>
            <pubDate>Wed, 21 Oct 2020 21:29:37 GMT</pubDate>
            <atom:updated>2020-10-24T10:29:38.632Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yIDnwshUzCSeDxLACccW6g.png" /></figure><p>Peace upon you. Securing NGINX server with SSL is easy. Normally Let’s encrypt establishes a secure link between a web server(it represents the domain) &amp; a browser. And we already know that Let’s encrypt is totally free to certify your domains. If you don’t know how to certify domain with one root, <a href="https://medium.com/@galib.rabib/how-to-secure-nginx-with-lets-encryption-by-cerbot-client-on-ububtu-16-04-3da65cf8dd12">this story</a> will assist you to secure your web server.</p><p>Now come to the point. In your NGINX server you might have only one domain but you want to make multiple root folders like</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1336cabc80db465586e2ac2c0e8aa733/href">https://medium.com/media/1336cabc80db465586e2ac2c0e8aa733/href</a></iframe><p>So, you want to secure all the root folders with multiple ports like <strong>80, 8080, 8081 </strong>&amp; you have only one domain like <strong>example.com</strong></p><p>If you have not installed your LEMP stack, follow <a href="https://medium.com/@galib.rabib/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-18-04-lts-19-10-263625ac65ad">this story</a>. As we know every root folder listens to port 80, for multiple roots here we’ll use other ports too. Once LEMP is installed, we’ll configure NGINX with laravel &amp; react [ <strong>I’m showing laravel &amp; react configuration as an example </strong>].</p><p>Now run below two commands</p><pre>sudo rm -rf /etc/nginx/sites-available/default<br>sudo rm -rf /etc/nginx/sites-enabled/default</pre><p>Now deploy below command to write config file</p><pre>sudo nano /etc/nginx/sites-available/multiPorts</pre><p>Paste the below code in your configuration file</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/af5bd5d44c5a753401c6e56e695ea9e0/href">https://medium.com/media/af5bd5d44c5a753401c6e56e695ea9e0/href</a></iframe><p>Now follow below commands</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cb55e0f3a07fc1ad53d54e5f7e43f746/href">https://medium.com/media/cb55e0f3a07fc1ad53d54e5f7e43f746/href</a></iframe><p>Now here comes the Let’s Encrypt SSL (Secure Socket Layer). Read &amp; Follow <a href="https://medium.com/@galib.rabib/how-to-secure-nginx-with-lets-encryption-by-cerbot-client-on-ububtu-16-04-3da65cf8dd12">my 2 minutes certbot SSL Encryption story.</a></p><p>Once certbot SSL is done, check the configuration file</p><pre>nano cd /etc/nginx/sites-available/multiPorts</pre><p>As we are using one domain [ <strong>example.com </strong>]only, certbot will secure &amp; manage port 80 only. If you browse <a href="https://example.com:8081,">http://example.com:8081</a> or <a href="https://example.com:8082/">http://example.com:8082</a>, it will remain unsecure. To secure these ports too, we need to add some manual codes in <strong>sites-available/multiPorts </strong>file. Here, in below gist, we can see that from <strong>line 49–55</strong> &amp; <strong>72–78</strong> we added some manual code to establish the SSL link for 8081 &amp; 8082. And make sure that you’ve kept the domain name same in manual codes.</p><p>Now paste the below code in multiports in /etc/nginx/sites-available/ directory.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4f2597c7f79f547a98cb189823aa05ed/href">https://medium.com/media/4f2597c7f79f547a98cb189823aa05ed/href</a></iframe><p>After this, we need to link this with sites-enabled directory &amp; need to restart nginx again.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1dc2e5a9b450e291a36be0b61f4ce737/href">https://medium.com/media/1dc2e5a9b450e291a36be0b61f4ce737/href</a></iframe><p>It’s all done here. As I said, I’ve shared my laravel &amp; react deployment knowledge here. If you want to know how <a href="https://medium.com/@galib.rabib/how-to-install-and-configure-laravel-with-lemp-on-ubuntu-16-04-18-04-lts-19-10-20-04-lts-3e9c6f6d2e0b">Laravel </a>&amp; <a href="https://medium.com/@galib.rabib/how-to-deploy-a-react-app-using-nginx-and-ubuntu-16-04-18-04-lts-19-10-20-04-lts-5a54a21d21b0">React </a>deployment &amp; configuration works!, then follow my those stories too.</p><p>Now your domain with 8081 &amp; 8082 ports are secured too. You can browse those too [ <a href="https://example.com:8081,">https://example.com:8081</a> or <a href="https://example.com:8082/">https://example.com:8082</a> ].</p><p>Have fun 🔥 💪</p><p>If you have any query, please put in below. Find me on <a href="https://github.com/RabibHossain/">Github</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=af501a893e64" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Install and Configure Laravel with LEMP on Ubuntu 16.04 / 18.04 LTS / 19.10 / 20.04 LTS]]></title>
            <link>https://galib-rabib.medium.com/how-to-install-and-configure-laravel-with-lemp-on-ubuntu-16-04-18-04-lts-19-10-20-04-lts-3e9c6f6d2e0b?source=rss-ac13a096b42c------2</link>
            <guid isPermaLink="false">https://medium.com/p/3e9c6f6d2e0b</guid>
            <category><![CDATA[php]]></category>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[laravel]]></category>
            <dc:creator><![CDATA[Rabib Galib]]></dc:creator>
            <pubDate>Thu, 20 Aug 2020 23:27:04 GMT</pubDate>
            <atom:updated>2020-08-20T23:32:55.771Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ajYlX_x2jfCIexGO4L5hVQ.jpeg" /></figure><p><a href="https://laravel.com/"><strong>Laravel</strong></a><strong> </strong>is an open-source PHP framework that provides a set of tools and resources to build modern PHP applications. In this guide, you’ll install and configure a new Laravel application on an Ubuntu 18.04 server, using <a href="https://getcomposer.org/">Composer</a> to download and manage the framework dependencies.</p><p>In order to complete the configuration, you will first need to perform the following tasks on your Ubuntu 18.04 server.</p><p>First logged into your remote system via ssh (<strong>Secure Shell</strong>).</p><pre>ssh root@server_ip_address</pre><p>Let’s begin by updating server’s package index</p><pre>sudo apt-get update</pre><h3>Installation</h3><blockquote><strong><em>Step 1: </em>Install a LEMP (Nginx, Php &amp; MySQL) Stack</strong></blockquote><p>If you haven’t set this up yet, you can follow my story on <a href="https://medium.com/@galib.rabib/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-18-04-lts-19-10-263625ac65ad">How to install Linux Nginx, MySQL, PHP (LEMP Stack) on Ubuntu</a>. Please follow the Nginx, Php &amp; MySQL installing processes only.</p><blockquote><strong><em>Step 2: </em>Enable remote Login to MySQL Database Server</strong></blockquote><p>To complete this step, please follow my story on <a href="https://medium.com/@galib.rabib/how-to-enable-remote-login-to-mysql-database-server-in-ubuntu-debian-36d875921eb2">How to enable remote Login to MySQL Database Server in Ubuntu / Debian</a>. You really need to do this for database connection purpose 😀 You can test the remote connection using <a href="https://dev.mysql.com/downloads/workbench/"><strong>MySQL Workbench</strong></a></p><blockquote><strong><em>Step 3: </em>Install Composer</strong></blockquote><pre>sudo apt-get install composer zip unzip -y</pre><blockquote><strong><em>Step 4: </em>Install Laravel</strong></blockquote><p>Install <strong>laravel via composer</strong> command</p><pre>cd /var/www/html<br>composer create-project --prefer-dist laravel/laravel LaraApp<br>composer install</pre><p>Or, you can <strong>git clone</strong> from your repo url 😇</p><pre>cd /var/www/html<br>sudo git clone [Your repository URL] .<br>cd [Your Repository Name]<br>composer install<br>composer dump-autoload</pre><blockquote><strong><em>Step 5: </em>Configure Laravel</strong></blockquote><p>Open the .env file using your command. Here we’ll use nano command here</p><pre>nano .env</pre><p>Paste the below code in .env</p><p>If you want to generate a new secure key for APP_KEY, you can use the php artisan key:generate command.</p><pre>APP_NAME=LaraApp<br>APP_ENV=development<br>APP_KEY=APPLICATION_UNIQUE_KEY_DONT_COPY<br>APP_DEBUG=true<br>APP_URL=http://domain_or_IP<br><br>LOG_CHANNEL=stack<br><br>DB_CONNECTION=mysql<br>DB_HOST=127.0.0.1<br>DB_PORT=3306<br>DB_DATABASE=dbOne<br>DB_USERNAME=root<br>DB_PASSWORD=passcode_here<br><br>...</pre><p>Once environment is done, please run below command to migrate app Database schema</p><pre>php artisan migrate</pre><p>In a <strong>development</strong> or <strong>testing</strong> environment, you can leave the APP_DEBUG option enabled, as this will give you important debug information while testing the application from a browser. The APP_ENV variable should be set to development or testing in this case.</p><p>In a <strong>production</strong> environment, you should disable the APP_DEBUG option, because it shows to the final user sensitive information about your application. The APP_ENV in this case should be set to production.</p><p><strong>If you use ‘#’/ ‘@’ or any punctuation symbol then put your passcode between double quotes “passcode_here”</strong></p><blockquote><strong><em>Step 6: </em>Permit write access</strong></blockquote><p>Run below command to permit write access to the storage and cache folders, where Laravel stores application-generated files</p><pre>sudo chown -R www-data.www-data /var/www/html/[directory]/storage<br>sudo chown -R www-data.www-data /var/www/html/[directory]/bootstrap/cache</pre><blockquote><strong><em>Step 7: C</em>onfigure Nginx to serve the application</strong></blockquote><pre>sudo rm -rf /etc/nginx/sites-available/default<br>sudo rm -rf /etc/nginx/sites-enabled/default</pre><pre>sudo nano /etc/nginx/sites-available/myLaraApp</pre><p>The following configuration file contains the <a href="https://laravel.com/docs/5.8/deployment#server-configuration">recommended</a> settings for Laravel applications on Nginx</p><pre>server {</pre><pre>listen 80;<br>root /var/www/html/[directory]/public;<br>index index.php index.html index.htm index.nginx-debian.html;<br>server_name _;<br>#Or write the above line as server_name [server_IP][domain_name];</pre><pre>location / {<br>    try_files $uri $uri/ /index.php?$query_string;<br>}</pre><pre>location ~ \.php$ {<br>    include snippets/fastcgi-php.conf;<br>    fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;<br>   # I am using php7.4-fpm, you can use other versions too<br>}</pre><pre>location ~ /\.ht {<br>    deny all;<br>}</pre><pre>}</pre><blockquote><strong><em>Step 8:</em> Enable the file by linking to the sites-enabled dir</strong></blockquote><pre>sudo ln -s /etc/nginx/sites-available/myLaraApp /etc/nginx/sites-enabled</pre><blockquote><strong><em>Step 9:</em> Test Nginx config</strong></blockquote><pre>sudo nginx -t</pre><p>You should see output like this</p><pre>nginx: the configuration file /etc/nginx/nginx.conf syntax is ok<br>nginx: configuration file /etc/nginx/nginx.conf test is successful</pre><p>If the test failed then check the Nginx configuration step again.</p><blockquote><strong><em>Step 10:</em> Do not forget to restart your Nginx server</strong></blockquote><pre>sudo systemctl restart nginx</pre><blockquote><strong><em>Step 11:</em> Customize your the application</strong></blockquote><p>Open the main route file, routes/web.php</p><pre>nano routes/web.php</pre><p>Then update the file with the following content</p><pre><strong>&lt;?php</strong><br><br>/*<br>|-----------------------------------------------------------------<br>| Web Routes<br>|-----------------------------------------------------------------<br>|<br>| Here is where you can register web routes for your application. These<br>| routes are loaded by the RouteServiceProvider within a group which<br>| contains the &quot;web&quot; middleware group. Now create something great!<br>|<br>*/<br><br>Route::get(&#39;/&#39;, function () {<br>    return view(&#39;welcome&#39;);<br>});</pre><p>Routes are defined within this file using the static method Route::get, which receives a <strong>path</strong> and a <strong>callback function</strong> as arguments.</p><p>Now go to your browser and access the application using the server’s domain name or IP address</p><pre>http://server_domain_or_IP</pre><p>If you want to <strong>activate SSL certificate on your domain/app, </strong>please read <a href="https://medium.com/@galib.rabib/how-to-secure-nginx-with-lets-encryption-by-cerbot-client-on-ububtu-16-04-3da65cf8dd12"><strong>this story</strong></a>.</p><p>Have fun 🔥 💪</p><p>If you have any query, please put in below. Find me on <a href="https://github.com/RabibHossain/">Github</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3e9c6f6d2e0b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How To Deploy a React app using Nginx  and Ubuntu 16.04 / 18.04 LTS / 19.10 / 20.04 LTS]]></title>
            <link>https://galib-rabib.medium.com/how-to-deploy-a-react-app-using-nginx-and-ubuntu-16-04-18-04-lts-19-10-20-04-lts-5a54a21d21b0?source=rss-ac13a096b42c------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a54a21d21b0</guid>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[ubuntu]]></category>
            <dc:creator><![CDATA[Rabib Galib]]></dc:creator>
            <pubDate>Thu, 20 Aug 2020 21:14:36 GMT</pubDate>
            <atom:updated>2020-08-20T23:19:17.890Z</atom:updated>
            <content:encoded><![CDATA[<h3>How To Deploy a React app using Nginx and Ubuntu 16.04 / 18.04 LTS / 19.10 / 20.04 LTS</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TPyiqIgwbU4MV6TQELdCFQ.jpeg" /></figure><p>This story will assist you to deploy React or any JS application in Ubuntu.</p><h3><strong>Server requirements</strong></h3><p>You need a Linux based system, I’m gonna use Ubuntu 18.04 for this story, you are free to use your own 😀<br>Disk : ~25GB<br>Memory : 2GB<br>CPU: 1 core</p><p>First logged into your remote system via ssh (<strong>Secure Shell</strong>).</p><pre>ssh root@server_ip_address</pre><p>Let’s begin by updating server’s package index</p><pre>sudo apt-get update</pre><h3>Installation</h3><blockquote><strong><em>Step 1: </em>Install NodeJS and npm</strong></blockquote><p><strong>Node.js</strong> is an open-source, cross-platform JavaScript run-time environment that executes JavaScript code outside of a browser. <strong>NPM</strong> is a package manager for the JavaScript programming language. It is the default package manager for <strong>Node.js</strong>.</p><pre>curl -sL https://deb.nodesource.com/setup_13.x | sudo -E bash -<br>sudo apt-get install nodejs</pre><p>Check your Node &amp; NPM version now</p><pre>node -v<br>npm -v</pre><blockquote><strong><em>Step 2: </em>Install Nginx</strong></blockquote><p>Nginx is a totally free, open-source, high-performance HTTP server.</p><pre>sudo apt-get install nginx</pre><blockquote><strong><em>Step 3: </em>Deployment</strong></blockquote><pre>cd /var/www/html<br>sudo git clone [Your repository URL with branch]<br>cd [Your Repository Name]<br>sudo npm install<br>sudo npm run build</pre><blockquote><strong><em>Step 4: </em>Permit Nginx to access your application folder</strong></blockquote><pre>sudo gpasswd -a &quot;$USER&quot; www-data<br>sudo chown -R &quot;$USER&quot;:www-data /var/www/html<br>find /var/www/html -type f -exec chmod 0660 {} \;<br>sudo find /var/www/html -type d -exec chmod 2770 {} \;</pre><blockquote><strong><em>Step 5: </em>Configure Nginx to serve your React application</strong></blockquote><pre>sudo rm -rf /etc/nginx/sites-available/default<br>sudo rm -rf /etc/nginx/sites-enabled/default<br>sudo nano /etc/nginx/sites-available/myreactapp</pre><p>Now paste the below code in myreactapp file</p><pre>server {<br>   listen 80;<br>   server_name [your_IP] [domain.com] [www.domain.com];<br>   root /var/www/html/[directory]/build;<br>   index index.html index.htm;</pre><pre>   location / {<br>       try_files $uri /index.html =404;<br>   }</pre><pre>}</pre><blockquote><strong><em>Step 6: </em>Enable the file by linking to the sites-enabled dir</strong></blockquote><pre>sudo ln -s /etc/nginx/sites-available/myreactapp /etc/nginx/sites-enabled</pre><blockquote><strong><em>Step 7: </em>Test Nginx config</strong></blockquote><pre>sudo nginx -t</pre><p>You should see output like this</p><pre>nginx: the configuration file /etc/nginx/nginx.conf syntax is ok<br>nginx: configuration file /etc/nginx/nginx.conf test is successful</pre><p>If the test failed then check the Nginx configuration step again.</p><blockquote><strong><em>Step 8: </em>Do not forget to restart your Nginx server</strong></blockquote><pre>sudo systemctl restart nginx</pre><p>Now open your browser and go to <a href="http://youripaddress/">http://youripaddress</a> or <a href="http://domain.com/">http://domain.com</a></p><p>If you want to <strong>activate SSL certificate on your domain/app, </strong>please read <a href="https://medium.com/@galib.rabib/how-to-secure-nginx-with-lets-encryption-by-cerbot-client-on-ububtu-16-04-3da65cf8dd12"><strong>this story</strong></a>.</p><p>Have fun 🔥 💪</p><p>If you have any query, please put in below. Find me on <a href="https://github.com/RabibHossain/">Github</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a54a21d21b0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to fix ‘CORS’ error in lumen API services]]></title>
            <link>https://galib-rabib.medium.com/how-to-fix-cors-error-in-lumen-api-services-ba5a62d23507?source=rss-ac13a096b42c------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba5a62d23507</guid>
            <category><![CDATA[cors]]></category>
            <category><![CDATA[lumen]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[laravel]]></category>
            <dc:creator><![CDATA[Rabib Galib]]></dc:creator>
            <pubDate>Thu, 13 Aug 2020 21:25:55 GMT</pubDate>
            <atom:updated>2022-05-13T14:46:09.460Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*aUsFSltINgFPTyFtOg6_NQ.jpeg" /></figure><p>While building APIs with micro-service based application, we often face an error as —<strong> ‘https://localhost:8000’ has been blocked by CORS policy: No Access-Control-Allow-Origin header is present on the requested resource.</strong></p><p>We usually know this issue as ‘CORS’ issue. <strong>Cross-Origin Resource Sharing</strong> (CORS) is a mechanism that uses additional HTTP headers to tell browsers to give a web application running at one origin, access to selected resources from a different origin. The CORS standard is needed because it allows servers to specify not just who can access its assets, but also <em>how</em> the assets can be accessed.</p><p>This story will assist you to fix this issue in Lumen application with the help of <a href="https://github.com/fruitcake/laravel-cors">Laravel-cors</a> package step by step.</p><blockquote><strong>Step 1 </strong><em>Install Laravel-Cors package in your terminal &amp; put the below command</em></blockquote><pre>composer require fruitcake/laravel-cors</pre><p>Above command will modify your composer.json by updating your dependencies. Have a look in composer.json &amp; you’ll find this package.</p><pre>&quot;fruitcake/laravel-cors&quot;: &quot;^2.0&quot;,</pre><blockquote><strong>Step 2 </strong>Now, in your lumen application, under config folder (<strong>If not then create a directory names config</strong>) create a file names cors.php &amp; put the below code in it (<strong>config/cors.php</strong>)</blockquote><pre>&lt;?php </pre><pre>return [    </pre><pre>   &#39;paths&#39; =&gt; [&#39;*&#39;],<br>   &#39;allowed_methods&#39; =&gt; [&#39;*&#39;],<br>   &#39;allowed_origins&#39; =&gt; [&#39;*&#39;],<br>   &#39;allowed_origins_patterns&#39; =&gt; [],<br>   &#39;allowed_headers&#39; =&gt; [&#39;*&#39;],<br>   &#39;exposed_headers&#39; =&gt; [],<br>   &#39;max_age&#39; =&gt; 0,<br>   &#39;supports_credentials&#39; =&gt; false,<br>];</pre><h3><strong>Explanation of above code:</strong></h3><p><strong>paths</strong>: This option takes an array value and allows us to enable cors for multiple paths. Some example configurations would be:</p><pre>&#39;paths&#39; =&gt; [&#39;api/*&#39;, &#39;*&#39;]</pre><p><strong>allowed_methods</strong>: This option indicates what HTTP request methods to allow on the specified paths. [*]allows all methods. Some examples of option values would be:</p><pre>&#39;allowed_methods&#39; =&gt; [&#39;POST&#39;, &#39;GET&#39;, &#39;DELETE&#39;, &#39;PUT&#39;, &#39;*&#39;]</pre><p><strong>allowed_origins: </strong>This option specifies what source requests should be allowed from. Either from local or single machine or from any machine.</p><pre>&#39;allowed_origins&#39; =&gt; [&#39;http://example.com:8080&#39;, &#39;*&#39;]</pre><p><strong>allowed_origins_patterns: </strong>This<strong> </strong>option<strong> </strong>matches the request origin with patterns</p><pre>&#39;allowed_origins_patterns&#39; =&gt; [&#39;example\&#39;]</pre><p><strong>allowed_headers</strong>: This specifies to set the Access-Control-Allow-Headers, which is used in response to a <a href="https://developer.mozilla.org/en-US/docs/Glossary/preflight_request">preflight request</a> which includes the <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Request-Headers">Access-Control-Request-Headers</a> to indicate which HTTP headers can be used during the actual request.</p><pre>&#39;allowed_headers&#39; =&gt; [&#39;<a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Request-Method">Access-Control-Request-Method</a>&#39;, &#39;<a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Request-Headers">Access-Control-Request-Headers</a>&#39;, &#39;*&#39;]</pre><p><strong>exposed_headers: </strong>A list of exposed headers consisting of zero or more <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers">header names</a> other than the <a href="https://developer.mozilla.org/en-US/docs/Glossary/CORS-safelisted_request_header">CORS-safelisted request headers</a> that the resource might use and can be exposed.</p><p><strong>max_age</strong>: This option is used to set the Access-Control-Max-Age response header. The <strong>Access-Control-Max-Age</strong> response header indicates how long the results of a <a href="https://developer.mozilla.org/en-US/docs/Glossary/preflight_request">preflight request</a> ( the information contained in the <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Methods">Access-Control-Allow-Methods</a> and <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers">Access-Control-Allow-Headers</a> headers) can be cached.</p><p><strong>supports_credentials</strong>: This option sets the Access-Control-Allow-Credentials header. The <strong>Access-Control-Allow-Credentials</strong> response header tells browsers whether to expose the response to frontend JavaScript code when the request&#39;s credentials mode (<a href="https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials">Request.credentials</a>) is included.</p><blockquote><strong>Step 3</strong> Now register the <strong>CorsServiceProvider </strong>manually in your <strong>bootstrap/app.php</strong> file as follow-</blockquote><pre>$app-&gt;register(Fruitcake\Cors\CorsServiceProvider::<strong>class</strong>);</pre><pre>$app-&gt;configure(&#39;cors&#39;);</pre><pre>$app-&gt;middleware([<br>    Fruitcake\Cors\HandleCors::<strong>class</strong>,<br>]);</pre><p>Once done, put the below commands, this will clear the configuration <strong>cache</strong> before it creates</p><pre>php artisan cache:clear</pre><p>Have fun 🔥 💪</p><p>If you have any query, please put in below. Find me on <a href="https://github.com/RabibHossain/">Github</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba5a62d23507" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to secure NGINX (SSL Certificate) with let’s Encryption by Certbot client on Ububtu 16.04]]></title>
            <link>https://galib-rabib.medium.com/how-to-secure-nginx-with-lets-encryption-by-cerbot-client-on-ububtu-16-04-3da65cf8dd12?source=rss-ac13a096b42c------2</link>
            <guid isPermaLink="false">https://medium.com/p/3da65cf8dd12</guid>
            <category><![CDATA[lets-encrypt]]></category>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[ssl-certificate]]></category>
            <category><![CDATA[certbot]]></category>
            <dc:creator><![CDATA[Rabib Galib]]></dc:creator>
            <pubDate>Wed, 22 Jul 2020 17:10:37 GMT</pubDate>
            <atom:updated>2020-08-13T21:36:07.691Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to secure NGINX (SSL Certificate) with let’s Encryption by Certbot client on Ububtu 16.04 / 18.04 LTS / 19.10 / 20.04 LTS</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gn8zG0WkncJP06ykmiEq8w.png" /></figure><p>This tutorial will assist you how to set up a <strong>TLS/SSL certificate</strong> from <a href="https://letsencrypt.org/">Let’s Encrypt</a> on an <strong>Ubuntu </strong>server running <strong>nginx </strong>as a web server.</p><p>First logged into your remote system via ssh.</p><pre>ssh root@server_ip_address</pre><p>Let’s begin by updating server’s package index</p><pre>sudo apt-get update</pre><p>Now install <strong>certbot </strong>&amp; other dependent packages. Certbot is a command line client for Let’s Encrypt. <strong>python-certbot-nginx</strong> is Certbot’s Nginx package with apt-get.</p><pre>sudo apt-get install certbot python-certbot-nginx</pre><p>After installation check your certbot version.</p><pre>certbot --version</pre><p>Let’s start registration process for certificate. Run below command-</p><pre>sudo certbot certonly --nginx</pre><p>In above command as we put — nginx, certonly will look into sites-available directory &amp; will find out domain(s) itself.</p><blockquote>Then it’ll ask for an email address for renewal or security issues.</blockquote><blockquote>Select the domain, you would like to activate HTTPS for.</blockquote><p>Then your domain will be registered for a time period as follows-</p><pre>IMPORTANT NOTES:<br> - <strong>Congratulations</strong>! Your certificate and chain have been saved at:<br>   /etc/letsencrypt/live/<strong>your_domain.com</strong>/fullchain.pem<br>   Your key file has been saved at:<br>   /etc/letsencrypt/live/<strong>your_domain.com</strong>/privkey.pem<br>   <strong>Your cert will expire on 2020-10-22</strong>. To obtain a new or tweaked<br>   version of this certificate in the future, simply run certbot again<br>   with the &quot;certonly&quot; option. To non-interactively renew *all* of<br>   your certificates, run &quot;certbot renew&quot;<br> - If you like Certbot, please consider supporting our work by:<br><br>   Donating to ISRG / Let&#39;s Encrypt:  https://letsencrypt.org/donate<br>   Donating to EFF:                  https://eff.org/donate-le</pre><p>Now run the below command to bring the certificate in your sites-available. This command will modify the config file with certbot SSL itself.</p><pre>sudo certbot install --nginx</pre><p>Check your configuration file now</p><pre>nano cd /etc/nginx/sites-available/configuration_file</pre><p>Let’s Encrypt’s certificates are only valid for ninety days (90 days).</p><p>Have fun 🔥 💪</p><p>If you have any query, please put in below. Find me on <a href="https://github.com/RabibHossain/">Github</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3da65cf8dd12" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to enable remote Login to MySQL Database Server in Ubuntu / Debian]]></title>
            <link>https://galib-rabib.medium.com/how-to-enable-remote-login-to-mysql-database-server-in-ubuntu-debian-36d875921eb2?source=rss-ac13a096b42c------2</link>
            <guid isPermaLink="false">https://medium.com/p/36d875921eb2</guid>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[mysql-database-server]]></category>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[remote-login]]></category>
            <category><![CDATA[enable-remote-access]]></category>
            <dc:creator><![CDATA[Rabib Galib]]></dc:creator>
            <pubDate>Fri, 17 Jul 2020 14:55:26 GMT</pubDate>
            <atom:updated>2020-07-17T15:24:27.296Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*am7aZqw4LO7LwYSzYNxzew.png" /></figure><p>At first Install and Configure MySQL Database Server in Ubuntu. If you have not installed yet, read <a href="https://medium.com/@galib.rabib/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-18-04-lts-19-10-263625ac65ad">this story</a>.</p><p>So, right now you are connected with MySQL Database server with Ubuntu/Debian machine. This story is going to assist you to know how to connect MySQL Database server from a different/remote machine. You can use remote root connection or if you want, you can use remote user connection too. Here, you will know how to connect remotely to MySQL not only by <strong>root login</strong> but also by <strong>user login</strong>.</p><blockquote><strong><em>Remote Root Login</em></strong></blockquote><p>You can check at the same time is it working or not by typing some commands in another terminal. So, first of all install mysql-client in your machine</p><pre>sudo apt install mysql-client -y</pre><p><strong><em>Step 1 —</em></strong> Let’s connect to the server via SSH in your main machine.</p><pre>ssh root@server_ip_address</pre><p><strong><em>Step 2 —</em> </strong>You can get the ip address via bellow command too 😉</p><pre>ip a</pre><p><strong><em>Step 3 —</em> </strong>Now you need to go to the mysql configuration file &amp; have to edit the configuration.</p><pre>nano /etc/mysql/mysql.conf.d/mysqld.cnf</pre><p><strong><em>Step 4 —</em> </strong>Now find <strong>bind address = 127.0.0.1 </strong>statement, by default it allows only the localhost to connect the database. Put “#” before the statement. Then it will be as <strong>#bind address = 127.0.0.1 </strong>So, it will allow to connect the database from anywhere 😀</p><p>If you don’t find the bind address line then you can add <strong>bind address = 0.0.0.0 </strong>or<strong> skip-networking</strong> and <strong>skip-bind-address</strong> in that configuration file. If you put any one of these three then do not put ‘#’ before it [Good to know]. Also check your port address. Here, <strong>your port address is 3306</strong>. So, it will allow also to connect the database from anywhere 😀</p><p>After editing your configuration file may like</p><pre><br>[mysqld_safe]<br>socket          = /var/run/mysqld/mysqld.sock<br>nice            = 0<br><br>[mysqld]<br>#<br># * Basic Settings<br>#<br>user            = mysql<br>pid-file        = /var/run/mysqld/mysqld.pid<br>socket          = /var/run/mysqld/mysqld.sock<br><strong>port            = 3306</strong><br>basedir         = /usr<br>datadir         = /var/lib/mysql<br>tmpdir          = /tmp<br>lc-messages-dir = /usr/share/mysql<br>skip-external-locking<br>#<br># Instead of skip-networking the default is now to listen only on<br># localhost which is more compatible and is not less secure.<br><strong>#bind-address            = 127.0.0.1<br>#skip-networking <br>#skip-bind-address</strong><br>#<br># * Fine Tuning<br>#<br>key_buffer_size         = 16M<br>max_allowed_packet      = 16M<br>thread_stack            = 192K<br>thread_cache_size       = 8<br><br>query_cache_limit       = 1M<br>query_cache_size        = 16M<br><br>log_error = /var/log/mysql/error.log<br><br>expire_logs_days        = 10<br>max_binlog_size   = 100M<br></pre><p><strong>NB </strong>— [ <strong>Good to know</strong> ] You can allow MySQL database access from a specific IP_ADDRESS</p><pre>sudo ufw allow from <strong>your_remote_ip_address </strong>to any port 3306</pre><p>Or, [ <strong>Good to know</strong> ] you can allow connections to MySQL database from any remote IP_ADDRESS too</p><pre>sudo ufw allow 3306</pre><p><strong><em>Step 5 — </em></strong>Now restart your mysql server</p><pre>sudo systemctl restart mysql</pre><p><strong><em>Step 6— </em></strong>Now you have connect the Database server by root user.</p><pre>sudo mysql -u root -p</pre><p><strong><em>Step 7— </em></strong>Check you databases</p><pre>show databases;</pre><p><strong><em>Step 8— </em></strong>Now lock mysql as it holds the database configuration</p><pre>use mysql;</pre><p><strong><em>Step 9— </em></strong>Now run below query &amp; check the output</p><pre>SELECT host FROM user WHERE user = &#39;root&#39;;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/679/1*xumaxAjQbrns3PYtSr1q-Q.png" /></figure><p>Here, we’ve only loalhost as host which means the user root is only allowed to login by localhost [<strong>not by different machine</strong>].</p><p><strong><em>Step 10— </em></strong>Now we are going to add root in host to allow remote login from different machine too. Now, run below query</p><pre>GRANT ALL ON *.* to root@&#39;%&#39; IDENTIFIED BY &#39;put_your_root_password&#39;;</pre><p>Here <strong>*.*</strong> means all the databases with tables can be accessible by root identified by your root password. Now put the below query again &amp; check the host</p><pre>SELECT host FROM user WHERE user = &#39;root&#39;;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/781/1*OJcUd8No5rBKDbZADcHugg.png" /></figure><p>Here, <strong>%</strong> is added, means you can connect to database by root remotely. Now write exit query to log out from mysql.</p><pre>exit;</pre><p><strong><em>Step 11 — </em></strong>So, your remote root connection configuration is done. Your can check the connection via another terminal. Open another terminal. Do not forget to install mysql-client [ <strong>sudo apt install mysql-client -y</strong> ]. Now write below command to check the remote connection.</p><pre>mysql -h <strong>ip_address </strong>-u root -p</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/893/1*33rzhqmXitBEHQ5AWYocxA.png" /><figcaption>Checking via another terminal window</figcaption></figure><p>Or you can test the remote connection using <strong>MySQL Workbench </strong>too. Too easy, just download it if you don’t have it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KlKKiqO2IhZHMZWutpBjgQ.png" /></figure><p>So, this is all about remote root login from different machine. Now comes remote user login process.</p><blockquote><strong><em>Remote User Login</em></strong></blockquote><p>It is just like root login process. Follow <strong>step 1 to step 6</strong>.</p><p>After connecting to mysql server via <strong>sudo mysql -u root -p </strong>command, write below query to create user.</p><pre>create user &quot;iamuser&quot;@&quot;%&quot; identified by &quot;put_your_user_password&quot;;</pre><p>Now run below query</p><pre>GRANT ALL ON dbname.* TO iamuser@&#39;%&#39; IDENTIFIED BY &#39;put_your_user_password&#39;;</pre><p>Here dbname is a specific Database, instead of ‘%’ you can use ‘IP_ADDRESS’. Now do exit; query.</p><p>So, your remote user login configuration is done. You can check the connection via another terminal. Open another terminal. Do not forget to install mysql-client [ <strong>sudo apt install mysql-client -y</strong> ]. Now write below command to check the remote connection.</p><pre>mysql -u user -h database_server_ip -p</pre><p>Or you can use <strong>MySQL Workbench </strong>too.</p><p>While configuring you may get some errors too. <strong>Let’s talk about some errors</strong>.</p><pre>&quot; ERROR 2003 (HY000): <strong>Can&#39;t connect to MySQL server on &#39;database_server_ip&#39;</strong> &quot;</pre><p>Above error says, either database <strong>port 3306 is not open</strong> or <strong>MySQL server is not listening</strong> on the connecting IP_ADDRESS. Solution is check &amp; follow step 4 correctly.</p><p>Let’s see another error</p><pre>&quot;ERROR 1130 (HY000): <strong>Host &#39;database_server_ip&#39; is not allowed to connect to this MySQL server </strong>&quot;</pre><p>Above error says, <strong>user doesn’t have permission</strong> to access the remote MySQL server. Solution is check &amp; follow step 6 to last correctly.</p><p>Finally, now you can connect to MySQL Database Server from any machine.</p><p>Have fun 🔥 💪</p><p>If you have any query, please put in below. Find me on <a href="https://github.com/RabibHossain/">Github</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=36d875921eb2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>