Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Bash script for installing pecl_http package in Ubuntu
#!/usr/bin/env bash
echo 'Start installing pecl_http...'
test $EUID -eq 0 || { echo 'Please run script as root' && exit 1; }
type pecl > /dev/null 2>&1 || (
echo 'Install PEAR and PECL...' && apt-get install -y php-pear
cat <<-"PHPCODE" >> /usr/share/php/Archive/Tar.php
<?php
/**
* Missing zlib functions.
*/
if (!function_exists('gzopen')) {
function gzopen($filename, $mode, $use_include_path = 0) {
return gzopen64($filename, $mode, $use_include_path);
};
}
if (!function_exists('gzseek')) {
function gzseek($zp, $offset, $whence = SEEK_SET) {
return gzseek64($zp, $offset, $whence);
}
}
if (!function_exists('gztell')) {
function gztell($zp) {
return gztell64($zp);
}
}
?>
PHPCODE
)
type pecl > /dev/null 2>&1 && echo 'PEAR and PECL successfully installed' || { echo 'Error on PEAR and PECL installing' && exit 1; }
echo 'Check if pecl_http is installed...'
pecl shell-test pecl_http && echo 'Package pecl_http installed' && exit 0
echo 'Install system dependencies...'
apt-get install -y libpcre3-dev
echo 'Install PECL dependencies...'
echo 'Install raphf...'
pecl shell-test raphf && echo 'Package raphf installed' || (
pecl install raphf-1.1.2
pecl shell-test raphf || { echo 'Error on raphf installing' && exit 1; }
php -m | grep raphf && echo 'Module raphf enabled' || (
echo 'Enable module raphf...'
echo 'extension=raphf.so' > /etc/php5/mods-available/raphf.ini
(cd /etc/php5/cli/conf.d; test -e 30-raphf.ini || ln -s ../../mods-available/raphf.ini 20-raphf.ini)
(cd /etc/php5/fpm/conf.d; test -e 30-raphf.ini || ln -s ../../mods-available/raphf.ini 20-raphf.ini)
)
php -m | grep raphf || { echo 'Error on raphf enabling' && exit 1; }
)
echo 'Install propro...'
pecl shell-test propro && echo 'Package propro installed' || (
pecl install propro-1.0.2
pecl shell-test propro || { echo 'Error on propro installing' && exit 1; }
php -m | grep propro && echo 'Module propro enabled' || (
echo 'Enable module propro...'
echo 'extension=propro.so' > /etc/php5/mods-available/propro.ini
(cd /etc/php5/cli/conf.d; test -e 30-propro.ini || ln -s ../../mods-available/propro.ini 25-propro.ini)
(cd /etc/php5/fpm/conf.d; test -e 30-propro.ini || ln -s ../../mods-available/propro.ini 25-propro.ini)
)
php -m | grep propro || { echo 'Error on propro enabling' && exit 1; }
)
echo 'Install pecl_http...'
yes '' | pecl install pecl_http-2.5.5
php -m | grep http && echo 'Module http enabled' || (
echo 'Enable module http...'
echo 'extension=http.so' > /etc/php5/mods-available/http.ini
(cd /etc/php5/cli/conf.d; test -e 30-http.ini || ln -s ../../mods-available/http.ini 30-http.ini)
(cd /etc/php5/fpm/conf.d; test -e 30-http.ini || ln -s ../../mods-available/http.ini 30-http.ini)
php -m | grep http || { echo 'Error on http enabling' && exit 1; }
)
echo 'Restart php fpm'
service php5-fpm restart
echo 'Package pecl_http successfully installed'
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment