0

I would like to set up REST API, which can communicate with my database on my NAS. I made this simple PHP code for the database connection, and it works perfectly with Xampp on my computer.

<?php

$servername = "localhost:3307";
$username = "root";
$password = "MyRootPassword";

// Create connection
$conn = new mysqli($servername, $username, $password);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";

However, when I upload this script to my web folder on my NAS, and when I want to load the file in the browser, I receive a HTTP Error 500 message.

(I have installed Web Station, and the server runs with PHP 7.3 and Apache HTTP Server 2.4. I also installed phpMyAdmin and MariaDB10.)

Why my code does not work on the NAS?

1 Answer 1

0

Finally I figured it out. There were multiple things to configure:

  1. First of all, if you want to connect to the database remotely (outside from network), you have to configure the host for the user, and set it to %. This means this user can connect from any location. This is not necessary, if you want to connect to the database from where the php code runs, then localhost or 127.0.0.1. is enough.

  2. The real issue why I had error 500 was that my mysqli extension was disabled in the Web Station PHP settings. I had to edit my PHP 7.3 settings, and add the mysqli extension.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .