Beginner Question PHP (ServerQuestion) - php

Hy!!
I just get a vserver running debian. I just installed apache and php. Now the server should support php.
i uploaded the file index.php:
<?
echo "Hallo";
?>
The problem is if i start a request to the site my browser wants to download a file.
Whats could be the problem?
THX

have you restarted apache after installing PHP?
/etc/init.d/apache2 restart

This could mean that the Mime extension of the File is not registered with the web server which means you will need to check if you have the PHP Interpreter installed as a extension/plugin in your server.

Try:
<?php
echo "Hallo";
The short_open_tags is disabled in may distributions by default. If you have to support legacy pages you can anable them in php.ini, if not then just use the above, your code will be more compatible.

Your server isn't set to parse PHP files before they are output.
Check out these pages:
http://www.phpbuilder.com/board/archive/index.php/t-7100332.html
http://www.petefreitag.com/item/516.cfm

If your page works if you changed that to the <?php tags, then vbence would be right, it could be as shanethehat says that you just need to restart apache if you've already made the change to php.ini, one of the joys of all these things working together you need to work through all the options to find out where these things fall down so you know where to start looking to fix it
(Found why it wasnt displaying, I hadnt put code round the php tags)

Related

PHP: <?= not working / Apache configuration issue?

I've ran into this issue before but don't remember what was causing it. I have a small app that uses the shorthand notation to print variables, <?=$myvar?>, but it doesn't seem to get parsed by the webserver?
Any ideas on what might be wrong here? It's a bit weird since everything else is working ok.
Thanks!
its a short open tag with an echo command (=). since php 5.4 its no longer marked as short open tag and therefore works even with php.ini setting short_open_tags set to off beginning with that version. for earlier versions it depends on that option.
more information:
http://php.net/manual/en/ini.core.php#ini.short-open-tag
you can check that option e.g. using $sot = ini_get('short_open_tags');
It may be turned off in the PHP configuration. Did you try adding this to your script?
<?php
phpinfo();
?>
Anyway, try to avoid short tags because they're good for nothing except creating a portability issue. :)
Not only check for the short_opened_tags but also be sure that AddHandler application/x-httpd-php .php is in your http.conf file. If its not there please add it and restart your apache server.

local php files will not work

I have to do a php project. I done php before so I understand the syntax for the most part. Just for a test, I made a file.php and in it I wrote:
<html>
<body>
<?php echo "helloWorld"; ?>
</body>
</html>
Well it won't display. The screen is blank. I tried it in chrome, firefox, IE and nothing wants to dispaly. Actually in IE, the source is displayed which is wierd. I also tried it without all the html and just used xampp to render it. It will not work. If I right click tho in the browser and view source, the code is there. Any ideas on what's going on?
Well, it comes from your web server configuration. If you're using Apache, have you enabled the mod-php module?
If you're new to setting up your own server, i would recommend using XAMPP (or WAMP), these are preconfigured PHP, Apache and MySQL servers.
If you're sure you have setup your server correctly check the following:
Make sure your executing your files from the server directory and NOT from a local directory. (your URL should look something like "http://localhost/test.php")
Note: You will need to phisically store the files in a place the apache server will look for, an example from XAMPP (on Windows, as thats what im assuming your using) is: "C:\xampp\htdocs"
Make sure your file ends in .php or something else that the Apache server will pickup as a PHP file. (.php3, .php4, etc)(make sure you didn't accidentally leave a .txt or something like that at the very end)
Check mod-php module is enabled (as Julien mentioned)
Hope that helps!
Edit:
Try
<?php
phpinfo();
?>
That as well, it should give you the php configuration information if the server is setup correctly.
EDIT2:
I see that you are using XAMPP, double check that the following file exists at the very least:
"C:\xampp\apache\conf\extra\httpd-xampp.conf", it loads the PHP module

PHP script not running on browser

I have installed XAMPP server on my system to be able to use PHP. But after installation, when I run any php script on the browser it does not run. I do not see any ouput. No checking the phpinfo() from local host I see that version 5.3.5 is installed
Even when running a a simple php file like where I echo a line;
I do not see anything on my browser. So, my question is do I need to make any configuration changes to my browser or system to get PHP running.
Put your scripts into /XAMPP/htdocs and then point your browser to: http://localhost/your_script.php
Your best bet is taking a look at your log files, and perhaps turning error reporting on. Put a simple script in your webroot that simply echo's a string, for example:
<?php echo "Hello World!";
with the above there is very little that can go wrong. Work from there. Take a look at your phpinfo, and see where your log files are located. Search for
error_log
for the path to your PHP error log file and maybe see if
display_errors
is on.
This is something that has a multitude of possibilities that can be the cause of your problem.
install phpxx-php which is used for creating dynamic web sites
check version of php using php -v
if you have php55 then use:
yum install php55-php.x86_64
Ensure to save file as .php ; e.g. index.php and not index.html
From Troublespy here are the reasons why php might not be working in the browser:
You did not download a local server
You are using the wrong version of php
You put your scripts in the wrong directory
You have a php error and the error didn't get printed
Your php code is wrong or incomplete
Make sure you check all reasons.

web browser not processing PHP code as PHP code

I have Joomla installed in my computer, but recently have been writing php files that aren't related to the Joomla-managed site. For some reason, when I try to open those php files in the web browser using xampp (note: Joomla also is using xampp), the browser doesn't process the code w/in the tags as php code.
For example, after opening a basic page (a page with title "test", no content except in the body tags) in the web browser and going to the source code, the following is shows up in the source code:
<body>
<?php echo "hello"; ?>
</body>
instead of the HTML conversion. (i.e. just "hello")
Does anyone have an idea about what's going on here?
Thanks.
It's probably because PHP module isn't loaded in your apache. Be sure it is enabled
PHP is interpreted in the server, not the browser. Whatever's going wrong, you need to look at the SERVER side to resolve it.
My first guess: maybe you didn't suffix the file ".php" (so the server doesn't recognize it as a PHP file?)
Second guess: is the directory containing your PHP files configured to parse PHP?
If you have Joomla, you probably have PHP. You probably also have Apache.
So check your Apache configuration, and check your file naming conventions.
Is the file extension .php? The server doesn't magically know when you're serving php files, this is a good way to ensure it knows what you're doing.
Apache is looking into your localhost's defined root directory for files it can parse. In this case htdocs. This is the default for XAMPP. As far as Apache is concerned, it will not interpret any files outside of that folder.
if the problem in php module it better to re install php5 in to the system and it will work fine. probably the problem is in php module you should try re installing php in your system.
Just restart httpd service. It will work fine.
sudo systemctl restart httpd.service
if it has not worked please reinstall PHP once again.

Just one PHP page won't run - it wants to download

All PHP pages are all running just fine on my site, except for one for which Firefox says "You have chosen to open checkpage.php which is a PHP script" and then wants me to select an application with which to open it.
The site is running PHP Version 5.2.10 on Centos 5.5.
I'm using exactly the same code on another site (PHP Version 5.2.10-2ubuntu6.4 on Ubuntu 9.10) and it's fine.
I've Googled myself silly trying to work out what the issue is!
Does anyone have any ideas why this one page might be causing a problem? The page is about 200 lines long but I'll post it here if it'll help...
All thoughts much appreciated
Mike
PasteBin: http://pastebin.com/A6uNj9CN
Last time I had this problem, I just installed PHP on my server. Worked fine after I rebooted it. Hope that helps.
Does the file that's downloaded have any content? Or is it zero bytes? It's possible something's causing PHP to puke on that script before it sends out any headers and so the browser has no choice but to interpret it as a download of a .php file with no content.
Check the server's error logs (and PHP's as well) to see if anything's showing up in there.
Is there a separate htaccess in the folder that stops apache from sending it to php or changes the mime-type? Does the file have a different extension than other files on your site?
Use something like a packet sniffer, or HTTP Debugger, to see what headers are actually sent by the webserver. That will help you, and us, debug the issue.
Call curl -I http://blahblah/foo.php and look at the content-type header. That will help point you in the right direction. Is it text/html or something else?
Try to change the permission of the file from 775 to 644 or try changing the permissions. Note: change to the correct permission type to avoid public viewing of the files

Categories