<?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 Devendrakhatri on Medium]]></title>
        <description><![CDATA[Stories by Devendrakhatri on Medium]]></description>
        <link>https://medium.com/@devendrakhatri904?source=rss-40ec454acfef------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*VoNtpd7xp7Xc431I</url>
            <title>Stories by Devendrakhatri on Medium</title>
            <link>https://medium.com/@devendrakhatri904?source=rss-40ec454acfef------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 18:50:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@devendrakhatri904/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[Connecting a Remote MySQL Database to a Virtual Server using NGINX and phpMyAdmin]]></title>
            <link>https://medium.com/@devendrakhatri904/connecting-a-remote-mysql-database-to-a-virtual-server-using-nginx-and-phpmyadmin-a2999806fa2e?source=rss-40ec454acfef------2</link>
            <guid isPermaLink="false">https://medium.com/p/a2999806fa2e</guid>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[mysql]]></category>
            <dc:creator><![CDATA[Devendrakhatri]]></dc:creator>
            <pubDate>Sun, 27 Jul 2025 09:09:54 GMT</pubDate>
            <atom:updated>2025-07-27T09:09:54.717Z</atom:updated>
            <content:encoded><![CDATA[<p>Ever wondered how to connect a virtual server (running on VirtualBox or any hypervisor) to a <strong>MySQL database hosted on a different machine</strong>?</p><p>In this guide, I’ll walk you through exactly how to:</p><ul><li>Set up a virtual Ubuntu server</li><li>Install NGINX and phpMyAdmin</li><li>Configure it to connect to a <strong>remote MySQL database</strong> running on your host machine</li></ul><p>Let’s get started</p><h3>Scenario</h3><p>You have two machines:</p><ul><li><strong>Machine A (Host)</strong>: Running MySQL server</li><li><strong>Machine B (Virtual Server)</strong>: Running NGINX + phpMyAdmin</li></ul><p>The goal is to access the MySQL database from the virtual server.</p><h3>1. Set up Your Virtual Machine</h3><p>Use VirtualBox or any VM tool and install <strong>Ubuntu Server</strong> on your virtual machine.</p><blockquote><em>Tip: Use </em><strong><em>Bridged Networking</em></strong><em> so your VM is accessible via a local IP like </em><em>192.168.x.x.</em></blockquote><h3>2. Install Required Software</h3><p>On your <strong>virtual server</strong>, run:</p><pre>sudo apt update<br>sudo apt install nginx php php-fpm php-mysql mysql-client</pre><p>You now have:</p><ul><li>NGINX for web server</li><li>PHP + FPM for processing php</li><li>MySQL client for terminal connection</li></ul><h3>3. Install and Configure phpMyAdmin</h3><pre>sudo apt install phpmyadmin</pre><ul><li>When prompted for a web server, press Tab and <strong>don’t select Apache</strong>.</li><li>Choose <strong>No</strong> when asked about dbconfig-common (you’ll configure manually).</li></ul><h4>Link phpMyAdmin to NGINX root:</h4><pre>sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin</pre><h3>4. Configure NGINX</h3><p>Edit the default config:</p><pre>sudo nano /etc/nginx/sites-enabled/default</pre><p>Paste the following:</p><pre>server {<br>    listen 80;<br>    root /var/www/html;<br>    index index.html index.php;<br><br>    location / {<br>        try_files $uri $uri/ =404;<br>    }<br><br>    location ~ \.php$ {<br>        include snippets/fastcgi-php.conf;<br>        fastcgi_pass unix:/run/php/php8.3-fpm.sock;<br>    }<br><br>    location /phpmyadmin/ {<br>        alias /var/www/html/phpmyadmin/;<br>        index index.php;<br>    }<br><br>    location ~ ^/phpmyadmin/(.+\.php)$ {<br>        alias /var/www/html/phpmyadmin/$1;<br>        include snippets/fastcgi-php.conf;<br>        fastcgi_pass unix:/run/php/php8.3-fpm.sock;<br>    }<br><br>    location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {<br>        alias /var/www/html/phpmyadmin/$1;<br>    }<br>}</pre><p>Then restart:</p><pre>sudo systemctl restart nginx php8.3-fpm</pre><h3>5. Configure the Host MySQL Server</h3><p>On your <strong>host machine</strong>, allow remote access:</p><p>Change:</p><ul><li>Go to /etc/mysql/mysql.conf.d/mysqld.conf</li><li>First bind-address to 0.0.0.0 from 127.0.0.1</li></ul><pre>bind-address = 0.0.0.0</pre><p>Then:</p><pre>sudo systemctl restart mysql</pre><h3>6. Create a Remote MySQL User</h3><pre>sudo mysql -u root -p</pre><p>Then:</p><pre>CREATE USER ‘remoteuser’@’192.168.x.x’ IDENTIFIED BY ‘yourpassword’;<br>GRANT ALL PRIVILEGES ON *.* TO ‘remoteuser’@’192.168.x.x’ WITH GRANT OPTION;<br>FLUSH PRIVILEGES;</pre><p>✔ Replace 192.168.x.x with your virtual machine’s IP.</p><h3>7. Configure phpMyAdmin to Use Remote MySQL</h3><p>Edit:</p><pre>sudo nano /etc/phpmyadmin/config-db.php</pre><p>Update the values:</p><pre>$dbuser=’remoteuser’;<br>$dbpass=’yourpassword’;<br>$dbserver=’192.168.1.1&#39;; // Your host IP<br>$dbname=’yourdatabase’; // Optional</pre><p>Now visit:</p><pre>http://&lt;virtual_server_ip&gt;/phpmyadmin</pre><p>You can now log in and interact with your <strong>host’s MySQL</strong> from the virtual server.</p><h3>8. Bonus: Use mysql-client from CLI</h3><p>Alternatively, connect via terminal from the virtual server:</p><pre>mysql -u remoteuser -p -h 192.168.1.1 -P 3306</pre><p>-h should be the host ip</p><h3>Firewall Troubleshooting (Optional)</h3><p>If you have ufw enabled on the host, allow MySQL port:</p><pre>sudo ufw allow 3306/tcp</pre><h3>✅ Wrapping Up</h3><p>You’ve now connected your virtual server to a remote MySQL server using:</p><ul><li>phpMyAdmin on NGINX</li><li>MySQL client via CLI</li></ul><p>This setup is perfect for testing real-world production-like architecture right from your local system. Feel free to scale it up with Docker or containers later on!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a2999806fa2e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>