Apache2 and PHP

I’m having some difficulties trying to setup a webserver with PHP.The PHP seems to work,but when i want to see a .php page,it shows me the content,just like the php isn’t present.What i have to do.It’s much easier in windows :’(

This is my loadmodule.conf

# Files in this directory are created at apache start time by /usr/sbin/rcapache2 
# Do not edit them!

# as listed in APACHE_MODULES (/etc/sysconfig/apache2)

LoadModule suexec_module                  /usr/lib/apache2-prefork/mod_suexec.so
LoadModule authz_host_module              /usr/lib/apache2-prefork/mod_authz_host.so
LoadModule actions_module                 /usr/lib/apache2-prefork/mod_actions.so
LoadModule alias_module                   /usr/lib/apache2-prefork/mod_alias.so
LoadModule auth_basic_module              /usr/lib/apache2-prefork/mod_auth_basic.so
LoadModule authz_groupfile_module         /usr/lib/apache2-prefork/mod_authz_groupfile.so
LoadModule authn_file_module              /usr/lib/apache2-prefork/mod_authn_file.so
LoadModule authz_user_module              /usr/lib/apache2-prefork/mod_authz_user.so
LoadModule authn_dbm_module               /usr/lib/apache2-prefork/mod_authn_dbm.so
LoadModule autoindex_module               /usr/lib/apache2-prefork/mod_autoindex.so
LoadModule cgi_module                     /usr/lib/apache2-prefork/mod_cgi.so
LoadModule dir_module                     /usr/lib/apache2-prefork/mod_dir.so
LoadModule env_module                     /usr/lib/apache2-prefork/mod_env.so
LoadModule expires_module                 /usr/lib/apache2-prefork/mod_expires.so
LoadModule include_module                 /usr/lib/apache2-prefork/mod_include.so
LoadModule log_config_module              /usr/lib/apache2-prefork/mod_log_config.so
LoadModule mime_module                    /usr/lib/apache2-prefork/mod_mime.so
LoadModule negotiation_module             /usr/lib/apache2-prefork/mod_negotiation.so
LoadModule setenvif_module                /usr/lib/apache2-prefork/mod_setenvif.so
LoadModule status_module                  /usr/lib/apache2-prefork/mod_status.so
LoadModule userdir_module                 /usr/lib/apache2-prefork/mod_userdir.so
LoadModule asis_module                    /usr/lib/apache2-prefork/mod_asis.so
LoadModule imagemap_module                /usr/lib/apache2-prefork/mod_imagemap.so
LoadModule rewrite_module                 /usr/lib/apache2-prefork/mod_rewrite.so
LoadModule ssl_module                     /usr/lib/apache2-prefork/mod_ssl.so
LoadModule php5_module                    /usr/lib/apache2/mod_php5.so
LoadModule ruby_module                    /usr/lib/apache2/mod_ruby.so
LoadModule authz_default_module           /usr/lib/apache2-prefork/mod_authz_default.so

Looks like you have php5 loaded but to double check do this:

/usr/sbin/httpd2 -M

php5 should be in the list.

In that case are you using short tags: <? … ?>. You should use <?php … ?>

Also the filename should end in .php, of course.

done,but still doesn’t work :frowning:

server:/home/legolas # /usr/sbin/httpd2 -M
Loaded Modules:
 core_module (static)
 mpm_prefork_module (static)
 http_module (static)
 so_module (static)
 suexec_module (shared)
 authz_host_module (shared)
 actions_module (shared)
 alias_module (shared)
 auth_basic_module (shared)
 authz_groupfile_module (shared)
 authn_file_module (shared)
 authz_user_module (shared)
 authn_dbm_module (shared)
 autoindex_module (shared)
 cgi_module (shared)
 dir_module (shared)
 env_module (shared)
 expires_module (shared)
 include_module (shared)
 log_config_module (shared)
 mime_module (shared)
 negotiation_module (shared)
 setenvif_module (shared)
 status_module (shared)
 userdir_module (shared)
 asis_module (shared)
 imagemap_module (shared)
 rewrite_module (shared)
 ssl_module (shared)
 php5_module (shared)
 ruby_module (shared)
 authz_default_module (shared)
Syntax OK

not even with the tags you said.it still showing me the page like a text viewer

Check that it’s actually loaded in apache, in case you forgot to restart apache:

lsof | grep mod_php5.so

should show several processes having the shared object open.

And of course you should be going through the web server, not browsing the file:


where /srv/www/htdocs/phpinfo.php is:


server:/home/legolas # lsof | grep mod_php5.so
lsof: WARNING: can't stat() fuse.gvfs-fuse-daemon file system /home/legolas/.gvfs
      Output information may be incomplete.
httpd2-pr  3121       root  mem       REG        8,2  2482640     297445 /usr/lib/apache2/mod_php5.so
httpd2-pr  3169     wwwrun  mem       REG        8,2  2482640     297445 /usr/lib/apache2/mod_php5.so
httpd2-pr  3171     wwwrun  mem       REG        8,2  2482640     297445 /usr/lib/apache2/mod_php5.so
httpd2-pr  3173     wwwrun  mem       REG        8,2  2482640     297445 /usr/lib/apache2/mod_php5.so
httpd2-pr  3175     wwwrun  mem       REG        8,2  2482640     297445 /usr/lib/apache2/mod_php5.so
httpd2-pr  3177     wwwrun  mem       REG        8,2  2482640     297445 /usr/lib/apache2/mod_php5.so
httpd2-pr  5805     wwwrun  mem       REG        8,2  2482640     297445 /usr/lib/apache2/mod_php5.so
httpd2-pr 13623     wwwrun  mem       REG        8,2  2482640     297445 /usr/lib/apache2/mod_php5.so
httpd2-pr 13624     wwwrun  mem       REG        8,2  2482640     297445 /usr/lib/apache2/mod_php5.so
httpd2-pr 13625     wwwrun  mem       REG        8,2  2482640     297445 /usr/lib/apache2/mod_php5.so

and the phpinfo page it displays me the code…

Have you modified any of apache’s config files? You shouldn’t need to, aside from adding php5 to /etc/sysconfig/apache2. If you did modify some things, it could be that you made .php not a special file suffix any more. Try this:

wget -O /dev/null -S http://localhost/phpinfo.php

You should get some lines like this:

HTTP request sent, awaiting response…
HTTP/1.1 200 OK
Date: Mon, 30 Mar 2009 09:17:15 GMT
Server: Apache/2.2.10 (Linux/SUSE)
X-Powered-By: PHP/5.2.6
Connection: close
Content-Type: text/html
Length: unspecified [text/html]

and it should say the length of the output is around 57kB. If the type is not text/html or the size is not 50+ kB, then something is badly wrong.

server:/home/legolas # wget -O /dev/null -S http://localhost/phpinfo.php
--2009-03-30 12:30:31--  http://localhost/phpinfo.php
Resolving localhost...
Connecting to localhost||:80... connected.
HTTP request sent, awaiting response... 
  HTTP/1.1 200 OK
  Date: Mon, 30 Mar 2009 09:30:31 GMT
  Server: Apache/2.2.8 (Linux/SUSE)
  Last-Modified: Mon, 30 Mar 2009 09:12:57 GMT
  ETag: "24d4c-14-466527cfab840"
  Accept-Ranges: bytes
  Content-Length: 20
  Keep-Alive: timeout=15, max=100
  Connection: Keep-Alive
  Content-Type: text/plain
Length: 20 [text/plain]
Saving to: `/dev/null'

100%======================================&gt;] 20          --.-K/s   in 0s      

2009-03-30 12:30:31 (1.95 MB/s) - `/dev/null' saved [20/20]

i guess it’s wrong…the type is plain?how can i fix this.and yes,i think i did some changes

Look at the .php files you’re serving, do they start with <? or with <?php ?

If they start with <?, edit /etc/php5/apache2/php.ini and change:

short_open_tag = off
short_open_tag = on

and restart Apache2.

I think better start from a clean slate and reinstall apache2 and apache2-mod_php5. Then apply the only change you really need, add php5 to APACHE_MODULES in /etc/sysconfig/apache2 and restart apache2.

Chrysantine’s idea didn’t payed off.I think that i will reinstall apache and see what happends.Thanks for helping guys and i’ll be back >:)

Works like a charm.Thanks for helping guys,especially you,ken_yap

Excellent. Have fun!