local PHP & local node.js (react-native) - php

I have a local Apache server using XAMPP which runs on port 80 and uses a local PHP file.
In the browser I can open this file from localhost/test/test.php and localhost:80/test/test.php.
I also have a react-native app, and it starts an NPM server on port 8081.
In this app I want to make a request to the local PHP file, but when I make the request it returns a 404 error.
I understand that it happens because the NPM server doesn't know about the local Apache server so I want to understand how to combine them.
Thanks.

don't write 'localhost/test/test.php'
You have to write with your ip, like this => '192.16x.x.x/test.php/'

Related

Bottle web server - how to serve PHP file?

I am working on a webapp made by someone else which uses Bottle routing. I want to create a simple login page which requires some PHP. If I return the PHP page as a static_file, any HTML will be executed but PHP won't, for obvious reasons. How should I serve the PHP file so that it is dynamic?
Not working:
#route('/login')
def serve():
return static_file('login.php', root='.')
In order to server PHP files, you need to have PHP installed on the web server. Additionally, the webserver needs to be configured to detect PHP files and execute them.
Serving PHP files from Python is kinda useless and not recommended.
I'd recommend you to take the time to translate this script from PHP to Python.
I wanted to do the same thing yesterday, but the answers I got to my question made it clear it was either impossible or extremely difficult. I came up with writing a small python program to run the PHP built in server. NOTE: PHP needs to be able to run from the command line for this to work.
#Import the os package so that this code can run commands
import os
#Get the port that the user wants to host on
port = str(input("What port would you like to host on?"))
#Add wanted port to the command that hosts the php server
cmd = "php -S localhost:" + port
#Actually run the command to host php server
os.system(cmd)
#Now the PHP server will take over until you
#use ctrl + C to quit hosting
Just remember that the port needs to be 4 numbers. When you host this, you can return any file from the folder you ran this code in by simply typing it in the browser. Example:
localhost:8080/login.php
Returns login.php (if it is there) on the localhost port that you asked for.

Unable to execute "testphp" from localhost

I installed LAMP from unixmen.com, but I am not able to run the php script using localhost. It says:
Not Found The requested URL /html/testphp.php was not found on this server. Apache/2.4.18 (Ubuntu) Server at localhost Port 80
Note! My apache server works fine.
Have you started your lampp server?
terminal command is
sudo/opt/lampp/lampp start
provided that is where lampp is installed.
Also the url should be http://localhost/name_of_your_project/testphp.php
first question: this file is first .php what executed in new serve?
case yes: make sure your server is started:
sudo/opt/lampp/lampp start
verify permission in your file.
or
try access using IP 127.0.0.1
http://127.0.0.1
your directory html are sub \var\www\html ?
try move to one level up
Regards

Laravel angularJS local host cannot be accesed from another computer inside my network

I have a proyect that is working on my main machine. I use the php -S localhost:8080 -t public command to start a local server. It works perfectly. But now I want to access it from another computer inside my own network but it does not work. In my other computer I type the ip address of the computer with the php server running like this 192.168.1.135:8080, but it does not connect. It just gives me timed out error. Any ideas on how to make this work?
I figured it out. Instead of localhost:8080, I changed it to 0.0.0.0:8080. That did the trick.

php exec not working properly on remote server

php functions like exec and shell_exec work fine on localhost but it doesn't work properly on remote host.
$output = shell_exec('dir');
echo "<pre>$output</pre>";
This code gives output in localhost but not at remote server.
Any Clue?
This kind of php commands are usually disabled on remote web servers. If you really want them to works, you should use a dedicated server and configure it yourself.
dir command is in windows system, so is your remote server a windows server too?
Even it is a windows server, the configure may be different from your local machine that disables shell_exec
Take a look at http://php.net/glob or http://php.net/manual/en/class.directoryiterator.php
Executing dir or ls makes no sense at all, to me.

Nginx and PHP-cgi - can't file_get_contents of any website on the server

This one is best explained by code I think. From the web directory:
vi get.php
Add this php to get.php
<?
echo file_get_contents("http://IPOFTHESERVER/");
?>
IPOFTHESERVER is the IP of the server that nginx and PHP are running on.
php get.php
Returns the contents of the (default) website hosted at that I.P. BUT
http://IPOFTHESERVER/get.php
..returns a 504 Gateway Time-out. It's the same with curl. It's the same using the PHP exec command and GET. However, from the command line directly it all works fine.
I've replicated it on 2 nginx servers. For some reason nginx won't allow me to make an HTTP connection to the server its running on, via PHP (unless it's via the command line).
Anyone got any ideas why?
Thanks!
Check that your not running into worker depletion on the PHP side of things, this was the issue on my lab server setup which was configured to save RAM.
Basically I forgot that your using a single worker to process the main page been displayed to the end-user, then the get_file_contents() function is basically generating a separate HTTP request to the same web server, effectively requiring 2 workers for a single page load.
As the first page was using the last worker there was none avaliable for the get_file_contents function, therefore Nginx eventually replied with a 504 on the first page because there was no reply on the reverse proxy request.
Check if allow_url_fopen is set to true in your php.ini.

Categories