Azure Website 404 (Not Found) on PHP Resources - javascript

I'm new to all things coding and have tried to use Azure to host a web app. The app is JavaScript using PHP to process MYSQL data. Everything works locally as expected. But when I try to access the app where it's hosted, I see 404 (Not Found) errors on all of my calls to .php files.
I'm using jQuery's getJSON to get data:
$.getJSON('bin/myFile.php', function(data) {
// Process data
})
Then in the browser console I see:
GET https://mysite.azurewebsites.net/bin/myFile.php 404 (Not Found)
But, if I move that file to the root directory and drop the bin/ from my call, it works perfectly. All other calls to files in folders work fine (images, scripts, styles), only the php files in the bin folder return this error.
Anyone know why?

Answer from comments:
Try renaming your bin folder. That is normally where binary files are placed in a windows web app environment, so it's possible the Azure server is configured to not serve any files from that location –
Rory McCrossan
Sep 26 '17 at 16:22

Related

PHP unable to identify sqlsrv_connect() function while trying to connect SQL Server

I'm trying to connect to my local SQL Server from a simple PHP file using the sqlsrv_connect() function, but every time I'm calling the file in the browser through localhost, it's throwing a 500 (Internal Server Error) saying:
PHP Fatal error: Uncaught Error: Call to undefined function sqlsrv_connect() in C:\inetpub\wwwroot\AJAX_Tutorial\get_db_data.php:4
get_db_data.php is the file from which I'm trying to connect the server. Seems like PHP or the localhost can't identify the sqlsrv_connect() function. But as far I'm concerned, I did all the needful to make sure PHP connects the SQL Server.
My environment: Windows 10 Pro, Version 21H2, 64-bit.
What I have done:
Enabled IIS ensuring CGI/Fast CGI is working.
Installed PHP 8.1.1 non-thread safe x64 version at C:\Program Files\PHP-8.1.1
In C:\Program Files\PHP-8.1.1, renamed php.ini-development file to php.ini
In the php.ini file, uncommented the extension_dir = "ext" directive.
Downloaded php_wincache.dll and added it to the default ext directory of PHP.
Added the line extension=php_wincache.dll at the Dynamic Extensions section of the php.ini file.
Installed PHPManagerForIIS_V1.5.0 and configured IIS accordingly so that PHP can be hosted through IIS. Also enabled the php_wincache.dll extension here.
Installed SQL Server 2019 Developer Edition along with the respective Management Studio.
Created the respective database and tables in SQL Server that I want to connect to from PHP.
Ensured Microsoft ODBC Driver 17 for SQL Server is installed in my PC, that is required by PHP.
Ensured Microsoft SQL Server 2012 Native Client is installed in my PC, that is required by PHP.
Downloaded Microsoft Drivers for PHP for SQL Server 5.9 and extracted its contents. Copied the file named php_sqlsrv_80_nts_x64.dll in the package and pasted it in the default ext directory of PHP.
Added the line extension=php_sqlsrv_80_nts_x64.dll at the Dynamic Extensions section of the php.ini file.
In IIS Manager, through PHP manager, enabled the php_sqlsrv_80_nts_x64.dll extension. Created a phpinfo.php file in the root of the IIS, which ran successfully but found no mention of wincache and sqlsrvin it.
After the steps above, I ran the actual PHP file trying to connect the SQL Server, but it's throwing an error saying it can't identify the sqlsrv_connect() function. Assuming the php_sqlsrv_80_nts_x64.dll not being loaded while PHP is starting, I ran php --ini in the command prompt.
That's when the following messages are being thrown:
PHP Warning: PHP Startup: Unable to load dynamic library 'php_wincache.dll' (tried: ext\php_wincache.dll (The specified module could not be found), ext\php_php_wincache.dll.dll (The specified module could not be found)) in Unknown on line 0
Warning: PHP Startup: sqlsrv: Unable to initialize module
Module compiled with module API=20200930
PHP compiled with module API=20210902
These options need to match
in Unknown on line 0
Configuration File (php.ini) Path:
Loaded Configuration File: C:\Program Files\PHP-8.1.1\php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)
However, PHP seems to be running fine, because when I used jQuery AJAX get() and post() method from an HTML file to fetch data from another PHP file, I was successful in doing so. No exception was thrown then.
So what am I missing now that neither php_wincache.dll and sqlsrv seem to load during PHP startup, nor can I connect the SQL Server from the PHP file? As I'm new jQuery AJAX and PHP, I'm not much aware of the intricacies of them and hence, stuck with the issue for the past four days. I've used every resource in my hand, but nothing is working. Please help. I can't get ahead with my tasks because of this.
get_db_data.php code:
<?php
$serverName = "(local)"; // Optionally use port number (1433 by default).
$connectionString = array("Database"=>"TestDB"); // Connection string.
$conn = sqlsrv_connect($serverName, $connectionString); // Connect using Windows Authentication.
if($conn === false) {
echo "Connection could not be established.<br/>";
die(print_r(sqlsrv_errors(), true));
} else {
echo "Connection established successfuly.<br/>";
}
sqlsrv_close($conn); // Close connection resources.
?>
Thanks and Regards!
I found the root of the problem, i.e., version mismatch. While I was using PHP-8.1, I downloaded the SQLSRV for PHP-8.0. Because of this match the driver file wasn't loading during the start of the PHP in the server. Downgrading to PHP-8.0 solved the issue.

Assets not fetched on cpanel server

I'm trying to work on cpanel before hosting my own website. And I'm very much new to this. After uploading my files on cpanel, I am getting the error and the assets folder is not read & my css & js files are not found. On localhost everything is working fine but on cpanel its not working.
I keep getting this error net::ERR_NAME_NOT_RESOLVED.
I tired looking for a solution, but most of them were regarding localhost, but the files are working on my localhost but not on cpanel.
Can anybody help me please.
Console errors:
Network JS headers:
I figured it out, the problem was the domain name, which direct the http request to the assets folder, but here I was using a free domain name that i got from infinityfree. And when i tried running the same link on a different cpanel with purchased domain name, it's loads up just fine.

For the ajax url shows 404 on the AWS tomcat log

I was using MVN install deploy my code on the AWS tomcat. I did this by directly open the AWSname:8080/manager/html and upload the WAR file(I am not sure if it is the correct way). The server can load the index.html successfully as my expectation and shows page on the front-end, but error went to call AJAX, which is in Javascript file, it always return 404. The servlet's url pattern will be like this
AJAX
Login Servlet
I tested everything fine on my localhost:8080, but in the AWS tomcat, the log showed like this.
Tomcat Log
I've never met such a case before, could somebody give me some useful suggestions on the possible solutions?
from your description it is not clear if you have multiple apps/war/containers/servers.
From your message you have a UI, which seems not to be bundled into your war file. To check in this case use these steps to check your setups
Add a index.html to your root in the war file and test if you can access it locally.
if this works, deploy on AWS and try to access the same path on AWS.
if the page is showing, your context is defined well on AWS. So you have an issue with your URL mappings
But if it does not show, you have a URL problem (wrong URL on AWS)

Run Meteor from within a folder

I've run meteor build to create my bundle, uploaded to the server, it runs fine, however the .css and .js paths are wrong, as it's using the root url. I need to run this from within a /project folder. Again it's running, but 404 on the files as they're not prefixed with /project.
eg. http://domain.com/65d054cb90ff094804072528d222178ddbf625e22.js?meteor_js_resource=true 404 (Not Found)
needs to be http://domain.com/project/65d054cb90ff094804072528d222178ddbf625e22.js?meteor_js_resource=true
I've tried using ROOT_URL=http://domain.com/project node main.js, that gives an unknown path error, i've also tried using Meteor.absoluteUrl('project', {}); in conjuntion with rooturl but again, no avail.
Any of you fine people have any ideas? :) Thanks!
PS. It's running on an apache server with ProxyPass, if that's of relevance.
You could instruct your apache to redirect those calls with a ProxyPassMatch, such as:
<LocationMatch ^/(.*)meteor_js_resource=true$>
ProxyPassMatch http://localhost/project/$1meteor_js_resource=true
</LocationMatch>

D3.js: Treemap doesn't load from JSON file

I am trying to run this very example of a treemap on localhost, but I can't load the JSON file (which, by the way, is the same JSON file that the example uses).
The console returns the next error in Google Chrome:
XMLHttpRequest cannot load file:///C:/Users/Usuario/Downloads/d3/flare.json. Cross origin requests are only supported for HTTP.
The JSON file is in the same folder as the html file.
Thanks in advance for your help.
You cannot load local files because of the security policy. To quote the D3 website:
When developing locally, note that your browser may enforce strict permissions for reading files out of the local file system. If you use d3.xhr locally (including d3.json et al.), you must have a local web server. For example, you can run Python's built-in server:
python -m SimpleHTTPServer 8888 &
or for Python 3+
python -m http.server 8888 &
Once this is running, go to http://127.0.0.1:8888/.
If people working d3.js on the xampp or wamp they can run their html file as like php file by starting the server.
I found the same issue then I started the wampp server then the file get loaded successfully without any issue like "XmlHttpRequest Access control allow orgin".
I am working in WAMP. I hope same thing for XAMPP, but I am not sure...

Categories