# php not working[SOLVED]

## manji_

I have emerge both apache2 and php(with apache2 use flag), and "/etc/conf.d/apache2" contains the line: 

APACHE2_OPTS="-D DEFAULT_VHOST -D INFO -D LANGUAGE -D SSL -D SSL_DEFAULT_VHOST -D SUEXEC -D PHP5"

 , but something seems to be wrong. Whereas projects like phpmyqdmin and phpsysinfo appear nicely on my browser, the same doesn' happen for php scripts i write. For example phpinfo() show ablsolutely nothing. Can anyone help me what to check?Last edited by manji_ on Thu Dec 27, 2007 9:37 pm; edited 2 times in total

----------

## poly_poly-man

 *manji_ wrote:*   

> I have emerge both apache2 and php(with apache2 use flag), and "/etc/conf.d/apache2" contains the line: 
> 
> APACHE2_OPTS="-D DEFAULT_VHOST -D INFO -D LANGUAGE -D SSL -D SSL_DEFAULT_VHOST -D SUEXEC -D PHP5"
> 
>  , but something seems to be wrong. Whereas projects like phpmyqdmin and phpsysinfo appear nicely on my browser, the same doesn' happen for php scripts i write. For example phpinfo() show ablsolutely nothing. Can anyone help me what to check?

 

Your scripts are probably done wrong  :Very Happy: 

Okay, this is a quickly hacked together script for you to put on your site:

```
<html>

<body>

This is regular text<br>

<?php

echo "This is PHP text<br>";

?>

This is regular again.

</body></html>

```

See if that works...

poly-p man

----------

## hoacker

 *manji_ wrote:*   

> ...projects like phpmyqdmin and phpsysinfo appear nicely on my browser, the same doesn' happen for php scripts i write. For example phpinfo() show ablsolutely nothing. Can anyone help me what to check?

 

Please post your phpinfo-script (I assume it's just a few lines).

And, can you give us the path phpmyadmin or phpsysinfo is installed in and the path to your script that does not work.

----------

## manji_

Thank you very much for your answers. But, now i am confused...

Opening this simple html file

```
<html>

<body>

This is regular text<br>

<?php

echo "This is PHP text<br>";

?>

This is regular again.

</body></html> 
```

gives me this on firefox:

```
This is regular text

"; echo 'This is PHP text

'; ?> This is regular again.
```

but this on Konqueror...  :

```
This is regular text

 This is regular again.
```

Moving the file to /var/www/localhost/htdocs/ , doesn't change anything.

Running this simple php script:

```
<?php phpinfo(); ?>
```

from my home directory, shows me nothing, but after i move it to /var/www/localhost/htdocs/ , it is displayed correctly.

phpmyadmin and phpsysinfo are located in their directories in var/www/localhost/htdocs/

It doesn't make any sense to me...

----------

## hoacker

 *manji_ wrote:*   

> 
> 
> Running this simple php script:
> 
> ```
> ...

 

Php scripts are executed if you access them via http protocol but not if you open them on the file system.

When the url in your browser is

```
file:///var/www/localhost/htdocs/phptest.php
```

or

```
file:///home/username/phptest.php
```

the php script is not executed. Instead you have to open

```
http://localhost/phptest.php
```

----------

## manji_

 *Quote:*   

> Php scripts are executed if you access them via http protocol but not if you open them on the file system. 

 

Thnx, i was not aware of this.

But still, why doesn'y php work correctly? phpinfo() works, but I have an index.html file(with the code mentioned before) in htdocs, and browsing to localhost gives me:

```
This is regular text

"; ?> This is regular again.
```

----------

## hoacker

 *manji_ wrote:*   

> 
> 
> ```
> <html>
> 
> ...

 

The php snippet inside the html file is not recognized as a php script. It is assumed a comment instead. The html parser in konqueror seems to identify the tag "<? ?>" correctly, while firefox closes it with ">" of "<br>".

Nevertheless, the script should be executed anyway. There seems to be a misconfiguration (as well on my machine here) of apache...

----------

## poly_poly-man

that's funny - it works on my server...

are echo's different in PHP5?

poly-p man

----------

## misterbob05

the code that he posted needs to be put into a file with a extension .php not .html

ok well it doesnt work on myserver either and im running php 5 but echos work just the same

i think it has to do with the html code im not too sure

----------

## hoacker

 *misterbob05 wrote:*   

> the code that he posted needs to be put into a file with a extension .php not .html

 

But it should be possible to include php code in html files when including in in a "<?php ?>" tag, as suggested by poly. This does not work for manji_ and me, the php code is not interpreted but treated as a comment. So, I assume a misconfiguration of apache.

----------

## poly_poly-man

 *hoacker wrote:*   

>  *misterbob05 wrote:*   the code that he posted needs to be put into a file with a extension .php not .html 
> 
> But it should be possible to include php code in html files when including in in a "<?php ?>" tag, as suggested by poly. This does not work for manji_ and me, the php code is not interpreted but treated as a comment. So, I assume a misconfiguration of apache.

 

Actually, I was under the impression that all php code had to be in a .php - that link is test.php, not test.html....

/me tests that theory out

Nope, doesn't parse within .html files....

poly-p man

----------

## hoacker

 *poly_poly-man wrote:*   

> 
> 
> Actually, I was under the impression that all php code had to be in a .php - that link is test.php, not test.html....
> 
> 

 

Yes, right, I was mistaken. In the default configuration only .php files are parsed.

----------

## manji_

Ok, thnx alot guys. I shall never put "<?php ?>" tags inside html files again!  :Smile: 

----------

