1. Please take a little time for this simple survey! Thank you for participating!
    Dismiss Notice
  2. Dear Pleskians, please read this carefully! New attachments and other rules Thank you!
    Dismiss Notice
  3. Dear Pleskians, I really hope that you will share your opinion in this Special topic for chatter about Plesk in the Clouds. Thank you!
    Dismiss Notice

Two PHP versions linux Plesk HOWTO

Discussion in 'Plesk 10.x for Linux Suggestions and Feedback' started by Igor Smitran, Apr 25, 2012.

  1. Igor Smitran

    Igor Smitran New Pleskian

    11
     
    Joined:
    Apr 25, 2012
    Messages:
    24
    Likes Received:
    0
    Few days ago i was exchanging emails with Parallels support. I was asking them to help me to setup two php versions on linux plesk server. After few emails they answeared me that it is not possible. It didn't help when i told them that i was using fastcgi on my own hosting server and that i was having 3 php versions configurable per customer. Nop... Their answear was
    And, there i was, left helpless, without possibility to finish migration from my old hosting server to our new and shiny Plesk. I needed newer php version because php provided by my linux distro is 5.1.
    So, i logged in to Plesk server and spend around 20 minutes planning how to intercept Plesk calls. And it is done.
    For this to work you have to have php running as fastcgi (it is most secure way, so i assume that everyone is running php as fastcgi)
    Here it goes:

    1. ssh to your plesk server, download php source, unpack it and configure it
    Code:
    ssh yourserver -l root
    cd /usr/local/src
    mkdir php540
    cd php540
    wget http://www.php.net/get/php-5.4.0.tar.gz/from/at2.php.net/mirror
    tar xzvf php-5.4.0.tar.gz
    cd php-5.4.0
    
    NOTICE: you HAVE TO USE PREFIX switch in order to have your new php installed inside one directory, for example:

    Code:
    ./configure '--with-libdir=lib64' '--cache-file=../config.cache' '--prefix=/usr/local/php540-cgi' '--with-config-file-path=/usr/local/php540-cgi/etc' '--disable-debug' '--with-pic' '--disable-rpath' '--with-bz2' '--with-curl' '--with-freetype-dir=/usr/local/php540-cgi' '--with-png-dir=/usr/local/php540-cgi' '--enable-gd-native-ttf' '--without-gdbm' '--with-gettext' '--with-gmp' '--with-iconv' '--with-jpeg-dir=/usr/local/php540-cgi' '--with-openssl' '--with-pspell' '--with-pcre-regex' '--with-zlib' '--enable-exif' '--enable-ftp' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-sysvmsg' '--enable-wddx' '--with-kerberos' '--with-unixODBC=/usr' '--enable-shmop' '--enable-calendar' '--without-sqlite3' '--with-libxml-dir=/usr/local/php540-cgi' '--enable-pcntl' '--with-imap' '--with-imap-ssl' '--enable-mbstring' '--enable-mbregex' '--with-gd' '--enable-bcmath' '--with-xmlrpc' '--with-ldap' '--with-ldap-sasl' '--with-mysql=/usr' '--with-mysqli' '--with-snmp' '--enable-soap' '--with-xsl' '--enable-xmlreader' '--enable-xmlwriter' '--enable-pdo' '--with-pdo-mysql' '--with-pdo-pgsql' '--with-pear=/usr/local/php540-cgi/pear' '--with-mcrypt' '--enable-intl' '--without-pdo-sqlite'
    
    As you can see, my prefix was /usr/local/php540-cgi/
    Choosing a prefix is a MUST because that way your new php installation will not interfere with older php used by plesk.

    2. compile your php
    Code:
    make
    
    3. install your new php
    Code:
    make install
    
    4. create php wrapper
    for example, let's say that you have a customer blabla.com that uses some newer php functions that don't exist in php 5.1. Let's call that customer blabla.com. For him we will tell apache to use our new php (5.4.0)
    Code:
    cd /var/www/vhosts/blabla.com/cgi-bin
    mkdir .cgi_wrapper
    cd .cgi_wrapper
    
    now we will create new file and name it .phpwrapper
    Code:
    vi .phpwrapper
    
    file content:
    Code:
    #!/bin/sh
    export PHPRC=/var/www/vhosts/blabla.com/etc/
    export PHP_FCGI_CHILDREN=4
    export PHP_FCGI_MAX_REQUESTS=1000
    exec /usr/local/php540-cgi/bin/php-cgi
    
    let's strengthen our new files and dirs permissions and privileges:
    Code:
    cd /var/www/vhosts/blabla.com/cgi-bin
    chmod 101 .cgi_wrapper
    chmod 500 .cgi_wrapper/.phpwrapper
    chown blabla.com:psacln .cgi_wrapper -R
    chattr -R +i .cgiwrapper
    
     
  2. Igor Smitran

    Igor Smitran New Pleskian

    11
     
    Joined:
    Apr 25, 2012
    Messages:
    24
    Likes Received:
    0
    5. make apache aware of our wrapper
    plesk offers a functionality of changing httpd setup per host. we will use that functionality to tell apache that for blabla.com it needs to use our new wrapper, instead of one provided by plesk:
    Code:
    cd /var/www/vhosts/blabla.com/conf
    
    we will create file named vhost.conf
    Code:
    vi vhost.conf
    
    file content:
    Code:
    <Directory /var/www/vhosts/blabla.com/httpdocs>
    RemoveHandler fcgid-script
    <IfModule mod_fcgid.c>
        AddHandler fcgid-script .php
        <Files ~ (\.php)>
            SetHandler fcgid-script
            FCGIWrapper /var/www/vhosts/blabla.com/cgi-bin/.cgi_wrapper/.phpwrapper .php
            Options +ExecCGI
            allow from all
        </Files>
    </IfModule>
    </Directory>
    
    So, we have told apache not to use plesk php wrapper (RemoveHandler fcgid-script) and instead of that we have created a new handler for php files. When executing php files on blabla.com domain apache will call our wrapper and use new php that we installed

    6. we need to reconfigure blabla.com domain
    Code:
    /usr/local/psa/admin/sbin/httpdmng --reconfigure-domain blabla.com
    
    7. and restart apache
    Code:
    /etc/init.d/httpd restart
    
    That's it. For every domain that needs some extra functions provided only in php versions newer than one provided with your plesk distro you can do steps 4,5,6 and 7 (replace blabla.com with your customer domain name) and that's all.
     
  3. EgidijusS

    EgidijusS Regular Pleskian

    23
    23%
    Joined:
    Jan 22, 2010
    Messages:
    183
    Likes Received:
    0
    Location:
    Vilnius, Lithuania
    Respect. Thanks for great tutorial.
     
  4. IgorG

    IgorG Forums Analyst Staff Member

    49
    24%
    Joined:
    Oct 27, 2009
    Messages:
    24,576
    Likes Received:
    1,243
    Location:
    Novosibirsk, Russia
    Igor Smitran, Thank you. Your concern is clear, we will consider making corresponding KB article.
     
  5. Igor Smitran

    Igor Smitran New Pleskian

    11
     
    Joined:
    Apr 25, 2012
    Messages:
    24
    Likes Received:
    0
    You should also consider implementing this into plesk. Let's leave it to the administrator installing of php, in that case you should consider:

    1. possibility of inserting php version awareness into plesk (something windows version already has)
    2. automating creation of wrapper and httpd.conf
     
  6. huglester

    huglester New Pleskian

    22
    73%
    Joined:
    Jan 23, 2009
    Messages:
    19
    Likes Received:
    0
    re

    I'm replying to this topic to subscribe to it.

    Also I think it would be good to have plesk unlimited options,
    like I saw in one of DirectAdmin instalations - screenshot: http://d.pr/i/eWQr

    So we have PHP 5.2, 5.3, 5.4 and 5.5 soon.

    It will make Plesk more powerfull than ever, since PHP version problem is from the very beginning and always was.
     
  7. EgidijusS

    EgidijusS Regular Pleskian

    23
    23%
    Joined:
    Jan 22, 2010
    Messages:
    183
    Likes Received:
    0
    Location:
    Vilnius, Lithuania
    That would be great feature. Now if you have lot clients with different PHP versions you need separate servers to fit your needs. With this feature all clients can fitted in one server.
     
  8. futureweb

    futureweb Regular Pleskian

    28
    23%
    Joined:
    Feb 4, 2007
    Messages:
    186
    Likes Received:
    4
    Location:
    Tirol, Austria
    Thank you for this great Guide!

    We would also like to see this feature implemented into Plesk - would be a great addition!!

    Andreas Schnederle-Wagner
     
    Last edited: Oct 4, 2012
  9. Faris Raouf

    Faris Raouf Silver Pleskian Plesk Guru

    31
    30%
    Joined:
    Mar 15, 2009
    Messages:
    667
    Likes Received:
    17
    The problem is that at least one of the versions of PHP would have to be provided by Parallels, and updated by them too.

    Maybe it would be best just to have an "additional php" selection within the hosting selection in Plesk (similar to the alternative webmail option) and let the admin worry about obtaining, compiling and installing? I'd really like that.
     
  10. sergius

    sergius Golden Pleskian

    28
    57%
    Joined:
    Nov 6, 2005
    Messages:
    1,898
    Likes Received:
    0
    http://kb.parallels.com/114753
     
  11. futureweb

    futureweb Regular Pleskian

    28
    23%
    Joined:
    Feb 4, 2007
    Messages:
    186
    Likes Received:
    4
    Location:
    Tirol, Austria
    For me as Server-Admin it would be perfectly OK to manage the different PHP Versions on Plesk Servers. Would just be a killer Feature if our Plesk Admins could choose between them in GUI ... so they don't need a Server-Admin anytime they need a different PHP Version for a Hosting ... :)
     
  12. futureweb

    futureweb Regular Pleskian

    28
    23%
    Joined:
    Feb 4, 2007
    Messages:
    186
    Likes Received:
    4
    Location:
    Tirol, Austria
    btw) you got a typo in the KB

    last Line should be:
    And I would suggest adding this param to the PHP configure - otherwise all PHP installations will share the same "additional config files":
     
  13. IgorG

    IgorG Forums Analyst Staff Member

    49
    24%
    Joined:
    Oct 27, 2009
    Messages:
    24,576
    Likes Received:
    1,243
    Location:
    Novosibirsk, Russia
    Thank you. I have updated article with your recommendations.
     
  14. Igor Smitran

    Igor Smitran New Pleskian

    11
     
    Joined:
    Apr 25, 2012
    Messages:
    24
    Likes Received:
    0
    If you are talking about php.ini then you are wrong, php.ini location is inside PHPRC environment variable. Since every domain has different wrapper, php.ini location is here:

    Code:
    export PHPRC=/var/www/vhosts/blabla.com/etc/
    
    so, php.ini is inside user directory and you are able to setup php.ini per user, easily.

    Thank you for typo notice :)
     
    Last edited: Sep 13, 2012
  15. futureweb

    futureweb Regular Pleskian

    28
    23%
    Joined:
    Feb 4, 2007
    Messages:
    186
    Likes Received:
    4
    Location:
    Tirol, Austria
    Hi,

    speaking about "/etc/php.d/xxx" <-- those will be shared along all PHP installs without passing '--with-config-file-scan-dir=/usr/local/php540-cgi/php.d' to configure - happened when I installed second PHP Version on our Plesk Server ;-)

    Andreas
     
  16. SauliusZ

    SauliusZ Basic Pleskian

    12
    35%
    Joined:
    Sep 1, 2012
    Messages:
    31
    Likes Received:
    0
    I have Plesk 11 installed on CentOS 6 with PHP 5.3.3 and wanted to install PHP 5.2.17 for some websites using your instructions.
    But after that I`ve got an error in /var/www/vhosts/domain.com/statistics/logs/error_log saying:
    [warn] [client x.x.x.x] (104)Connection reset by peer: mod_fcgid: error reading data from FastCGI server
    [error] [client x.x.x.x] Premature end of script headers: index.php

    Do you know what could be wrong?
     
  17. futureweb

    futureweb Regular Pleskian

    28
    23%
    Joined:
    Feb 4, 2007
    Messages:
    186
    Likes Received:
    4
    Location:
    Tirol, Austria
    PHP binary works?

     
  18. SauliusZ

    SauliusZ Basic Pleskian

    12
    35%
    Joined:
    Sep 1, 2012
    Messages:
    31
    Likes Received:
    0
    Well, I have installed php in /usr/local/php520-cgi/

    And trying ./php -v I get:
    with ./php -i I get lots of information.

    By default command php -v I get:
     
  19. futureweb

    futureweb Regular Pleskian

    28
    23%
    Joined:
    Feb 4, 2007
    Messages:
    186
    Likes Received:
    4
    Location:
    Tirol, Austria
    chmod/chown of the wrapper/directory are correct?
     
  20. SauliusZ

    SauliusZ Basic Pleskian

    12
    35%
    Joined:
    Sep 1, 2012
    Messages:
    31
    Likes Received:
    0
    I did this commands:

    So the chown/chmod is made by this.
     
Loading...