Unity - PHP - MySql question

Hi

I am attempting to access a MySQL database from Unity using the UnityWebRequest class.
The order of connection would be UnityWebRequest>>a PHP file>>MySql database.

The database is set up with the MySQL workbench application, and a VS script is running to enable a UI and data access through a port. This is basically a web-browser based manipulation interface for the database and it should be independent from the Unity access.
The whole thing is running on localhost with a local folder as root.

From Unity I am trying to access a .php file I placed in the localhost’s folder system.
I have tested the path and the access with a simple .txt file and a .html file too and I can access them without a problem, however when trying to access the .php I get a not found error. It is 100% sure that the filename and path is correct.

I am using the following code :

        UnityWebRequest r = UnityWebRequest.Get("http://localhost:50693/.php/webtest.php");
       
        yield return r.SendWebRequest();


        if (r.isNetworkError || r.isHttpError)
        {
            Debug.LogError(r.error);
        }
        else
        {
            Debug.LogError(r.downloadHandler.text);
        }

and the result is :
HTTP/1.1 404 Not Found

When I am using the same code with the same path except for the filename as test.txt or test.html, I am getting the correct contents of the files.

Any idea what could be the problem?

Maybe your http sever (or php processor) does not serve files from unix-hidden folders (folders starting with a dot “.” - e.g. “host/.php/…”). Try moving the webtest.php file to a different directory. You also say that you use the same path for .txt and .html and those work fine. So maybe your http server just doesn’t know how to process a .php file. If it’s an Apache server, you need to install a php extension into it. If it’s an Nginx, then you need to refer it to a php-fpm process. Either way I didn’t catch what your http server is so cannot help more…

Anyways, doing all of this by yourself is quite a bit of hassle (as you see). I’ve just released a tool that lets you build a backend server with a database easily. You can use C# on the server-side and not PHP and also the JSON serialization is completely invisible and transparent :slight_smile: Check it out, I would like to know what you think of it: https://unisave.cloud/

Thanks :wink:

EDIT: This article might be relevant to people reading:
Why not to build game backend server with MySQL and PHP

are you running a local php server? Like WAMP or something?
You cant run PHP files locally otherwise.