John Davidson

How to connect a web app in a pc with a database on another pc using php mysql XAMPP

0 comments
Message:


I have a web app in php mysql programmed with xampp server.


I need to have the web server with the app files in one pc on xammp and connect it to a mysql database on another pc using xampp also I imagine on phpmyadmin as usual.


I don't know how to redirect the database, as in one pc you just put the dB name in the queries but I don't know how to do it if the database is on another pc.


I couldn't find any info online, I already can access my xampp server through ip address on another devices but with the web server and the dB server on the same pc.


I need to have the web app files in one pc and the database in another, using xampp in both pc. So I can connect other devices as clients and use the web app normally.


Please help:( it is for a project :(


Edit:
I am beginner, so I really would like a detailed explanation with examples please so I can replicate it.



My Answer:
To connect a web app on one PC with a database on another PC using XAMPP, you will need to follow these steps:

1. Configure MySQL on the database PC:
- Make sure MySQL is running on the database PC.
- Open phpMyAdmin on the database PC and create a new database for your web app.
- Create a new user with appropriate privileges for the database.
- Note down the database name, username, and password for later use.

2. Configure XAMPP on the web server PC:
- Make sure XAMPP is running on the web server PC.
- Open the phpMyAdmin on the web server PC and create a new database connection.
- In the config.inc.php file located in the phpMyAdmin directory, add the following lines:

$cfg['Servers'][$i]['host'] = 'database_pc_ip_address';
$cfg['Servers'][$i]['port'] = '3306';
$cfg['Servers'][$i]['user'] = 'database_username';
$cfg['Servers'][$i]['password'] = 'database_password';

Replace 'database_pc_ip_address', 'database_username', and 'database_password' with the actual values for the database PC.

3. Update the connection settings in your web app:
- In your PHP code, update the connection settings to point to the database on the database PC.
- Use the database name, username, and password that you noted down earlier.
- Update the host parameter in the connection string to the IP address of the database PC.

4. Test the connection:
- Run your web app on the web server PC and check if it can connect to the database on the database PC.
- Test the functionality of your web app to ensure that it is working correctly with the remote database.

By following these steps, you should be able to connect your web app on one PC with a database on another PC using XAMPP. If you encounter any issues, make sure that both PCs are on the same network and that the necessary ports are open for communication.

Rate this post

3 of 5 based on 3165 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us