The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PHP5 & PHP4 Hosting Options

Discussion in 'General Discussion' started by djspark, Jan 13, 2005.

  1. djspark

    djspark Active Member

    Joined:
    Feb 3, 2003
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    1
    To Quote http://www.iniquinet.com/php5_hosting.php
    How is this sort of setup possible in cpanel? This sounds like a great stepping stone to get users moving towards PHP5 without killing all your php4 customers.


    Mark
     
  2. dezignguy

    dezignguy Well-Known Member

    Joined:
    Sep 26, 2004
    Messages:
    534
    Likes Received:
    0
    Trophy Points:
    16
    Use the search button on the top menu...

    there was another thread recently that discussed installing both versions at the same time.
     
  3. DigitalN

    DigitalN Well-Known Member

    Joined:
    Sep 23, 2004
    Messages:
    420
    Likes Received:
    1
    Trophy Points:
    18
    I have installed php4 + php5 onto a server for testing (both running as apache modules, rather than run 1 as a module and 1 as CGI).

    I did this by installing a second apache installation onto the server with php5 configured --with-apxs=/path/to/apache_php5/apxs and installing mod_proxy into the original apache server, allowing only localhost to access the second apache install which runs on a different port.

    This way, the users can test php5 in an apache module environment, as it would be when we install it instead of php4 ... if that happens, eventually.
     
  4. barwin

    barwin Active Member

    Joined:
    Jan 5, 2004
    Messages:
    37
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Manhattan
    hey ... that's me :)

    I was the one who set it up originally for Iniquinet.com (quoted in first post of this thread) and did the same thing for www.a2hosting.com

    Basically I did what DigitalN described. That's the best way I could think to do it since you can't load both modules in the same Apache, and running one as a CGI didn't seem like a good solution either.
     
  5. djspark

    djspark Active Member

    Joined:
    Feb 3, 2003
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    1
    Awesome, thanks :-D Would you have the time or patience to post up a step by step of what you did? I'm wondering if cpanel's apache builder will eventually go this route as they integrate php5 more.

    Thanks,
    Mark
     
  6. DigitalN

    DigitalN Well-Known Member

    Joined:
    Sep 23, 2004
    Messages:
    420
    Likes Received:
    1
    Trophy Points:
    18
    I will post a How To do this at the weekend if I have the time - Unless someone beats me to it :)
     
  7. djspark

    djspark Active Member

    Joined:
    Feb 3, 2003
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    1
    Thank you very much! I doubt anyone will beat you to it since everyone else I talked to is under NDA :eek:

    Thanks again,

    Mark
     
  8. djspark

    djspark Active Member

    Joined:
    Feb 3, 2003
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    1
    was this posted somewhere else?


    mark
     
  9. DigitalN

    DigitalN Well-Known Member

    Joined:
    Sep 23, 2004
    Messages:
    420
    Likes Received:
    1
    Trophy Points:
    18
    No, haven't really had the time to think about posting a how to for this (and haven't had any offers of crossing my palm with gold to do it for anyone either :) ) but maybe I'll post an example install for you shortly.
     
  10. DigitalN

    DigitalN Well-Known Member

    Joined:
    Sep 23, 2004
    Messages:
    420
    Likes Received:
    1
    Trophy Points:
    18
    OK, here is an example of how you can run mod_php + mod_php5 on the same server.

    NOTE: This covers the installation where you are running mod_php - It won't work for people wanting to use phpsuexec and cgi installs of php.

    Disclaimer: You are on your own, if you use or follow any of the following advice and you have any problems, you should be able to work things out for yourself. If you aren't competent in installing apache/php and solving simple related problems, then I would advise that you proceed at your own risk.

    Ok,

    If you have installed cpanels apache lately, cd to the directory where apache was installed and copy the buildscript to buildscriptphp5

    Otherwise, reinstall apache


    Code:
    # cd /usr/local/src 
    # wget http://layer1.cpanel.net/buildapache.sea
    # sh buildapache.sea
    Make sure to select the option to install apache, even if the version is the same.

    Then when apache has been reinstalled and is back running, cd to wherever your buildapache is, could be /usr/local/src or /home/cpapachebuild

    Code:
    # cd buildapache
    
    # cp buildscript buildscriptphp5
    Now edit the file buildscriptphp5

    Replace the following at around line 24

    Code:
    REWRITE="--enable-module=rewrite --enable-shared=rewrite"
    WITH

    Code:
    REWRITE="--enable-module=rewrite --enable-shared=rewrite --enable-module=proxy --enable-shared=proxy"
    I am assuming here that you will have built apache with mod_rewrite enabled, if you haven't got that line within buildscriptphp5 then add --enable-module=proxy --enable-shared=proxy
    to the apache ./configure line lower down the script.

    Now, to install apache as you did the last time you ran the buildapache install script, with the new addition of mod_proxy type

    Code:
    # rm -rf apache_1.3.33 mod_ssl-2.8.22-1.3.33
    # ./buildscriptphp5
    Assuming all went well and your new apache install has kicked up ok, check the following and add to /usr/local/apache/conf/httpd.conf if you need to

    Create a file to hold all the php5 enabled vhosts

    Code:
    # touch /usr/local/apache/conf/httpd.php5.conf
    Edit httpd.conf, make sure these are included and add the Include within your vhost section of httpd.conf

    Within the LoadModule config

    Code:
    LoadModule proxy_module       libexec/libproxy.so
    Within the AddModule config

    Code:
    AddModule mod_proxy.c
    Then within your Vhost config add

    Code:
    <IfModule mod_proxy.c>
    Include /usr/local/apache/conf/httpd.php5.conf
    </IfModule>

    Then restart apache, watch for any errors

    Code:
    # /etc/init.d/httpd graceful
    The above will enable mod_proxy into your existing apache installation, which we will use later on to access the second install of apache.

    Right, now we will install our second installation of apache, this is where mod_php5 will be installed and running from.

    Code:
    # cd /usr/local/src
    You can use this to install apache if needed, basically just download apache from your apache mirror or use the one that the cpanel script downloaded for you earlier if need be.
    Just change the apache url (APACHE variable) or comment the download part out if you copy the files locally.

    This will install apache into

    /usr/local/apache_php5

    using --prefix=/usr/local/apache_php5

    Create the apache install script named anything you like and enter the following

    Code:
    #!/bin/sh
    # Install apache for php5 - Make listen to 127.0.0.1 port 8080
    # or a port of your choosing.
    
    # Change the apache mirror to where yours is http://httpd.apache.org/download.cgi
    APACHE="http://Your_apache_mirror/apache_1.3.33.tar.gz"
    
    if [ ! -e "/usr/local/src/apache-php5" ]; then
    mkdir /usr/local/src/apache-php5
    fi
    cd /usr/local/src/apache-php5
    if [ ! -e "/usr/local/src/apache-php5/apache_1.3.33.tar.gz" ]; then
    wget -c $APACHE
    fi
    if [ ! -e "/usr/local/src/apache-php5/mod_ssl-2.8.22-1.3.33" ]; then
    wget -c http://www.modssl.org/source/mod_ssl-2.8.22-1.3.33.tar.gz
    fi
    if [ -d "/usr/local/src/apache-php5/mod_ssl-2.8.22-1.3.33" ]; then
    rm -rf /usr/local/src/apache-php5/mod_ssl-2.8.22-1.3.33
    fi
    if [ -d "/usr/local/src/apache-php5/apache_1.3.33" ]; then
    rm -rf /usr/local/src/apache-php5/apache_1.3.33
    fi
    tar xvzf mod_ssl-2.8.22-1.3.33.tar.gz
    tar xvzf apache_1.3.33.tar.gz
    cd /usr/local/src/apache-php5/mod_ssl-2.8.22-1.3.33
    SSL_BASE=/usr \
    CFLAGS="-DEAPI" \
    ./configure --with-apache=/usr/local/src/apache-php5/apache_1.3.33 \
    --prefix=/usr/local/apache_php5 --with-ssl=/usr \
    --enable-module=rewrite --enable-shared=rewrite \
    --enable-module=ssl --enable-shared=ssl \
    --enable-suexec \
    --suexec-logfile=/usr/local/apache_php5/logs/suexec_log \
    --suexec-caller=nobody \
    --suexec-uidmin=100 \
    --suexec-gidmin=100 \
    --suexec-docroot=/ \
    --suexec-userdir=public_html \
    --enable-module=expires --enable-shared=expires \
    --enable-module=so
    
    cd /usr/local/src/apache-php5/apache_1.3.33
    SSL_BASE=/usr \
    C_INCLUDE_PATH=/usr/kerberos/include make
    C_INCLUDE_PATH=/usr/kerberos/include make certificate
    C_INCLUDE_PATH=/usr/kerberos/include make install
    This is assuming redhat and that you want SSL to be enabled for this apache install, I haven't enabled ssl and you will need to figure that out if you need it.
    If you don't want SSL to be enabled.
    Enter the defaults or your details when prompted for the SSL cert details.
    Do not say 'y' to having the ssl cert password protected, the one that is generated with 'make certificate' otherwise you will need to type in that pass everytime that you restart this installation of apache.

    Now if the install went ok,

    edit /usr/local/apache_php5/conf/httpd.conf

    Change the Values and add as per the following

    Code:
    Listen 127.0.0.1:8080
    Code:
    #
    # Port: The port to which the standalone server listens. For
    # ports < 1023, you will need httpd to be run as root initially.
    #
    Port 8080
    Code:
    <IfDefine SSL>
    Listen 8080
    Listen 8081
    </IfDefine>
    Within the Vhost section, add

    Code:
    NameVirtualHost 127.0.0.1:8080
    Assuming all goes well

    /usr/local/apache_php5/bin/apachectl start

    You should see

    Code:
    # ps auxf
    Code:
    /usr/local/apache_php5/bin/httpd
    nobody   25971  0.0  1.0 16288 5616 ?        S    12:40   0:00  \_ /usr/local/apache_php5/bin/httpd
    nobody   25972  0.0  1.0 16320 5436 ?        S    12:40   0:00  \_ /usr/local/apache_php5/bin/httpd
    nobody   25973  0.0  1.1 16288 5620 ?        S    12:40   0:00  \_ /usr/local/apache_php5/bin/httpd
    nobody   25974  0.0  1.1 16288 5628 ?        S    12:40   0:00  \_ /usr/local/apache_php5/bin/httpd
    nobody   25975  0.0  1.0 16320 5436 ?        S    12:40   0:00  \_ /usr/local/apache_php5/bin/httpd
    nobody   25976  0.0  1.0 16188 5356 ?        S    12:40   0:00  \_ /usr/local/apache_php5/bin/httpd
    If not, then check the error logs for further clues

    /usr/local/apache_php5/logs/error_log
     
    #10 DigitalN, Feb 14, 2005
    Last edited: Feb 15, 2005
  11. DigitalN

    DigitalN Well-Known Member

    Joined:
    Sep 23, 2004
    Messages:
    420
    Likes Received:
    1
    Trophy Points:
    18
    Part 2

    Ok, lets now install php 5

    Download and extract php5 - www.php.net choose your mirror or download from elsewhere.

    You can use the following to install php into /usr/bin/php5

    If you need other modules included or get errors when the ./configure runs, you will need to install what you need or remove the --with-whatever from the script until the install goes clean.

    cd /usr/local/src

    Assuming you have extracted php-5.0.3 already into /usr/local/src (if not then do that)

    Code:
    #!/bin/sh
    PHPVERSION="5.0.3"
    
    cd php-$PHPVERSION
    if [ -f "Makefile" ]; then
    make clean
    fi
    ./configure --with-apxs=/usr/local/apache_php5/bin/apxs --prefix=/usr/local/php5 --with-config-file-path=/usr/local/lib/php5 --with-xml --enable-bcmath --enable-calendar --with-curl --with-dom --with-dom-xslt --with-dom-exslt --enable-exif --enable-ftp --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr --with-xpm-dir=/usr/X11R6 --with-gettext --with-imap --with-imap-ssl --with-kerberos --enable-mbstring --enable-mbstr-enc-trans --enable-mbregex --enable-magic-quotes --with-mysql=/usr --enable-discard-path --with-pear --with-pgsql=/usr --with-pspell --enable-safe-mode --enable-sockets --enable-track-vars --with-ttf --with-freetype-dir=/usr --enable-gd-native-ttf --enable-versioning --enable-wddx --with-xmlrpc --with-zip --with-zlib
    make
    make install
    if [ ! -e "/usr/local/lib/php5" ]; then
    mkdir /usr/local/lib/php5
    fi
    /bin/cp php.ini-dist /usr/local/lib/php5/php.ini
    if [ -f "/usr/local/lib/php5/php.ini" ]; then
    echo " Review the php config /usr/local/lib/php5/php.ini .. then"
    fi
    echo " Restart apache_php5 /usr/local/apache_php5/bin/apachectl graceful"
    cd ..
    Now check that you have the following and add to /usr/local/apache_php5/conf/httpd.conf

    Code:
    LoadModule php5_module        libexec/libphp5.so
    Code:
    AddModule mod_php5.c
    Code:
    <IfModule mod_dir.c>
        DirectoryIndex index.html index.php index.pl index.cgi index.htm
    </IfModule>
    Code:
        AddHandler cgi-script .cgi .pl
        AddType application/x-httpd-php .php
        #
        # To use server-parsed HTML files
        #
        AddType text/html .shtml
        AddHandler server-parsed .shtml
    Add any other extensions as needed, but those will do for a default install.

    Now, restart your php5 enabled apache

    Code:
    # /usr/local/apache_php5/bin/apachectl graceful
    Assuming no errors, you should see

    Code:
    # ps auxf
    Code:
    /usr/local/apache_php5/bin/httpd
    nobody   25971  0.0  1.0 16288 5616 ?        S    12:40   0:00  \_ /usr/local/apache_php5/bin/httpd
    nobody   25972  0.0  1.0 16320 5436 ?        S    12:40   0:00  \_ /usr/local/apache_php5/bin/httpd
    nobody   25973  0.0  1.1 16288 5620 ?        S    12:40   0:00  \_ /usr/local/apache_php5/bin/httpd
    nobody   25974  0.0  1.1 16288 5628 ?        S    12:40   0:00  \_ /usr/local/apache_php5/bin/httpd
    nobody   25975  0.0  1.0 16320 5436 ?        S    12:40   0:00  \_ /usr/local/apache_php5/bin/httpd
    nobody   25976  0.0  1.0 16188 5356 ?        S    12:40   0:00  \_ /usr/local/apache_php5/bin/httpd
    Right now all that is really left is to add a Vhost that we will use for php5 usage

    edit /usr/local/apache/conf/httpd.php5.conf

    xxx.xxx.xxx.xxx is the IP of the site, could be your shared IP.
    Replace php5.domain.com with your sites - I have added an example here that will simply use a subdomain to access the php5 installation. If you want to redirect based on file extension say .php5 then you need to do something different.

    Code:
    ProxyRequests Off
    <VirtualHost xxx.xxx.xxx.xxx>
    Servername php5.domain.com
    ServerAlias php5.domain.com
    DocumentRoot /home/user/public_html
    User user
    Group user
    ProxyPass / http://proxy.domain.com:8080/
    ProxyPassReverse / http://proxy.domain.com:8080/
    </VirtualHost>
    Now edit the php5 httpd.conf /usr/local/apache_php5/conf/httpd.conf

    Add the Vhost for the redirect domain - proxy.domain.com

    Code:
    NameVirtualHost 127.0.0.1:8080
    <VirtualHost 127.0.0.1>
    ServerName proxy.domain.com
    ServerAlias proxy.domain.com
    DocumentRoot /home/user/public_html
    User user
    Group user
    ErrorLog logs/proxy.domain.com-error_log
    CustomLog logs/proxy.domain.com-access_log common
    ScriptAlias /cgi-bin/ /home/user/public_html/cgi-bin/
    </VirtualHost>
    Make sure the A records are added for php5 and proxy as follows

    edit

    /var/named/domain.com.db

    Code:
    php5  IN   A   xxx.xxx.xxx.xxx
    proxy     IN    A     127.0.0.1
    The xxx.xxx.xxx.xxx IP as the same as you added in the apache vhost /usr/local/apache/conf/httpd.php5.conf

    Reload named

    Code:
    # rndc reload
    Restart both installs of apache

    Code:
    # /etc/init.d/httpd graceful
    Code:
    # /usr/local/apache_php5/bin/apachectl graceful
    Now make a test page

    Code:
    # echo "<? phpinfo();?>" > /home/user/public_html/testphp5.php
    All being well

    http://php5.domain.com/testphp5.php

    will show up a phpinfo page with the php 5 installation details.

    I hope this is a helping hand as to how you can do this installation - Good luck :)


    References:

    http://httpd.apache.org
    http://httpd.apache.org/docs/mod/mod_proxy.html
    www.php.net
     
    #11 DigitalN, Feb 14, 2005
    Last edited: Feb 14, 2005
  12. rgyure

    rgyure Member

    Joined:
    Jan 27, 2005
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    1
    Just did the tutorial and it works great. I had a few issues with getting mod_proxy on my current apache install, so all I did was complied mod_proxy on my linux test box and moved the .so over.


    Is there an easy way to do that? If so, what would I have to do?


    Thanks for the tutorial.

    Ryan
     
  13. DigitalN

    DigitalN Well-Known Member

    Joined:
    Sep 23, 2004
    Messages:
    420
    Likes Received:
    1
    Trophy Points:
    18
    You could try to cd the apache module src and install it like

    cd apache_1.3.33/src/modules/proxy/

    /usr/local/apache/bin/apxs -cia mod_proxy.c
     
  14. rgyure

    rgyure Member

    Joined:
    Jan 27, 2005
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    1
    I got mod_proxy all worked out. I built mod_proxy off my test linux machine.

    The thing I want to know about is this:

    Ryan
     
    #14 rgyure, Feb 15, 2005
    Last edited: Feb 15, 2005
  15. DigitalN

    DigitalN Well-Known Member

    Joined:
    Sep 23, 2004
    Messages:
    420
    Likes Received:
    1
    Trophy Points:
    18
    I've given you all a good start :) - You can work the rest out and modify to do as you need it to do, including redirecting based on file extension - There are a few ways of achieving the same thing, you could use mod_rewrite rules or something else, what works for you is the best.
     
  16. djspark

    djspark Active Member

    Joined:
    Feb 3, 2003
    Messages:
    29
    Likes Received:
    0
    Trophy Points:
    1

    Ahh, thank you VERY much for posting up this guide. I think I know how I can make mod_rewrite work with this to get the .php5 going. I'll play with it today and post up a config if all goes well. Thank you very much for posting up the step by step of getting both running.

    Mark
     
  17. DigitalN

    DigitalN Well-Known Member

    Joined:
    Sep 23, 2004
    Messages:
    420
    Likes Received:
    1
    Trophy Points:
    18
    No problem :)

    Of course there is an advantage to view the complete site and all .php pages using php5 - The users can immediately see what they need to change within their exisiting scripts at http://php5.domain.com to make them php5 ready at http://www.domain.com without modifying their .php extensions :)

    I hope the info was of use to you.
     
    #17 DigitalN, Feb 16, 2005
    Last edited: Feb 16, 2005
  18. rgyure

    rgyure Member

    Joined:
    Jan 27, 2005
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    1
    I got the mod_rewrite code to make it use .php5 extentions.

    Ryan
     
  19. vwiley1

    vwiley1 Well-Known Member

    Joined:
    Oct 4, 2003
    Messages:
    87
    Likes Received:
    0
    Trophy Points:
    6
    Hi Everyone,

    I followed the tutorial posted, however I am having a few problems.

    Apache with PHP4 is working great, I have not been able to test the one with PHP5 yet.

    After the tutorial here is what I did:

    Mydomain.com is already setup as an account through WHM. So I went into the CPanel for this domain, and added a subdomain.

    php5.mydomain.com

    I edited the /var/named/mydomain.db and added the sub-domain: proxy which is an A record that points to 127.0.0.1.

    I edited the PHP4 apache httpd.conf, and removed the virtualhost for php5.mydomain.com.

    I added the VirtualHost for php5.mydomain.com to /usr/local/apache/conf/httpd.php5.conf

    The httpd.php5.conf file now looks like this:

    ProxyRequests Off
    <VirtualHost 111.222.333.444>
    Servername php5.mydomain.com
    ServerAlias php5.mydomain.com
    DocumentRoot /home/vwiley1/public_html/php5
    User vwiley1
    Group vwiley1
    ProxyPass / http://proxy.mydomain.com:8080/
    ProxyPassReverse / http://proxy.mydomain.com:8080/
    </VirtualHost>

    Of course the IP and mydomain.com are edited in this post :)

    Next I edited the /usr/local/apache_php5/conf/httpd.conf

    The addition I made to this file looks like this:

    <VirtualHost 127.0.0.1>
    ServerName proxy.mydomain.com
    ServerAlias proxy.mydomain.com
    DocumentRoot /home/vwiley1/public_html/proxy
    User vwiley1
    Group vwiley1
    ErrorLog logs/proxy.mydomain.com-error_log
    CustomLog logs/proxy.mydomain.com-access_log common
    ScriptAlias /cgi-bin/ /home/vwiley1/public_html/proxy/cgi-bin/
    </VirtualHost>


    I then restarted both Apaches with NO errors and also restarted BIND. However when I go to php5.mydomain.com I get the default CPanel "There is no website configured at this address." page.

    All directories related to the sub-domains have been created, and they both have a phpinfo.php script in them. So it's not showing that page because of an empty directory.

    Does anyone know what may be wrong? Is there anyone who would be kind enough to look into it?

    Thanks,

    Vince

    I
     
  20. DigitalN

    DigitalN Well-Known Member

    Joined:
    Sep 23, 2004
    Messages:
    420
    Likes Received:
    1
    Trophy Points:
    18
    Did you add

    Include /usr/local/apache/conf/httpd.php5.conf

    into /usr/local/apache/conf/httpd.conf

    and then restart apache?

    Does

    # dig php5.domain.com

    resolve to the same IP that you have setup within /usr/local/apache/conf/httpd.php5.conf

    does

    # dig proxy.domain.com

    resolve to 127.0.0.1 ?

    Do you have a

    NameVirtualHost 127.0.0.1:8080

    Within /usr/local/apache_php5/conf/httpd.conf

    also try changing

    <VirtualHost 127.0.0.1>

    to

    <VirtualHost 127.0.0.1:8080>

    in

    /usr/local/apache_php5/conf/httpd.conf

    Adding a sub domain using cPanel wasn't part of the tutorial and isn't required - it will add a sub domain config to /usr/local/apache/conf/httpd.conf that will prevent this working correctly if you do this, if the Include /usr/local/apache/conf/httpd.php5.conf is after the subdomain configuration that gets added by cPanel.
    In short, you don't need to add a subdomain, as you have created one manually if you follow the instructions here.
     
    #20 DigitalN, Feb 26, 2005
    Last edited: Feb 26, 2005
Loading...
Similar Threads - PHP5 PHP4 Hosting
  1. durangod
    Replies:
    2
    Views:
    218

Share This Page