I am having trouble with several php files.
The problem is when I try to access my WebApp in said php files it results in a 503 error. Both files have API calls to different services that have worked perfectly until yesterday. When I remove the API call from the code the WebApp opens with no problem. I called both API services and they are both getting the API requests made from my server with no problem.
I've already exhausted all options to fix this error but came up with no results.
Any help is valid.
Thank you so much.
I've tried to change PHP version, but as I said there is no problem with PHP. Removing the API call makes the webapp function normally.
Related
I'm trying to learn React by replicating a simple CRUD page I created earlier.
The old CRUD page was a Javascript/jQuery front-end with a form. It sent data via AJAX to a PHP backend page, and the PHP page interacted with a mySQL/mariaDB database.
Everything was locally hosted on my PC on XAMPP Apache, and everything worked fine.
I have now managed to replicate the front end using React, via Create React App and it's running on localhost:3000
I am now stuck. I don't know how to make my front-end (on localhost:3000) send data via AJAX to my back-end PHP page (on localhost:80 running on XAMPP Apache)
There are a lot of us PHP / mariaDB types out there who want to continue using that sub-stack as our back-end. The answers to this question will be enormously helpful in encouraging our crowd to try Create React App and React (I'm loving React btw!). (I was surprised that when I searched [create-react-app] [php] in StackOverflow, I got only 2 hits.)
Update: if this is off-topic for SO, then I'd appreciate suggestions on which SE I should post this on... thanks!
Answering my own question.
The basic problem is one of CORS (cross-origin resource sharing). The error one gets is (in the Chrome console):
No 'Access-Control-Allow-Origin' header is present on the requested resource.
During development only, this issue is easily resolved by adding this line of code to the top of the PHP file:
<?php
header("Access-Control-Allow-Origin: *");
This code should never be left there in production unless you're okay with anyone in the world accessing the PHP file API.
In actual production of this React app, one would expect that the JavaScript and the PHP files would share the same domain, so there won't be a CORS issue.
So on my webserver, I am making a rest api that works perfectly when you visit the page and set get parameters in the URL. I am now trying to add a page where the php access the api and gets the value that it returns, like with the Wikipedia api. I have tested using curl and file_get_contents with multiple sites, and they both worked fine with low loading times. I have also accessed my api successfully from runscope, and it works fine. So why is it that when I try to read my file on my server from the same server, it just loads forever and times out? I have been looking all over for hours and I can't find anyone with this same issue. Should I just host my api elsewhere?
This question already has answers here:
Origin is not allowed by Access-Control-Allow-Origin
(18 answers)
Closed 7 years ago.
I am developing a mobile application that uses js on the frontend and connects to a PHP backend which runs script against MongoDB database to return json data.Now everything was working fine as I tested the whole backend using localhost but now I want to upload the PHP files to some server so that I can test the whole thing using the actual mobile app.
So here's what I have done so far:-
I made my MongoDB database on MongoLab (they have a starter free plan) and I also uploaded my PHP files to google app engine (again for free). But now when I try to call a file using say Postman in google chrome, it shows Access-Allow-Control-Origin error, http://localhost is not allowed. I tried to google to find a solution to this but it didn't prove to be helpful as the error still persists.
So I switched to Amazon aws, fired up an ec2 instance, installed apache and PHP and uploaded my PHP files there, and I got the same Access-Allow-Control-Origin error.
So I guess my real question is can someone just walk me through the process of how I can upload my PHP files and have them connect to MongoDb database and then call them from localhost or from mobile app and have the result given to me.
P.S. - Sorry for such a long post but I just wanted to explain everything.
Add
header('Access-Control-Allow-Origin: http://localhost');
to the top of any page which has the problem.
In trying to follow the Hello Analytics API (https://developers.google.com/analytics/solutions/articles/hello-analytics-api) I have found many issues. I have downloaded it off github as described. The problem is: The API comes with errors itself. Firstly it has many internal (files from within the api to other files within the api) link errors. It does not link correctly to its other files. I was able to fix this
But, some functions that the class in the API provides are incorrect as well. There are errors that exist within the php files the api provides. Such as :
Call to undefined method Google_Http_Request::getItems().
This is due to a incorrect return type
In conclusion the API comes with errors within itself! How has anyone been able to use this API if it causes errors before it can even execute?
Did i download it from the correct location? (https://github.com/google/google-api-php-client)
Is there something causing an error with my server?
I dont understand how the API has errors by itself
Any help would be greatly appreciated.
I had the same problem.
The reason is that the function getItems return bad type in case it fails (http instead of list).
I am currently trying out the Google App Engine for PHP on my local development environment. So far, I have been following the instructions at https://developers.google.com/appengine/docs/php/gettingstarted/helloworld in order to just test out a small app to get used to how the SDK works. However, when I get to the point of loading the test web server using the SDK, I get an error trying to load the very basic helloworld.php example. The command I currently run is:
../GoogleAppEngineSDK/google_appengine/dev_appserver.py --php_executable_path=/usr/bin/php --port=9999 helloworld/
As you can see I use a custom port to avoid conflict with another application that runs on the default 8080. The SDK engine loads fine, but as soon as I try to access my application under localhost:9999 I get the error:
AssertionError("invalid CGI response: ''",)
and the web page itself throws a 500 error.
So far my attempts to correct the problem have yielded nothing and was wondering if there may be something I am missing.
You should make sure you're pointing to the php-cgi executable not php. Not every OS comes with this so you may need to install it. The getting started guide has more detailed instructions.
Just had this issue. Changing my php_executable_path to /opt/local/bin/php-cgi54 did the trick.