LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   UBUNTU 11.10 apache do not process PHP code inside HTML page (http://www.linuxquestions.org/questions/linux-newbie-8/ubuntu-11-10-apache-do-not-process-php-code-inside-html-page-927836/)

dvah 02-05-2012 11:42 PM

UBUNTU 11.10 apache do not process PHP code inside HTML page
 
I installed LAMP on ubuntu 11.10 the test for running PHP file works but I can't get the apache to process PHP code embedded inside the HTML page.
I noticed some comments about adding "addhandler" & "addtype" but the httpd.conf file on ubuntu apache installation is empty and the apache2.conf does not have any such directives.

klearview 02-06-2012 01:14 AM

The problem is most likely basic. So let's start from the beginning. Could you post the results of this first:

Quote:

dpkg -l | egrep 'php|apache'

dvah 02-06-2012 05:28 AM

Klearview
Thanks for your feedback, I managed to resolved the problem I found on another thread that relates to running apache on Windows that I need to add to httpd.conf:

LoadModule php5_module "c:/php/php5apache2_2.dll"
PHPIniDir "C:/Windows"
AddHandler application/x-httpd-php .php
AddType application/x-httpd-php .html .htm

1. My problem was that under ubuntu the httpd.conf is an empty file
2. The first 2 lines seems to be Windows specific

I end up placing the last 2 line in the httpd.conf-
AddHandler application/x-httpd-php .php
AddType application/x-httpd-php .html .htm

This solved the problem and my apache does process the php code inside html pages

I wonder why this setting is not produced automatically during the package installation, I assume that I am not the first one placing PHP inside HTML ......
Do I miss something or this is not the complete fix for the problem?
Thanks

Dvah

klearview 02-06-2012 05:38 AM

"why this setting is not produced automatically during the package installation" - it is, I can't tell what was different in your case but it is.

On Debian and Debian-derived distros like Ubuntu one enables/disables Apache modules and virtual hosts using a2enmod/a2dismod and a2ensite/a2dissite utitlities, in your case:

sudo a2enmod php5.

One should NOT use httpd.conf on Debian/Ubuntu.

dvah 02-06-2012 05:42 AM

the results for: dpkg -l | grep 'php | apache'

ii apache2 2.2.20-1ubuntu1.1
Apache HTTP Server metapackage
ii apache2-mpm-prefork 2.2.20-1ubuntu1.1
Apache HTTP Server - traditional non-threaded model
ii apache2-urils 2.2.20-1ubuntu1.1
utility programs for webservers
ii apache2.2-bin 2.2.20-1ubuntu1.1
Apache HTTP Server common binary files
ii apache2.2-common 2.2.20-1ubuntu1.1
Apache HTTP Server common files

I don't see here the PHP or MySQL BUT THEY ARE ENABLED AND WORKING???

klearview 02-06-2012 06:29 AM

See the command - egrep, not grep!

But I already see that there is no libapache2-mod-php5 - are you running with CGI or PHP-FPM?

dvah 02-06-2012 07:04 AM

I am new to linux and to ubuntu, first time installing so I am not sure how to check:
1. I didn't enable PHP-FPM intentionally so I assume I am running with CGI
2. I checked /etc/apache2/mods-enabled folder and can see there
cgi.load
php5.conf & php5.load
additional modules files, nothing with FPM
3. I checked /etc/apache2/mods-available and se there also
cgid.conf & cgid.load so I assume it is not installed
additional modules files but nothing with FPM
4. I ran dpkg -l | egrep 'php | apache'
and got the same results as grep

I understand that I have some mess here, is the best solution to remove apache/PHP/MySQL and reinstall them properly?

What is the best way to have a clean removal of all LAMP packages?

Thanks

dvah

klearview 02-06-2012 07:42 AM

Quote:

4. I ran dpkg -l | egrep 'php | apache'
Once again, see the command above! There are no spaces, it's 'php|apache', NOT 'php | apache'. Why not just copy/paste the command if you are going to run it anyway? (and a word of caution - do not copy/paste stuff off the Net without understanding what it does)

Quote:

I didn't enable PHP-FPM intentionally so I assume I am running with CGI
- actually either is unlikely because you would have known about it and especially seeing that you have php5 in mods-enabled.

So again - let's establish what you've installed already first.

dvah 02-07-2012 03:47 PM

I decided to reinstall, after installation it did work fine and at a certain point I got again the same problem.
I will try to find out when/what cause it and post a new thread when I know more about the problem
Thanks again for your time and your help
dvah

BBoppie 03-04-2012 03:39 PM

If have installed LAMP via the tasksel command and PHP doesn't doesn't display try using the instructions included in the php.conf file located in the apache2/mods-enabled directory. You will see the following:
<IfModule mod_php5.c>
AddHandler application/x-httpd-php .php .html .htm .file
AddType application/x-httpd-php .php .phtml .php3
AddType application/x-httpd-php-source .phps
<FilesMatch "\.ph(p3?|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>
# To re-enable php in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
# <IfModule mod_userdir.c>
# <Directory /home/*/public_html>
# php_admin_value engine Off
# </Directory>
# </IfModule>
</IfModule>

Do what I did by following the instructions given by the comments...
This for apache server 2.2.1.7 version. Under version 2.2.1.4, I did not have to do this but we talking about software right?

lenberman 05-26-2012 09:10 AM

I believe the reason that php inside html files doesn't work is that the pattern included in the FilesMatch stanza in php5.conf file doesn't match html! It matches phtml. changing the pattern to: <FilesMatch "\.p?h(p3?|tml)$"> (i.e. adding a '?' after the first p) fixes it.

What I'm not sure is whether the patter is a policy choice or a bug.
--Len

BBoppie 05-27-2012 08:08 AM

This is what my php5.conf file looks like for 2.2.1.7:
<IfModule mod_php5.c>
AddHandler application/x-httpd-php .php .html .htm .file
AddType application/x-httpd-php .php .phtml .php3
AddType application/x-httpd-php-source .phps
<FilesMatch "\.ph(p3?|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>
# To re-enable php in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
# <IfModule mod_userdir.c>
# <Directory /home/*/public_html>
# php_admin_value engine Off
# </Directory>
# </IfModule>
</IfModule>

In my experience with Apache, it tends to change I think because of software improvements and depending on which distro configured it.


All times are GMT -5. The time now is 03:24 PM.