I'm using sftp to reach my folder on a server at uni. Both chrome and firefox would download my simple test.php instead of opening the page.
Is there any suggestion where should I look with the preferences to change this? (Ubuntu 16.04)
Oh, okay I understand it now, my bad.
I literally mounted the server to my local machine with ssh, thus I had no server whatsoever.
I had to reach directly with the url to open it, so I couldn't just open it from editor (VS Code - open with browser).
Your webserver isnt passing the php file to php for processing and is just sending it on as it would any other file. You will need to ensure that your webserver is setup to handle php correctly be it php-fpm for apache and nginx or the php module for apache
What's the webserver? You can start to read here: http://php.net/manual/en/install.php
Related
It is possible to open a txt file from desktop to my webserver?
I have tried fopen but It cant open the stream.
Code:
$txtfile = fopen("C:\Users\steve\Desktop\AntiCheat.txt","r");
echo $txtfile;
The Error message:
Warning: fopen(C:\Users\steve\Desktop\AntiCheat.txt): failed to open stream: No such file or directory
This works fine If I using XAMPP but on my webserver it does not works
This works fine If I using XAMPP but on my webserver it does not works
XAMPP is a package that includes a web server, so presumably, you mean that it doesn't work if you use a web server that is running on a different computer.
This shouldn't be a surprise as the other computer won't have your hard disk in it, so it won't have your C drive or your files.
You need to either:
Share your file over the network to the computer running the web server (since the web server probably doesn't run on your LAN, this is likely to be logistically challenging).
Copy the file to the computer running the web server.
I'm trying to download a file locally from a remote server but every time i access the file that contains the PHP code using the browser file_get_contents() fails because it doesn't have the permission to write to /var/www/html (Apache2). I tried using cURL but that didn't work either, checked to see if allow_url_fopen is on (it is) and added the php file to sudoers. I can't seem to find any solution online.
i think this is permission issue, see this maybe will solve your problem, pick that suit to your enviroment.
I installed php and apache2 correctly, I am able to open localhost/index.php. Index.php is located in /var/www.
However when I open port 8000 by python -m SimpleHTTPServer 8000, localhost:8000/index.php will not be opened, the browser will just to start to download it.
I also add Listen 8000 in ports.conf.
What else do I need to change to make it work properly?
One more question, what do I need to change make php work in all files not just /var/www?
Thanks
You're using python to respond to the HTTP request, not Apache, so Apache never gets a chance to execute index.php.
Try Google to learn how Apache works.
I just solve my problem. I edited apache2.conf and add 8000 port, then I change the document root to my home directory.
Could anyone please tell me how to run a php file locally on my system.
Currently I am using a server to run files.
I know both php & Apache to be installed.
I need to see out put of this program, for example:
<?php
$a=5;
$b=10;
$c=$a+$b;
print $c;
?>
Can you please tell how I can run these files of if I need anything more.
php have a easy way to run a light server:
first cd into php file directory, then
php -S 127.0.0.1:8000
then you can run php
You have to run a web server (e.g. Apache) and browse to your localhost, mostly likely on port 80.
What you really ought to do is install an all-in-one package like XAMPP, it bundles Apache, MySQL PHP, and Perl (if you were so inclined) as well as a few other tools that work with Apache and MySQL - plus it's cross platform (that's what the 'X' in 'XAMPP' stands for).
Once you install XAMPP (and there is an installer, so it shouldn't be hard) open up the control panel for XAMPP and then click the "Start" button next to Apache - note that on applications that require a database, you'll also need to start MySQL (and you'll be able to interface with it through phpMyAdmin). Once you've started Apache, you can browse to http://localhost.
Again, regardless of whether or not you choose XAMPP (which I would recommend), you should just have to start Apache.
In short:
Install WAMP
Put this file to C:\wamp\www\ProjectName\filename.php
Go to browser: http://localhost/ProjectName/filename.php
I just put the content in the question in a file called test.php and ran php test.php.
(In the folder where the test.php is.)
$ php foo.php
15
If you have apache running, put your file in server folder for html files and then call it from web-browser (Like http://localhost/myfile.php ).
Running PHP script directly in browser:
Here are all steps (in short) to run PHP program in XAMPP
Step 1: First of all, open the Apache Friends website, The download and install XAMPP for Windows.
Step 2: Open the XAMPP Program Control Panel and start “Apache Web Server”.
(NB: If your PHP scripts need MySQL database to work, Start “MySQL” service as well)
Step 3: Create a new folder inside “htdocs” folder. For example: “php-project”
Path looks like: C:/xampp/htdocs/php-project/
Step 4: Open any text editor and create a new file and write a simple PHP program then Save it with .php extension as “example.php”.
Path looks like: C:/xampp/htdocs/php-project/example.php
<?php
echo “Hello Level 5 Developers”;
?>
Step 5: Go to the browser and type “localhost/php-project/example.php” in the address bar and press enter then it gets executed.
Step 6: After that, you can see the output of your first PHP program like this:
Hello Level 5 Developers
3 easy steps to run your PHP program is:
The easiest way is to install MAMP!
Do a 2-minute setup of MAMP.
Open the localhost server in your browser at the created port to see your program up and runing!
question is how to give command line (in .cmd script) to execute browser to then in turn have browser execute .php script.
Presently if from a command window I execute like ...
"c:\Program Files\Internet Explorer\iexplore.exe" file:\c:\users\win7ultsdtest\findroot.php
....OR....
C:\Program Files\Internet Explorer\iexplore c:\users\win7ultsdtest\findroot.php
This will run the Explorer browser, but then the browser the browser will download the contents of findroot.php instead of executing the php code as I need. Does anyone know how I can get the browser to instead execute the php code and not just download it as data?
Let me explain my need ... The findroot.php file contains php code to access the $_SERVER['DOCUMENT_ROOT'] variable. This variable is ONLY non-null when the localhost is running a http server and then it contains the localhost document server root path where loadable browser .html, .php etc may be stored to loaded from http:\ lines.
The findroot.php outputs the $_SERVER['DOCUMENT_ROOT'] contents to a file as rootpath.txt so that my .cmd script can then can automatically install PHP code into the active PHP servers document root area.
So understand I must find the $_SERVER['DOCUMENT_ROOT'] from a .cmd script.
Now I might search ALL the computers drives for httpd.conf and then scan that file for the value but this wouldn't work for two reasons; 1. there can be multiple httpd.conf files and I can't know which server is active and using what httpd.conf. 2. it would take a long time to search a given computers entire drive(s) on all httpd.conf files.
The browser won't execute PHP code. You either need a server to run PHP and to access it via HTTP such as C:\Program Files\Internet Explorer\iexplore http://localhost/url/for/findroot.php or you can run PHP via the command line c:\path\to\php.exe c:\users\win7ultsdtest\findroot.php. However running it via the command line won't give you $_SERVER['DOCUMENT_ROOT'] as that is only populated when running PHP within a server.
It's not possible to execute PHP by the HTTP server without the server knowing about the PHP before hand - for example, by being in the document root. Of course if you don't know the document root, your script won't be there. If you're trying to install a script into a web server for a user, it's much better to give instructions on how to do so as their server environment will likely vary from what you expect.
There are light browsers like lynx if you are in a linux machine
lynx http://whateverurl/php.php