getting php4 to work (gpl version)

23 posts / 0 new
Last post
#1 Mon, 05/04/2009 - 16:26
christophera

getting php4 to work (gpl version)

I've got a new server with updated software, but some of my sites aren't working right on php 5, so I need to switch to them to php 4 so they work. Then I can work on the scripts.

I installed php4 via the yum package interface.

Now, how do I get a virtual site to use it? I was hoping I could use .htaccess and do:

AddType application/x-httpd-php4 .php

but that just caused the site not to work at all.

I see there's a php module with settings (currently empty) for php configuration values, is that where I change anything?

I read some posts where Joe says he provides a simple solution for doing this in the gpl version, but I haven't been able to find that.

Thanks for any guidance on this! Chris

Mon, 05/04/2009 - 16:31
Joe
Joe's picture

You cannot run two versions of mod_php in one Apache process. It will crash the whole server after a very short time.

The discussion FastCGI and Suexec on a Virtualmin GPL system is here:

http://www.virtualmin.com/forums/virtualmin/convert-php-sites-to-use-mod...

It is stickied at the top of the Virtualmin forum.

This doesn't actually cover having a <i>second</i> PHP, but it's possible (and even easy) with FastCGI. You just replicate the files into php4.fcgi and ~/etc/php4/php.ini, and change the paths and such. Note that PHP 4 and PHP 5 have different file name conventions for the php-cgi binary. I think it's just php4 in PHP 4, but I don't actually remember. You have to do a little legwork, but the process is identical for PHP 4 or PHP 5, just the paths are different.

--

Check out the forum guidelines!

Mon, 05/04/2009 - 16:57 (Reply to #2)
christophera

oh, and opps :)

Luckily, I made a backup before I tried this!

From the title of that post, I would have had no idea that dealt with the php4 and php5 issue.

Does the Pro version still have this as an easy option? (reading that post makes it look complicated - to me, but there is so much I don't know). I hard to spend the money right now, but it may be worth it.

Mon, 05/04/2009 - 17:02 (Reply to #3)
christophera

eh, just checked prices and I would need the $198 license. I can't do that, will have to figure it out on my own.

Thank you for your help Joe,

Chris

Mon, 05/04/2009 - 17:49 (Reply to #4)
andreychek

The Pro version does indeed make all this pretty easy, but it can certainly be made to work in the GPL version.

It's actually not too hard, the section of interest in that post is here:

http://www.virtualmin.com/forums/virtualmin/convert-php-sites-to-use-mod...

It's a matter of adding some config lines to the httpd.conf, and then creating a short script for each Virtual Server you intend on using this setup for.

What you see in that post describes how to set things up for PHP5 and FastCGI.

However, the same steps can be used to set it up for PHP4 as well. So when all is said and done, you'll be using PHP4+FastCGI and PHP5+FastCGI on the same server.
-Eric

Mon, 05/04/2009 - 20:17 (Reply to #5)
christophera

Well, I hate to look dense here, but...

The instructions start with &quot;Add to httpd.conf in the public_html Directory section within the relevant VirtualServer section:&quot; and then gives the code.

But if I go to home/virtualservername/public_html, httpd.conf isn't here (I didn't really expect it to be, as this is public, but what am I missing here?)

After the code, it says &quot;Create the wrapper in /home/domainname/fcgi-bin/php5.fcgi:&quot;

But I don't have an fcgi-bin directory there.

My OS is centos LAMP if that matters.

Sorry I am having trouble follow your instructions, they look straight forward.

Mon, 05/04/2009 - 20:25 (Reply to #6)
Joe
Joe's picture

&quot;Directory section&quot; means the section of httpd.conf for the VirtualHost you are talking about.

public_html is the directory being configured by that DirectorySection.

e.g.:

&lt;Directory /home/virtualmin/domains/jdev.virtualmin.com/public_html&gt;
Options Indexes Includes FollowSymLinks ExecCGI
AllowOverride all
Order allow,deny
Allow from all
AddHandler fcgid-script .php
AddHandler fcgid-script .php4
FCGIWrapper /home/virtualmin/domains/jdev.virtualmin.com/fcgi-bin/php4.fcgi .php
FCGIWrapper /home/virtualmin/domains/jdev.virtualmin.com/fcgi-bin/php4.fcgi .php4
&lt;/Directory&gt;

--

Check out the forum guidelines!

Mon, 05/04/2009 - 20:26 (Reply to #7)
Joe
Joe's picture

And, no, httpd.conf would never be found in public_html. ;-)

--

Check out the forum guidelines!

Mon, 05/04/2009 - 20:57 (Reply to #8)
christophera

Ah, ok, got that part now, thank you :) I was thinking there was an httpd.conf for each site. Now I found the way to edit the httpd.conf through vm.

Next, I don't seem to have any fcgi-bin directory, I did a find command via telnet and it can't find anything. Do I need to install fcgi? Is it a package in vm? I didn't see it in the list.

Mon, 05/04/2009 - 21:06 (Reply to #9)
Joe
Joe's picture

<div class='quote'>I don't seem to have any fcgi-bin directory</div>

Of course not. You already know fcgi support isn't built into Virtualmin GPL. ;-)

You have to create it in each virtual server home where you want to use fcgid.

You also have to install mod_fcgid (but that won't create any fcgid-bin directories, it just installs the mod_fcgid module for Apache).

--

Check out the forum guidelines!

Mon, 05/04/2009 - 21:41 (Reply to #10)
christophera

Actually, I didn't, I knew switching php4/5 was not supported, but I am just learning about it's relationship to fcgid... But I'm learning :)

Ok, I see mod_fcgid in yum. I've seen reference to suexec, is that something I need to install also, or is that already there?

And does mod_fcgid include php4, or do I need to install that as well (somehow different that what I did before).

Thank you for your time and patience,

Chris

Tue, 05/05/2009 - 00:53 (Reply to #11)
Joe
Joe's picture

<div class='quote'>Ok, I see mod_fcgid in yum. I've seen reference to suexec, is that something I need to install also, or is that already there?</div>

Suexec is already in there (and is supported by Virtualmin GPL, though not in the flexible way it is supported in Virtualmin Professional...the whole execution modes stuff is part of Install Scripts, so isn't in GPL). mod_suexec, on CentOS/RHEL is actually part of the httpd package. You can't not have it.

<div class='quote'>And does mod_fcgid include php4, or do I need to install that as well (somehow different that what I did before).</div>

No. mod_fcgid is a tiny little thing. Just a simple protocol proxy for Apache so it can start up and talk to FastCGI protocol servers (like PHP running in fastcgi mode).

I think you already said you'd installed the php4 packages we provide. The package <i>named</i> php4 contains php4. Go figure. ;-)

You'll also need a handful of other php4-* packages, but I assume you've seen those and chosen the ones you need for your applications.

--

Check out the forum guidelines!

Tue, 05/05/2009 - 06:20 (Reply to #12)
christophera

installed php4 -mysql
installed mod_fcgi

added the adhandler and fcgiwrapper to httpd.conf like this:

[code:1]&lt;Directory /home/mydomainname/public_html&gt;
Options -Indexes IncludesNOEXEC FollowSymLinks
allow from all
AllowOverride All
AddHandler fcgid-script .php
FCGIWrapper /home/mydomainname/fcgi-bin/php4.fcgi .php
&lt;/Directory&gt;[/code:1]

rebooted apache

created /home/mydomainname/fcgi-bin/php4.fcgi and put in:

[code:1]#!/bin/bash
PHPRC=$PWD/../etc/php4
export PHPRC
umask 022
SCRIPT_FILENAME=$PATH_TRANSLATED
export SCRIPT_FILENAME
exec /usr/bin/php-cgi[/code:1]

and created home/mydomainname/etc/php4/php.ini and copied in the contents from (root)/etc/php4/php.ini

I did this all under root, and checked permissions/owners on php4.fcgi:

-rw-r--r-- 1 root root 143 May 5 10:17 php4.fcgi

and the files in (root)/etc/php4

-rw-r--r-- 1 root root 808 Jun 24 2008 pear.conf
drwxr-xr-x 2 root root 4096 May 5 09:30 php.d
-rw-r--r-- 1 root root 38687 Jun 24 2008 php.ini

and home/mydomainname/etc/php4/php.ini

-rw-r--r-- 1 root root 38687 May 5 10:18 php.ini

When I go to http://www.mydomainname.com/phpinfo.php though, I get an 403/forbidden page.

Are the 'application files' you said should be checked the (root)/etc/php4 files, or something else?

See anything I've missed?

Thanks again for all your help, you've gone above and beyond the call..

Tue, 05/05/2009 - 15:58 (Reply to #13)
Joe
Joe's picture

The logs. Go to the logs. /home/domain/logs/error_log and /var/log/httpd/suexec_log would be the first places I'd look.

--

Check out the forum guidelines!

Tue, 05/05/2009 - 16:01 (Reply to #14)
Joe
Joe's picture

<div class='quote'>-rw-r--r-- 1 root root 38687 May 5 10:18 php.ini</div>

Obviously this one is wrong. Ought to be owned by the user. That's the point of suexec.

I bet your scripts are also owned by root, which will never work with suexec.

--

Check out the forum guidelines!

Tue, 05/05/2009 - 17:14 (Reply to #15)
christophera

hmm, yes, I'm sure they are.

Would this not have worked either if I had the pro version, or does that handle things differently?

I'll have to figure out what to do next.

Tue, 05/05/2009 - 17:19 (Reply to #16)
Joe
Joe's picture

Nothing owned by root will run under suexec, regardless of Pro or GPL (we didn't build suexec...that's just the rules in a suexec environment, for security reasons).

<div class='quote'>I'll have to figure out what to do next. </div>

chown username:usergroup

--

Check out the forum guidelines!

Tue, 05/05/2009 - 17:22 (Reply to #17)
Joe
Joe's picture

Also, go to the logs. Seriously. Get used to looking at the logs whenever anything isn't working. It's the only way to ever understand what's happening on your system (and it's the only way we can help in most cases, since the error you see in your browser can only ever be just a number and a type of error...it's got no actual information in it beyond, &quot;it didn't work&quot;).

--

Check out the forum guidelines!

Thu, 05/07/2009 - 00:58 (Reply to #18)
duncanbbd

would it not be better to move to PHP5 ?

I have done thi smigration recently and its not too painful. there are certain things you need to do (of course it depends on whether its your own code or somebody else's ;o) )

Thu, 05/07/2009 - 06:50 (Reply to #19)
Joe
Joe's picture

There's also the consideration that PHP 4 has been end-of-lifed by the PHP developers. It is no longer being maintained.

But, I think OP was considering PHP 4 a brief stopover while migrating to PHP 5. I didn't get the impression he was planning to use it for a longer period of time (any amount of time with a deprecated piece of software is dangerous, but maybe good luck will hold and no major new exploits will be found...there are already a few minor security issues known in PHP 4, since its deprecation a few months ago).

--

Check out the forum guidelines!

Mon, 05/11/2009 - 05:51 (Reply to #20)
dart

Hi

I'm in the same situation of having two PHP4 websites which are supposed to run on a new system, CentOS 5.2 64bit with Virtualmin GPL.
I was able to run any PHP5 website as CGI or FastCGI, but I can't tell the same thing about PHP4. Basically anything else than Apache module will not work. The installed PHP4 version is php4-4.4.8-1vm.
I noticed that christophera intention was the same - to run some PHP4 websites on the same Apache serving mostly PHP5 websites.
So, there is anyone running such configuration on a system with the last packages provided by Virtualmin repository?
I don't know where to look or check anymore. In the best scenario I'm getting a blank page and a 200 error code in the logs. I was wondering why there is no cgi binary in the PHP4 package.

Daniel

Mon, 05/11/2009 - 11:59 (Reply to #21)
Joe
Joe's picture

I don't understand? What are you asking? This thread, and the one linked from it tells how to do this. What have you done that isn't working? What errors are you getting? As far as I know, we've covered what you need to do to run two versions of PHP in pretty significant detail. I'm happy to answer any specific questions. But repeating what I've already said in this and the linked thread doesn't seem a productive use of our time.

--

Check out the forum guidelines!

Tue, 05/05/2009 - 04:11
christophera

ah, ok, when you said I couldn't run two versions in one Apache process, I was concerned that was what I had done by installing that package. So I restored the backup I had made just before I dug into this.

But I guess not, I would probably have to put it into the httpd.conf to 'run' it in apache.

I think I got it now, will set it up and let you know!

Topic locked