Announcement

Collapse
No announcement yet.

Custom PHP per directory weird behavior

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Custom PHP per directory weird behavior

    So Ive noticed rather weird behavior of PHP selector. So were using lsapi on all of our cPanel server and configured them correctly in order to use custom PHP versions for some directories (added in /etc/container/php.handler lines like "application/x-lsphp52 /opt/alt/php52/usr/bin/lsphp" .
    So when we add string "AddType application/x-lsphp52 .php5 .php4 .php .php3 .php2 .phtml" to .htaccess, PHP version switches correctly. However it loads without necessary PHP modules (like mysql) while they are selected in PHP selector for this version:

    Code:
    # cl-selector --list-extensions=php --user dincomua --version=5.2
    
    bcmath
    
    dom
    
    gd
    
    hidef
    
    htscanner
    
    imap
    
    json
    
    mcrypt
    
    mysql
    
    mysqli
    
    pdo
    
    pdo_mysql
    
    pdo_sqlite
    
    phar
    
    posix
    
    sockets
    
    xmlreader
    
    xmlwriter
    Code:
    dincomua@shared [/root]# /opt/alt/php52/usr/bin/php -m
    
    [PHP Modules]
    
    bz2
    
    calendar
    
    ctype
    
    curl
    
    date
    
    exif
    
    filter
    
    ftp
    
    gettext
    
    gmp
    
    hash
    
    iconv
    
    libxml
    
    mhash
    
    openssl
    
    pcntl
    
    pcre
    
    readline
    
    Reflection
    
    session
    
    shmop
    
    SimpleXML
    
    SPL
    
    standard
    
    tokenizer
    
    xml
    
    zlib
    
    [Zend Modules]
    
    dincomua@shared [/root]#
    We noticed, that alt_php.ini loads only for currently selected PHP version, while for other PHP versions only empty default.ini loads:

    Code:
    dincomua@shared [/root]# ls -l /opt/alt/php5*/link/conf/
    
    /opt/alt/php51/link/conf/:
    
    total 12
    
    drwxr-xr-x  2 root  486 4096 Mar 22 02:18 ./
    
    drwxr-xr-x 13 root root 4096 Mar 22 02:18 ../
    
    -rw-r--r--  1 root  486  211 Mar  9 09:13 default.ini
    
    /opt/alt/php52/link/conf/:
    
    total 12
    
    drwxr-xr-x  2 root  486 4096 Mar 22 02:18 ./
    
    drwxr-xr-x 15 root root 4096 Mar 22 02:18 ../
    
    -rw-r--r--  1 root  486  268 Apr 22 14:36 default.ini
    
    /opt/alt/php53/link/conf/:
    
    total 12
    
    drwxr-xr-x  2 root  486 4096 Mar 22 02:18 ./
    
    drwxr-xr-x 15 root root 4096 Mar 22 02:18 ../
    
    -rw-r--r--  1 root  486  229 Mar  9 10:01 default.ini
    
    /opt/alt/php54/link/conf/:
    
    total 12
    
    drwxr-xr-x  2 root  486 4096 Mar 22 02:18 ./
    
    drwxr-xr-x 16 root root 4096 Mar 22 02:18 ../
    
    -rw-r--r--  1 root  486  229 Mar  9 09:32 default.ini
    
    /opt/alt/php55/link/conf/:
    
    total 12
    
    drwxr-xr-x  2 dincomua dincomua 4096 Apr 19 02:21 ./
    
    drwxr-xr-x 10 dincomua dincomua 4096 Feb  3 11:41 ../
    
    -rw-r--r--  1 dincomua dincomua  628 Apr 19 02:21 alt_php.ini
    
    /opt/alt/php56/link/conf/:
    
    total 12
    
    drwxr-xr-x  2 root  486 4096 Apr 19 02:05 ./
    
    drwxr-xr-x 14 root root 4096 Apr 19 02:06 ../
    
    -rw-r--r--  1 root  486  229 Apr  5 04:00 default.ini
    
    dincomua@shared [/root]#
    The content of default.ini below:

    Code:
    dincomua@shared [/root]# cat /opt/alt/php52/link/conf/default.ini
    
    ;extension=mbstring.so
    
    ;extension=bcmath.so
    
    ;extension=dom.so
    
    ;extension=json.so
    
    ;extension=gd.so
    
    ;extension=posix.so
    
    ;extension=sockets.so
    
    ;extension=xmlreader.so
    
    ;extension=xmlwriter.so
    
    ;extension=zip.so
    
    ;extension=fileinfo.so
    
    dincomua@shared [/root]#
    So the question is - how to connect selected in PHP selector modules for user, for PHP versions wich differs from the default one? As currently theres no point in switching between PHP versions inside one account (on directory basis).

    Sorry, if this topic was previosly discussed, as I havent found it

  • #2
    Unfortunately this is related to how php-selector works now... And so far there is no nice solution for it, quite same is described in this thread: http://old.cloudlinux.com/solutions/...m18/topic1121/

    The fix is not ready yet.

    Comment


    • #3
      As said in that older thread - a draft fix is:

      - remove /opt/alt/php53/etc/php.d directory

      Code:
      rm -rf /opt/alt/php53/etc/php.d
      - create a symlink on it to /etc/cl.php.d/alt-php53/

      Code:
       ln -s /etc/cl.php.d/alt-php53/ /opt/alt/php53/etc/php.d
      This should be done for all php versions.

      Comment


      • #4
        Thanks for your explanation Bogdan

        But today, when weve installed completely new server, we are not able to switch a PHP version using .htacces like it was before. So there is simply no effect on adding AddType directive in .htaccess (which we took from your documentation http://docs.cloudlinux.com/index.htm...d_lsapi.html):

        Code:
        [15:06] [shared01 ~] # cat /home/usertexample/public_html/.htaccess
        
        AddType application/x-httpd-lsphp .php5 .php4 .php .php3 .php2 .phtml
        
        AddType application/x-lsphp53 .php53
        
        [15:06] [shared01 ~] #
        Code:
        [15:00] [shared01 ~] # cat /etc/container/php.handler
        
        application/x-lsphp44 /opt/alt/php44/usr/bin/lsphp
        
        application/x-lsphp51 /opt/alt/php51/usr/bin/lsphp
        
        application/x-lsphp52 /opt/alt/php52/usr/bin/lsphp
        
        application/x-lsphp53 /opt/alt/php53/usr/bin/lsphp
        
        application/x-lsphp54 /opt/alt/php54/usr/bin/lsphp
        
        application/x-lsphp55 /opt/alt/php55/usr/bin/lsphp
        
        application/x-lsphp56 /opt/alt/php56/usr/bin/lsphp
        
        application/x-lsphp70 /opt/alt/php70/usr/bin/lsphp
        
        [15:06] [shared01 ~] #
        Ive tried to reinit cagefs and provide reinstallation of lsapi by running:
        /usr/bin/switch_mod_lsapi --uninstall
        /usr/bin/switch_mod_lsapi --setup
        /usr/bin/switch_mod_lsapi --enable-global

        But it didnt give any effect on situation, as file with extension .php53 still runs default PHP 5.6.

        Thanks in advance.

        Comment


        • #5
          I got the solution via ticket. So in order to make php per directory working you should:
          1. Create symlinks like Bogdan described
          2. Replace in /etc/httpd/conf/conf.d/lsapi.conf following strings:

          - AddType application/x-httpd-lsphp .php .php4 .php5 .php53 .php54 .php55 .php56 .php6 .phtml
          - AddHandler application/x-httpd-lsphp .php .php4 .php5 .php53 .php54 .php55 .php56 .php6 .phtml
          with the following ones:

          - AddType application/x-httpd-lsphp .php .php4 .php5 .phtml .php6
          - AddHandler application/x-httpd-lsphp .php .php4 .php5 .phtml .php6

          3. In .htaccess instead of adding AddType or AddHandler you should add the following:

          SetHandler application/x-lsphp53

          In my case this solution worked rather well.

          Comment

          Working...
          X