LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (http://www.linuxquestions.org/questions/linux-server-73/)
-   -   centos 5: config apache to execute php scripts/pages (http://www.linuxquestions.org/questions/linux-server-73/centos-5-config-apache-to-execute-php-scripts-pages-774432/)

deostroll 12-09-2009 03:00 AM

centos 5: config apache to execute php scripts/pages
 
most of my googling odysseies lead me to articles which talk about compiling apache & php from the source as this is touted to be more flexible. But the problem we have is this...we already have an apache 2 web server running. Now how do we serve php pages of it...

PS: i believe we even have php installed...

datopdog 12-09-2009 03:12 AM

If you already have php installed it should work out of the box, you do not need to do anything.

Check using

Code:

rpm -qi php
cat /etc/httpd/conf.d/php.conf


deostroll 12-09-2009 03:28 AM

Here is the output of both commands:

Code:

$ rpm -qi php
The php package contains the module which adds support for the PHP
language to Apache HTTP Server.
Name        : php                          Relocations: (not relocatable)
Version    : 5.1.6                            Vendor: CentOS
Release    : 23.2.el5_3                    Build Date: Tue 07 Apr 2009 05:34:02 PM IST
Install Date: Mon 25 May 2009 06:53:19 PM IST      Build Host: builder10.centos.org
Group      : Development/Languages        Source RPM: php-5.1.6-23.2.el5_3.src.rpm
Size        : 3017223                          License: The PHP License v3.01
Signature  : DSA/SHA1, Tue 07 Apr 2009 05:50:04 PM IST, Key ID a8a447dce8562897
URL        : http://www.php.net/
Summary    : The PHP HTML-embedded scripting language. (PHP: Hypertext Preprocessor)
Description :
PHP is an HTML-embedded scripting language. PHP attempts to make it
easy for developers to write dynamically generated webpages. PHP also
offers built-in database integration for several commercial and
non-commercial database management systems, so writing a
database-enabled webpage with PHP is fairly simple. The most common
use of PHP coding is probably as a replacement for CGI scripts.

The php package contains the module which adds support for the PHP
language to Apache HTTP Server.

Code:

$ cat /etc/httpd/conf.d/php.conf
#
# PHP is an HTML-embedded scripting language which attempts to make it
# easy for developers to write dynamically generated webpages.
#

LoadModule php5_module modules/libphp5.so

#
# Cause the PHP interpreter to handle files with a .php extension.
#
AddHandler php5-script .php
AddType text/html .php

#
# Add index.php to the list of files that will be served as directory
# indexes.
#
DirectoryIndex index.php

#
# Uncomment the following line to allow PHP to pretty-print .phps
# files as PHP source code:
#
#AddType application/x-httpd-php-source .phps

Yet I am not getting the php page served...don't know if the php code is incorrect either...pasting the code here for reference:

PHP Code:

<html>
<body>

<?php phpinfo(); ?>

</body>
</html>


datopdog 12-09-2009 03:29 AM

This should do, test.php with the following in it
Code:

<?php
phpinfo();
?>


deostroll 12-09-2009 03:51 AM

it still doesn't work...4got to mention wher i've kept my php file...
in /var/www/html/test folder I've created a page called index.php with the above code.

In the browser I an typing http://localhost/test/index.php still nt giving me an output...

datopdog 12-09-2009 03:55 AM

Code:

tail /var/log/httpd/access_log /var/log/httpd/error_log

deostroll 12-09-2009 05:12 AM

Code:

$ tail /var/log/httpd/access_log /var/log/httpd/error_log
==> /var/log/httpd/access_log <==
::1 - - [09/Dec/2009:12:15:35 -0500] "GET /test/index.php HTTP/1.1" 200 - "-" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.10) Gecko/2009042718 CentOS/3.0.10-1.el5.centos Firefox/3.0.10"
::1 - - [09/Dec/2009:12:21:45 -0500] "GET /test/index.php HTTP/1.1" 200 - "-" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.10) Gecko/2009042718 CentOS/3.0.10-1.el5.centos Firefox/3.0.10"
::1 - - [09/Dec/2009:12:21:47 -0500] "GET /test/index.php HTTP/1.1" 200 - "-" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.10) Gecko/2009042718 CentOS/3.0.10-1.el5.centos Firefox/3.0.10"
::1 - - [09/Dec/2009:12:21:48 -0500] "GET /test/index.php HTTP/1.1" 200 - "-" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.10) Gecko/2009042718 CentOS/3.0.10-1.el5.centos Firefox/3.0.10"
::1 - - [09/Dec/2009:12:21:49 -0500] "GET /test/index.php HTTP/1.1" 200 - "-" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.10) Gecko/2009042718 CentOS/3.0.10-1.el5.centos Firefox/3.0.10"
::1 - - [09/Dec/2009:12:24:53 -0500] "GET /test/index.php HTTP/1.1" 200 - "-" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.10) Gecko/2009042718 CentOS/3.0.10-1.el5.centos Firefox/3.0.10"
::1 - - [09/Dec/2009:12:26:12 -0500] "GET /test/index.php HTTP/1.1" 200 - "-" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.10) Gecko/2009042718 CentOS/3.0.10-1.el5.centos Firefox/3.0.10"
::1 - - [09/Dec/2009:04:57:09 -0500] "GET /test/index.php HTTP/1.1" 200 - "-" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.10) Gecko/2009042718 CentOS/3.0.10-1.el5.centos Firefox/3.0.10"
::1 - - [09/Dec/2009:04:58:08 -0500] "GET /test/index.php HTTP/1.1" 200 - "-" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.10) Gecko/2009042718 CentOS/3.0.10-1.el5.centos Firefox/3.0.10"
::1 - - [09/Dec/2009:06:18:51 -0500] "GET /favicon.ico HTTP/1.1" 404 294 "-" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.10) Gecko/2009042718 CentOS/3.0.10-1.el5.centos Firefox/3.0.10"

==> /var/log/httpd/error_log <==
[Wed Dec 09 12:26:12 2009] [error] [client ::1] PHP Warning:  Unknown: Failed opening '/var/www/html/test/index.php' for inclusion (include_path='.:/usr/share/pear:/usr/share/php') in Unknown on line 0
[Wed Dec 09 04:57:09 2009] [error] an unknown filter was not added: PHP
[Wed Dec 09 04:57:09 2009] [error] an unknown filter was not added: PHP
[Wed Dec 09 04:57:09 2009] [error] [client ::1] PHP Warning:  Unknown: failed to open stream: Permission denied in Unknown on line 0
[Wed Dec 09 04:57:09 2009] [error] [client ::1] PHP Warning:  Unknown: Failed opening '/var/www/html/test/index.php' for inclusion (include_path='.:/usr/share/pear:/usr/share/php') in Unknown on line 0
[Wed Dec 09 04:58:08 2009] [error] an unknown filter was not added: PHP
[Wed Dec 09 04:58:08 2009] [error] an unknown filter was not added: PHP
[Wed Dec 09 04:58:08 2009] [error] [client ::1] PHP Warning:  Unknown: failed to open stream: Permission denied in Unknown on line 0
[Wed Dec 09 04:58:08 2009] [error] [client ::1] PHP Warning:  Unknown: Failed opening '/var/www/html/test/index.php' for inclusion (include_path='.:/usr/share/pear:/usr/share/php') in Unknown on line 0
[Wed Dec 09 06:18:51 2009] [error] [client ::1] File does not exist: /var/www/html/favicon.ico


datopdog 12-09-2009 05:16 AM

There is a permissions issue, i am guessing selinux what is the output of sestatus ?

deostroll 12-09-2009 08:04 AM

don't understand what is selinux in the context?

datopdog 12-09-2009 08:05 AM

You want help supply the output of
Code:

sestatus

deostroll 12-09-2009 08:17 AM

Code:

$ sestatus
SELinux status:                disabled


datopdog 12-09-2009 08:20 AM

Thats very wierd given the errors
Code:

[Wed Dec 09 04:57:09 2009] [error] [client ::1] PHP Warning:  Unknown: failed to open stream: Permission denied in Unknown on line 0
[Wed Dec 09 04:57:09 2009] [error] [client ::1] PHP Warning:  Unknown: Failed opening '/var/www/html/test/index.php' for inclusion (include_path='.:/usr/share/pear:/usr/share/php') in Unknown on line 0
[Wed Dec 09 04:58:08 2009] [error] an unknown filter was not added: PHP

Check the file and directory ownership

Code:

ls -l /var/www/html
ls -l /var/www/html/test/


deostroll 12-09-2009 08:27 AM

Code:

$ ls -l /var/www/html
total 12
drwxr-xr-x 2 root root 4096 Dec  9 15:27 test
$ ls -l /var/www/html/test
total 12
-rw------- 1 root root 55 Dec  9 15:27 index.php
-rw------- 1 root root 57 Dec  9 15:26 index.php~
-rwxr-xr-x 1 root root 20 Dec  9 04:08 test.html
-rw------- 1 root root  0 Dec  9 04:07 test.html~
$


datopdog 12-09-2009 09:24 AM

The permissions are incorrect fix them using

Code:

chmod a+r /var/www/html/test/index.php

deostroll 12-10-2009 05:06 AM

Thanx tht worked!!!

Don't understand those permissions I've to set tho. Are there any articles that can come in handy?

Isn't there a more direct way? I mean I am looking at directly creating php files and expecting them to get deployed...straight. So those files should have the correct permissions...I don't want to create a file and then change its permission always...OR, is this how its done always?!!


All times are GMT -5. The time now is 05:47 AM.