You are not logged in.

#1 2011-03-02 22:13:25

NaX_sa
Member
From: South Africa
Registered: 2010-12-18
Posts: 12

[solved] Install PHP5.2 and PHP5.3 on dev laptop

I have been using Arch for a few months now on my laptop and really enjoying it, but I am still a little confused about a few things when it comes to software versions.

I have a bunch of PHP apps that need to be updated to be PHP 5.3 comparable. So I would like to setup both PHP 5.2 and PHP 5.3.

I have searched a lot assuming that I am not the first person that would have asked about this kind of setup, but failed to find anything that was Arch specific.

I have read about two ways of doing this on other distros.

One method involves setting up both version to be different CGI handlers in Apache and then setting the appropriate handler in your virtual hosts.

The second sets one version to use mod_php (php-apache) and the other as a CGI handler.

I have found both php version as packages and in AUR.

So, if I install both packages (php and php52) will there be any conflicts or problems or do I need to use the AUR packages and some how alter the install/configure scripts.

Additionally what would happen if I install one of the php modules EG: php-curl. Will the module work for both version.

I am currently leaning towards using mod_fcgid for both versions.

Thanks.

Last edited by NaX_sa (2011-03-08 22:08:47)

Offline

#2 2011-03-08 22:07:33

NaX_sa
Member
From: South Africa
Registered: 2010-12-18
Posts: 12

Re: [solved] Install PHP5.2 and PHP5.3 on dev laptop

OK, I figured it out. I think this topic should probably be under "Creating & Modifying Packages" and it was probably a mistake on my part to have posted in this forum in the first place.

What I ended up doing was to rebuild the php52 package in community using ABS. This was my first time use ABS.
I followed the instruction on the wiki https://wiki.archlinux.org/index.php/Arch_Build_System
The only thing I did that was not in the wiki was to delete the src directory when I did a rebuild, else it tried to re-apply the patch's, it took multiple attempts to get the PKGBUILD correct and not conflicting with PHP 5.3.

What I ended up with was a PHP package that installed everything into /usr/local.

I dont know if the way I did it was correct or the best way, but it seems to work.

Personally I think it would be best if the current PHP52 package was created in such away that it did not conflict with the main PHP package since it is very common for a LAMP setup to have more than one PHP versions installed.

Here is my modified PKGBUILD if anybody is interested.

# Maintainer: Evangelos Foutras <foutrelis@gmail.com>
# Contributor: Pierre Schmitz <pierre@archlinux.de>

pkgname=php52
pkgver=5.2.17
pkgrel=3
_suhosinver=5.2.16-0.9.7
pkgdesc='A high-level scripting language'
arch=('i686' 'x86_64')
license=('PHP')
url='http://www.php.net'
backup=('usr/local/etc/php/php.ini')
depends=('glibc' 'readline' 'ncurses' 'libxml2' 'pcre')
makedepends=('apache' 'imap' 'postgresql-libs' 'libmysqlclient'
             'libldap' 'postfix' 'libpng' 'libjpeg' 'sqlite3' 'unixodbc'
             'net-snmp' 'mhash' 'gmp' 'libmcrypt' 'tidyhtml' 'aspell' 'libtool'
             'freetype2' 'curl' 'libxslt' 'pam' 'openssl' 'bzip2' 'gdbm' 'db')
optdepends=('bzip2: bz2'
            'curl: curl'
            'gdbm: dba'
            'libpng: gd'
            'libjpeg: gd'
            'freetype2: gd'
            'pam: imap'
            'libldap: ldap'
            'libmcrypt: mcrypt'
            'libtool: mcrypt'
            'libmysqlclient: mysql/mysqli/pdo_mysql'
            'unixodbc: odbc/pdo_odbc'
            'openssl: openssl'
            'postgresql-libs: pgsql/pdo_pgsql'
            'aspell: pspell'
            'net-snmp: snmp'
            'sqlite3: pdo_sqlite'
            'tidyhtml: tidy'
            'libxslt: xsl'
            'mhash: mhash'
            'gmp: gmp')
provides=("php=$pkgver")
#conflicts=('php')
source=("http://php.net/distributions/php-${pkgver}.tar.bz2"
        "http://download.suhosin.org/suhosin-patch-${_suhosinver}.patch.gz"
        'php.ini'
        'apache.conf'
        'db-configure.patch'
        'db-5.patch'
        'libpng14.patch')
md5sums=('b27947f3045220faf16e4d9158cbfe13'
         'd815fc99a0c25c21f5df28551fcbb001'
         '55c09c89e34eb5c555d842a4d01590e6'
         '96ca078be6729b665be8a865535a97bf'
         'f3da248d934bc99354fdfa98cdac23ad'
         '40f3d5f546087dac33bfa21a85b79203'
         '77ea0756996df0932fce472ff3ec2693')

build() {
    phpconfig="--prefix=/usr/local \
    --sysconfdir=/usr/local/etc/php \
    --with-layout=PHP \
    --with-config-file-path=/usr/local/etc/php \
    --with-config-file-scan-dir=/usr/local/etc/php/conf.d \
    --enable-inline-optimization \
    --disable-debug \
    --disable-rpath \
    --disable-static \
    --enable-shared \
    --mandir=/usr/local/share/man \
    "

    phpextensions="--with-openssl=shared \
    --with-zlib=shared \
    --enable-bcmath=shared \
    --with-bz2=shared \
    --enable-calendar=shared \
    --with-curl=shared \
    --enable-dba=shared \
    --without-db2 \
    --without-db3 \
    --with-db4=shared \
    --with-gdbm=shared \
    --enable-dbase=shared \
    --enable-exif=shared \
    --enable-ftp=shared \
    --with-gd=shared \
    --enable-gd-native-ttf \
    --with-jpeg-dir=shared,/usr \
    --with-png-dir=shared,/usr \
    --with-gettext=shared \
    --with-imap=shared \
    --with-imap-ssl=shared \
    --with-ldap=shared \
    --enable-mbstring=shared \
    --with-mcrypt=shared \
    --with-mysql=shared \
    --with-mysql-sock=/var/run/mysqld/mysqld.sock \
    --with-mysql=shared \
    --with-mysqli=shared \
    --with-ncurses=shared \
    --with-unixODBC=shared,/usr \
    --enable-pdo=shared \
    --with-pdo-mysql=shared \
    --with-pdo-sqlite=shared,/usr \
    --with-pdo-odbc=shared,unixODBC,/usr \
    --with-pdo-pgsql=shared \
    --with-sqlite=shared \
    --enable-sqlite-utf8 \
    --with-pgsql=shared \
    --enable-shmop=shared \
    --with-snmp=shared \
    --enable-soap=shared \
    --enable-sysvmsg=shared \
    --enable-sysvsem=shared \
    --enable-sysvshm=shared \
    --with-tidy=shared \
    --with-xsl=shared \
    --enable-zip=shared \
    --enable-posix=shared \
    --enable-sockets=shared \
    --enable-xml \
    --with-ttf=shared \
    --enable-session=shared \
    --with-regex=php \
    --with-pcre-regex=/usr \
    --enable-mbstring=all \
    --enable-mbregex \
    --enable-json=shared \
    --with-iconv=shared \
    --with-xmlrpc=shared \
    --with-pspell=shared \
    --with-freetype-dir=shared,/usr \
    --with-mime-magic=shared \
    --with-gmp=shared \
    --with-mhash=shared \
    "

    PEAR_INSTALLDIR=/usr/local/share/pear
    export PEAR_INSTALLDIR

    cd ${srcdir}/php-${pkgver}

    # db 5.1 fix
    patch -p4 -i ${srcdir}/db-5.patch

    # avoid linking against old db version
    patch -p0 -i ${srcdir}/db-configure.patch

    # libpng 1.4 fix
    patch -p3 -i ${srcdir}/libpng14.patch

    # gmp 5.0 fix
    sed -i 's/__GMP_BITS_PER_MP_LIMB/GMP_LIMB_BITS/g' ext/gmp/gmp.c

    # apply suhosin patch
    patch -p1 -i ${srcdir}/suhosin-patch-${_suhosinver}.patch

    # cli
    ./configure ${phpconfig} \
        --disable-cgi \
        --with-readline \
        --enable-pcntl \
        --with-pear=/usr/local/share/pear \
        ${phpextensions}
    make
    # make test
    make -j1 INSTALL_ROOT=${pkgdir} install

    # cleanup
    rm -f ${pkgdir}`${pkgdir}/usr/local/bin/php-config --extension-dir`/*.a
    # install php.ini
    install -D -m644 ${srcdir}/php.ini ${pkgdir}/usr/local/etc/php/php.ini
    install -d -m755 ${pkgdir}/usr/local/etc/php/conf.d/

    # cgi and fcgi
    ./configure ${phpconfig} \
        --enable-fastcgi \
        --enable-cgi \
        --enable-discard-path \
        --enable-force-cgi-redirect \
        --disable-cli \
        ${phpextensions}
    make
    install -D -m755 sapi/cgi/php-cgi ${pkgdir}/usr/local/bin/php-cgi

    # mod_php
    ./configure ${phpconfig} \
        --with-apxs2 \
        --disable-cli \
        ${phpextensions}
    make
    install -D -m644 libs/libphp5.so ${pkgdir}/usr/lib/httpd/modules/libphp52.so
    install -D -m644 ${srcdir}/apache.conf ${pkgdir}/etc/httpd/conf/extra/php52_module.conf
}

After all that, I setup mod_fcgid and 2 test virtual hosts, one for each PHP version.
My setup was semi based on this tutorial http://2bits.com/articles/apache-fcgid- … ation.html

I ended up doing it with 3 Apache includes, excluding my vhosts include. I don't know if it is the best way of doing it, but considering this is a dev machine and I was going for easy management of PHP versions with multiple vhosts, I think this setup works well.

If anybody is interested here is my apache conf files.

/etc/httpd/conf/extra/fcgid_module.conf

# Server wide conf for fcgid
# Required modules: mod_fcgid
# FYI: All directives have been renamed in order to use a common prefix "Fcgid".
# see http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html

<IfModule mod_fcgid.c>
        # Maximum number of PHP processes
        MaxProcessCount             10   
</IfModule>

/etc/httpd/conf/extra/php52_fcgid.conf

# Required modules: mod_fcgid php5_cgi

<IfModule mod_fcgid.c>
        AddHandler fcgid-script .fcgi .php
        # Where to look for the php.ini file?
        DefaultInitEnv PHPRC        "/usr/local/etc/php"
        # Maximum requests a process handles before it is terminated
        MaxRequestsPerProcess       100
        # Number of seconds of idle time before a process is terminated
        IPCCommTimeout              240
        IdleTimeout                 240
        #Or use this if you use the file above
        FCGIWrapper /usr/local/bin/php-cgi .php
</IfModule>

/etc/httpd/conf/extra/php53_fcgid.conf

# Default PHP package config, PHP 5.3
# Required modules: mod_fcgid php5_cgi

<IfModule mod_fcgid.c>
        AddHandler fcgid-script .fcgi .php
        # Where to look for the php.ini file?
        DefaultInitEnv PHPRC        "/etc/php"
        # Maximum requests a process handles before it is terminated
        MaxRequestsPerProcess       100
        # Number of seconds of idle time before a process is terminated
        IPCCommTimeout              240
        IdleTimeout                 240
        # Or use this if you use the file above
        FCGIWrapper /usr/bin/php-cgi .php
</IfModule>

/etc/httpd/conf/extra/httpd-vhosts.conf (and adding of domain to /etc/hosts)

<VirtualHost *:80>
    ServerAdmin root@localhost
    DocumentRoot "/srv/http/php52.test"
    ServerName php52.test
    ErrorLog "/var/log/httpd/php52.test"
    CustomLog "/var/log/httpd/php52.test" common

    Include conf/extra/php52_fcgid.conf
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin root@localhost
    DocumentRoot "/srv/http/php53.test"
    ServerName php53.test     
    ErrorLog "/var/log/httpd/php53.test"
    CustomLog "/var/log/httpd/php53.test" common

    Include conf/extra/php53_fcgid.conf
</VirtualHost>

The rest was changes to my http.conf, here are most of the parts that changed.

#...

# mod_fcgid
LoadModule fcgid_module modules/mod_fcgid.so

#...

<Directory "/srv/http">
    #...
    Options Includes Indexes FollowSymLinks ExecCGI
    #...
</Directory>

#...

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

#...

# mod_fcgid server wide conf
Include conf/extra/fcgid_module.conf

I hope somebody else finds this useful. This was a learning experience for me.

Offline

#3 2011-04-11 08:36:24

mandos
Member
From: Greece
Registered: 2006-01-23
Posts: 101
Website

Re: [solved] Install PHP5.2 and PHP5.3 on dev laptop

although I'm looking to install only php52 on my system (and not both version) I read your post and believe that it should be mentioned in the wiki. Either in its own entry or as a link in the php entry

Offline

#4 2014-10-15 18:02:16

x-yuri
Member
Registered: 2013-01-06
Posts: 161

Re: [solved] Install PHP5.2 and PHP5.3 on dev laptop

I wanted to share the way I solved the problem. I decided to go with one of rbenv/rvm equivalents. I don't really like rvm, because it "is already doing too much, and trying to do more". I'm using rbenv for ruby. So I decided to give phpenv a try. I now understand there are several versions. With one I was unable do much:

$ phpenv install --releases
phpenv v0.0.4-dev

                    init extensions  the cloning of repositories for additional extensions           
<takes a while to complete>
$ phpenv install 5.3.29
phpenv v0.0.4-dev

I take it it's a rewrite of the second one. Which just clones rbenv's repository and patches it, as far as I can tell. But at least it somehow works. I was able to install php-5.3.29. But before that I had to install openssl 0.9.x from sources:

PHP_BUILD_CONFIGURE_OPTS=--with-openssl=/usr/local/ssl phpenv install 5.3.29

And to make it even better:

PHP_BUILD_CONFIGURE_OPTS='--with-openssl=/usr/local/ssl --with-mysql-sock' phpenv install 5.3.29

Also, luckily php had service file bundled, so I just copied it to ~/.config/systemd/user/php53-fpm.service (I decided to try and make it a user service), made some amendments:

[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target

[Service]
PIDFile=/home/yuri/.phpenv/versions/5.3.29/var/run/php-fpm.pid
ExecStart=/home/yuri/.phpenv/versions/5.3.29/sbin/php-fpm --nodaemonize --fpm-config /home/yuri/.phpenv/versions/5.3.29/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID

[Install]
WantedBy=multi-user.target

Copied ~/.phpenv/versions/5.3.29/etc/php-fpm.conf.default to ~/.phpenv/versions/5.3.29/etc/php-fpm.conf. Started the service:

$ systemctl --user start php53-fpm

And now it works.

Last edited by x-yuri (2014-10-15 18:29:50)

Offline

Board footer

Powered by FluxBB