LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 12-09-2009, 03:00 AM   #1
deostroll
Member
 
Registered: Aug 2007
Location: Bangalore
Distribution: fedora
Posts: 113

Rep: Reputation: 15
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...

Last edited by deostroll; 12-09-2009 at 03:03 AM. Reason: added more info.
 
Old 12-09-2009, 03:12 AM   #2
datopdog
Member
 
Registered: Feb 2008
Location: JHB South Africa
Distribution: Centos, Kubuntu, Cross LFS, OpenSolaris
Posts: 806

Rep: Reputation: 41
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
 
Old 12-09-2009, 03:28 AM   #3
deostroll
Member
 
Registered: Aug 2007
Location: Bangalore
Distribution: fedora
Posts: 113

Original Poster
Rep: Reputation: 15
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>
 
Old 12-09-2009, 03:29 AM   #4
datopdog
Member
 
Registered: Feb 2008
Location: JHB South Africa
Distribution: Centos, Kubuntu, Cross LFS, OpenSolaris
Posts: 806

Rep: Reputation: 41
This should do, test.php with the following in it
Code:
<?php
phpinfo();
?>
 
Old 12-09-2009, 03:51 AM   #5
deostroll
Member
 
Registered: Aug 2007
Location: Bangalore
Distribution: fedora
Posts: 113

Original Poster
Rep: Reputation: 15
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...
 
Old 12-09-2009, 03:55 AM   #6
datopdog
Member
 
Registered: Feb 2008
Location: JHB South Africa
Distribution: Centos, Kubuntu, Cross LFS, OpenSolaris
Posts: 806

Rep: Reputation: 41
Code:
tail /var/log/httpd/access_log /var/log/httpd/error_log
 
Old 12-09-2009, 05:12 AM   #7
deostroll
Member
 
Registered: Aug 2007
Location: Bangalore
Distribution: fedora
Posts: 113

Original Poster
Rep: Reputation: 15
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
 
Old 12-09-2009, 05:16 AM   #8
datopdog
Member
 
Registered: Feb 2008
Location: JHB South Africa
Distribution: Centos, Kubuntu, Cross LFS, OpenSolaris
Posts: 806

Rep: Reputation: 41
There is a permissions issue, i am guessing selinux what is the output of sestatus ?
 
Old 12-09-2009, 08:04 AM   #9
deostroll
Member
 
Registered: Aug 2007
Location: Bangalore
Distribution: fedora
Posts: 113

Original Poster
Rep: Reputation: 15
don't understand what is selinux in the context?
 
Old 12-09-2009, 08:05 AM   #10
datopdog
Member
 
Registered: Feb 2008
Location: JHB South Africa
Distribution: Centos, Kubuntu, Cross LFS, OpenSolaris
Posts: 806

Rep: Reputation: 41
You want help supply the output of
Code:
sestatus
 
Old 12-09-2009, 08:17 AM   #11
deostroll
Member
 
Registered: Aug 2007
Location: Bangalore
Distribution: fedora
Posts: 113

Original Poster
Rep: Reputation: 15
Code:
$ sestatus
SELinux status:                 disabled
 
Old 12-09-2009, 08:20 AM   #12
datopdog
Member
 
Registered: Feb 2008
Location: JHB South Africa
Distribution: Centos, Kubuntu, Cross LFS, OpenSolaris
Posts: 806

Rep: Reputation: 41
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/
 
Old 12-09-2009, 08:27 AM   #13
deostroll
Member
 
Registered: Aug 2007
Location: Bangalore
Distribution: fedora
Posts: 113

Original Poster
Rep: Reputation: 15
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~
$
 
Old 12-09-2009, 09:24 AM   #14
datopdog
Member
 
Registered: Feb 2008
Location: JHB South Africa
Distribution: Centos, Kubuntu, Cross LFS, OpenSolaris
Posts: 806

Rep: Reputation: 41
The permissions are incorrect fix them using

Code:
chmod a+r /var/www/html/test/index.php
 
Old 12-10-2009, 05:06 AM   #15
deostroll
Member
 
Registered: Aug 2007
Location: Bangalore
Distribution: fedora
Posts: 113

Original Poster
Rep: Reputation: 15
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?!!
 
  


Reply

Tags
apache2, centos, php



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to execute php scripts remotly in apache? harbo Linux - Server 1 03-17-2009 10:40 AM
Cant Get Apache to execute php pages nevarlen Linux - Newbie 1 02-17-2005 11:48 PM
Apache : execute pages as different user guideweb Linux - Security 2 03-15-2004 06:41 PM
Need help to configure Apache TO EXECUTE PHP SCRIPTS mgrapr Linux - Hardware 2 01-21-2004 09:23 AM
Apache Config for users to execute CGI scripts CragStar Linux - General 9 01-20-2003 12:37 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 07:54 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration