forked from teddysun/lamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmongodb.sh
86 lines (81 loc) · 2.61 KB
/
mongodb.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
#=========================================================#
# System Required: CentOS / RedHat / Fedora #
# Description: MongoDB extension for LAMP #
# Author: Teddysun <[email protected]> #
# Visit: https://lamp.sh #
#=========================================================#
if [[ $EUID -ne 0 ]]; then
echo "Error:This script must be run as root!" 1>&2
exit 1
fi
cur_dir=`pwd`
mongoVer=$(curl -s http://pecl.php.net/package/mongo | awk -F'>' '/mongo-.+.tgz/{print $3}' | cut -d'<' -f1 | sort -V | tail -1)
if [[ -z $mongoVer ]]; then
mongoVer="mongo-1.6.12.tgz"
fi
mongoFolder=$(echo $mongoVer | cut -d. -f1-3)
# Get PHP version
PHP_VER=$(php -r 'echo PHP_VERSION;' 2>/dev/null | awk -F. '{print $1$2}')
if [ $? -ne 0 ] || [[ -z $PHP_VER ]]; then
echo "Error: PHP looks like not installed, please check it and try again."
exit 1
fi
# Get PHP extensions date
if [ $PHP_VER -eq 53 ]; then
extDate='20090626'
elif [ $PHP_VER -eq 54 ]; then
extDate='20100525'
elif [ $PHP_VER -eq 55 ]; then
extDate='20121212'
elif [ $PHP_VER -eq 56 ]; then
extDate='20131226'
elif [ $PHP_VER -eq 70 ]; then
extDate='20151012'
fi
# Download mongodb extension
if [ -s $mongoVer ]; then
echo "${mongoVer} [found]"
else
echo "${mongoVer} not found!!!download now......"
if ! wget http://pecl.php.net/get/${mongoVer}; then
echo "Failed to download ${mongoVer},please download it to ${cur_dir} directory manually and retry."
exit 1
fi
fi
# Install mongodb extension
echo "Mongodb extension install start..."
if [ ! -d $cur_dir/untar/ ]; then
mkdir -p $cur_dir/untar/
fi
tar xzf $mongoVer -C $cur_dir/untar/
cd $cur_dir/untar/$mongoFolder
export PHP_PREFIX="/usr/local/php"
$PHP_PREFIX/bin/phpize
./configure -with-php-config=$PHP_PREFIX/bin/php-config
make && make install
if [ $? -ne 0 ]; then
echo "Installing PHP extension mongodb failed, Please visit https://lamp.sh/support.html and contact."
exit 1
fi
# Create ini file
if [ -s /usr/local/php/lib/php/extensions/no-debug-non-zts-${extDate}/mongo.so ]; then
if [ ! -f $PHP_PREFIX/php.d/mongo.ini ]; then
echo "mongodb configuration not found, create it!"
cat > $PHP_PREFIX/php.d/mongo.ini<<-EOF
[mongodb]
extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-${extDate}/mongo.so
EOF
fi
else
echo "Mongodb extension install failed!"
exit 1
fi
# Clean up
cd $cur_dir
rm -rf $cur_dir/untar/
rm -f $cur_dir/$mongoVer
# Restart httpd service
/etc/init.d/httpd restart
echo "Mongodb extension install completed..."
exit 0