Blank php page over Apache - php

I have installed php 7.0 and the apache2 server on my machine and made sure that the apache server is running (when I go to localhost, it shows the index.html page). I created a testdirectory, set the right permissions for it and placed a sample hello.php file in there. All it contains is:
<?php echo "it's working fine"; ?>
When I go to localhost/testdirectory I can see my hello.php file in the index, but when I click on it, there is no output.
However, if I run the php file through cli, I get the output, so the php is working fine.
Please tell me where am I going wrong?

Related

When i ran php file in HTML , it didn't actually show up the result code that was expected

I ran this in chrome browser but it didn't show the expected results...
It showed the exact same code which was written
<!DOCTYPE html>
<html>
<body>
<?php
echo "My first PHP script!";
?>
</body>
</html>
To run PHP code in your browser, you need a server like XAMP, WAMP, etc. I recommend XAMPP as it is quite easy to use.
Download XAMPP from here: https://www.apachefriends.org/index.html
After the installation is done, go the the htdocs folder (C:\xampp\htdocs in windows) and paste your .php file there. After that, open XAMPP control panel and start Apache. Open http://localhost/test.php (assuming the filename is test.php) in your browser and see the result. Done!
Before working on PHP Codes. You should know how to run PHP codes in browser.
If you dont have any server then please install some server like XAMPP, WAMP, etc.
Also, If you have installed the server then might be the file you are running on browser has html extension. It should be a .php extension.
& should run using
http://localhost/test.php (If its in htdocs folder)
I suggest you to see the below documentation before working on PHP.
https://codeofaninja.com/2013/06/how-to-run-a-php-script.html

Apache downloads PHP files instead of displaying in browser when called via CMD (Ubuntu)

I've installed LAMP on my Ubuntu laptop with no apparent problems and successfully did the phpinfo() test by navigating to the file through the browser. But the same file is downloaded instead of executing when I'm trying to build from Sublime Text 3 using the following script:
{ "cmd": ["/opt/google/chrome/google-chrome" ,"$file"] }
That worked the first couple of times I tested it, but stopped right after I changed the name of the build system and hasn't been functioning since even after I reversed the change. How would I go about fixing the issue?
$file is "The full path to the current file, e.g., C:\Files\Chapter1.txt.".
Apache isn't causing the file to be downloaded; you aren't requesting it from Apache.
You need to translate $file into a URL on your HTTP server.

Call to PHP prints source, doesn't run when called from another file

I have a quick question that I can't figure out. I've tried searching Google and following examples, but I can't find anything.
I have an HTML form that I'm trying to process with a PHP file, but when I submit the form, it merely prints the source of the PHP file, it doesn't execute it. If I run the PHP file by itself (not indirectly through the HTML button), it works fine.
HTML form header:
<form id="registrationform" name="registrationform" method="post" action="processregistration.php">
Submit button:
<button type="submit" value="Submit" >Create</button>
The PHP form is just <?php print "Hello"; /?
Again, it runs fine if I just run the PHP file, but prints the PHP file (doesn't run) when it gets called through the HTML form.
Any help is appreciated.
edit-Running locally through Coda
edit-Here is the output that I'm getting:
Output when the PHP is called through an HTML action:
</php
print "Hello";
?>
Output when I run the PHP directly through Coda:
Hello
I had the same problem and just fixed it on my coda version 1.7.4
I installed MAMP on my mac and set up the apache path under MAMP preferences to the folder where my sites are located;
/Users/yourUserName/Sites
this points MAMP's 'http://localhost:8888' address to your sites folder, if you paste that on your browser you'll now see your sites folder's content in the browser.
then, all you do is point the local site's connection settings to the site you are testing;
I was going to post an image, but I'm new to the site and wasn't allowed.
Under my site's preferences i set up the addresses as follows;
Root URL : 'http://localhost:8888/yourSiteRootFolder/'
Local URL : 'http://localhost:8888/yourSiteRootFolder/'
Remote Root : /yourSiteRootFolder/
Local Root : /Users/amartinez/Sites/yourSiteRootFolder/
I hope this is related to the problem you're having and helps you fix it.
Line #19 from Coda 1.6 Release notes:
Coda no longer tries to locally
preview a remote PHP file while
editing/previewing
Listed under "Improvement" - doubt they brought it back for the 1.7 release.
I'm running Apache2/PHP5 10.5.8 OS X (no problem reproducing your issue with Coda)
Even when running my form.html and post.php files from /Library/WebServer/Documents folder.
My sample files work fine in the Apache env....I just needed to run them through Coda to "break" them. :-)
Are you sure the html file and the php script are on a server with php support enabled?
I've never used Coda, but you need to be running it through a server (e.g. Apache + PHP). You cannot just open the file itself within Windows.
Try looking at xampp as a quick server for testing.
If it works properly, you should be viewing the PHP file on something like http://localhost/test.php instead of file:///something/test.php.
This may be because you don't have PHP installed on your server. I would check to make sure that your hosting package included PHP, pre installed.
Here are some resources to get you started with that, if not installed:
http://www.thesitewizard.com/php/install-php-5-apache-windows.shtml
http://www.php.net/manual/en/install.php
http://www.w3schools.com/PHP/php_install.asp
Edit: actually, I think I may have found it.
If you look at the starting PHP tag, you have a slash instead of a ?. If that's in your script, just change that to <?php. But it may not be, it could be that's just question format-ing.

php silently ignoring include on localhost, but not on external server

I'm running Ubuntu 10.04 with Apache2 and PHP5.
I have a directory structure like this:
\www\
\index.php
\parts
\head.php
\body.php
Inside my index.php I have a command
<?php include("parts/head.php") ?>
and the equivalent for body.
These files both exist and they contain more php and html code.
The only thing that shows up when I test the website on localhost (\var\www) is the html outside of the PHP commands. There is no error message, it's as if the file is included but empty.
It is exactly the same as on the website (not localhost) but it works perfectly on the website. I don't understand what is different. Any help would be appreciated.
Check your php.ini file to see if "." is on the path?
You could also try this:
include(basename(__FILE__).'parts/head.php');
It's almost always about permissions. When you have something working locally, and then upload and find it doesn't work (include is ignoring file) check the remote files/folders so that you have read/write/execute permissions set as required. (You can do this in FTP) - then run the script again and it should work.

Apache doesn't execute my copied PHP files, but testing.php works

I've just installed LAMP on my Ubuntu 9.10 machine, and everything works fine except when I copy my PHP files from another computer.
The LAMP guides I've followed also made me create a phpinfo() test file, which works, but when I try to type in e.g. index.php absolutely nothing happens - just a blank page in FireFox. :(
The files are in the exact same directory.
I'm thinking it's probably something with permissions and so on, but since I'm new to both PHP and Ubuntu, I'm kind of lost. It's like I can't create a PHP file with my file browser, but only by using the terminal - like when I created the testing.php from the LAMP guide.
Whaddayaknow... I made an error, tried to:
echo "Hello" world
which, even though I'm a PHP noob, I clearly know is wrong.
I think I'll have to figure out how to enable some sort of error reporting, a blank page is clearly not good enough.
You mean you have a index.php (copied from another computer) and a test.php (edited by hand, with a call to phpinfo()) in the same apache directory, the second works from your browser and the first doesnt ?
That can be a permission issue, or some compilation error in your php.
About permissions, for files should be readable from the apache server (more precisely, form the user that runs the apache server). You can type chmod a+r index.php.
YOu can also check your apache error logs (location dependent on installation). In any case it's vital to know where the error logs are if your are developing a web site.

Categories