(gs):Install Zip for PHP 5

  • This page was last modified on March 24, 2012, at 12:36.
The (mt) Community Wiki is a collaborative project. Any (mt) Media Temple customer or employee may contribute. Not all articles and/or content have been tested for accuracy by (mt) Media Temple.

For officially moderated and tested articles, be sure to visit our KnowledgeBase.

From (mt) Community Wiki

Results

You will install the Zip utility for PHP 5 on your (gs) Grid-Service.

This is not supported by (mt) Media Temple. Also, it will be your responsibility to check for important security patches and updates for this extension. You should reinstall or update the extension once updates are available. Otherwise, your server may become vulnerable as your installed software becomes more and more outdated over time.

Instructions

  1. Log into your (gs) Grid-Service with SSH.
  2. Automatically set your site number variable and current PHP path for later use:
    export SITEID=`pwd | awk -F\/ '{ print $3 }'`
    

    If your site uses PHP 5.2.17:

    export PHPPATH=`php5 -i | grep "Configure Command" | perl -pe "s/.*'.\/configure'\s*?'--prefix\=(.*?)'.*/\1/"`
    

    If your site uses PHP 5.3.10:

    export PHPPATH=`php-latest -i | grep "Configure Command" | perl -pe "s/.*'.\/configure'\s*?'--prefix\=(.*?)'.*/\1/"`
    

    To verify and/or change what version of PHP is being used by your website, please visit the following KnowledgeBase link: How can I specify the PHP version on the (gs) Grid-Service?

  3. Make the library folder for Zip:
    mkdir -p /home/$SITEID/data/lib/php
    
  4. Set up a temporary folder for the Zip download:
    mkdir ~/zip
    
  5. Enter your temporary folder:
    cd ~/zip
    
  6. Download and decompress the Zip module (you will see a download bar):
    wget http://pecl.php.net/get/zip
    
    tar -zxvf zip
    
  7. Move into the zip directory (note: this directory path may change with later versions of zip):
    cd zip-1.10.2/
    
  8. Install Zip:
    $PHPPATH/bin/phpize
    
    ./configure --with-php-config=$PHPPATH/bin/php-config --enable-zip
    
    make
    
  9. Copy the compiled file to the lib folder we created previously:
    cp modules/zip.so /home/$SITEID/data/lib/php/
    
  10. Now we just need to tell Apache where to find the module. You can add the line of code to your existing php.ini file, or you can copy the sample file first, then add the line.

    If you need to copy the sample php.ini file, run this command (SKIP if you already have one):

    cp /home/$SITEID/etc/php.ini.sample /home/$SITEID/etc/php.ini
    

    Add the necessary directives to your php.ini file:

    echo -e "\n; Zip for PHP 5\nextension_dir=/home/$SITEID/data/lib/php\nextension=zip.so\n" >> /home/$SITEID/etc/php.ini
    


    Or, alternatively, open the php.ini file for editing:

    vi /home/$SITEID/etc/php.ini
    

    vi tip: Press "i" to enter "insert mode" so you can type and copy/paste. Press "Esc" to exit "insert mode" when you are done modifying the file. Type ":wq" to save and quit.

    Add the following lines to your php.ini (be sure to replace 00000 with your site number):

    php.ini
    
    ; Zip for PHP 5
    extension_dir=/home/00000/data/lib/php
    extension=zip.so
    

That's it! You should now be able to use Zip on your domains that are running PHP 5. You can test this by viewing your PHP 5 (gs):Phpinfo.php page. You should see a section for zip, and zip will also be listed in the "Registered PHP Streams" row.