Shubham Raj
Shubham Raj

Reputation: 1

Is it possible to update my PHP website hosted on an FTP server when the database is located on separate XAMPP server? If so, how can I achieve this?

I am seeking information on the feasibility of updating a PHP website hosted on an FTP server when the website's database is located on a separate XAMPP server. I am interested in understanding if this can be done and if so, how to go about it. In essence, I want to know if it's possible to maintain and synchronize my website with the database under these circumstances.

I've been researching online, but I haven't found valuable information regarding the possibility of interacting with a MySQL database hosted on XAMPP from a website stored on a remote server using FTP. Even ChatGPT has suggested that such interaction might be impossible based on the available information.

Upvotes: 0

Views: 128

Answers (1)

Rob Eyre
Rob Eyre

Reputation: 2203

As long as both the website server and the MySQL server are on the same network and can communicate with each other, then this is straightforward. In fact, this is quite a standard setup.

What you need to do is to ensure that your PHP code includes the connection details for reaching the database server. How you do this depends on if you're using a framework or library. For example, if you're using PDO, then you'll need something like this:

$pdo = new PDO("mysql:host=my_mysql_server;dbname=my_database", 'my_user', 'my_password');

You may also need to confirm that your MySQL server's permissions are set to allow connections from your PHP server. Depending on your setup, this might work 'out of the box', but you may need to allow the connection explicitly using something like:

GRANT ALL ON my_database.* TO 'my_user'@'my_php_server';
FLUSH PRIVILEGES;

See some summary documentation on this here: https://www.digitalocean.com/community/tutorials/how-to-create-a-new-user-and-grant-permissions-in-mysql

Upvotes: 1

Related Questions