#!/bin/sh # Description: 安裝memcached-1.4.36 SOFTWARE_DIR='/root/' # ERROR Output error_echo(){ printf "\033[31m $* \033[0m\n" } # 安裝php-redis擴展模塊 php_redis(){ cd ${SOFTWARE_DIR} && tar zxf php_redis-3.1.2.tgz && rm -rvf package.xmltar zxf php_redis-3.1.2.tgz && rm -rvf package.xml mv redis-3.1.2/ /usr/local/php/include/php/ext/redis/ && cd /usr/local/php/include/php/ext/redis/ /usr/local/php/bin/phpize && ./configure --with-php-config=/usr/local/php/bin/php-config && make && make install } # 安裝php-memcache擴展模塊 php_memcache(){ cd ${SOFTWARE_DIR} && tar zxf php_memcache-3.0.9.tgz mv memcache-3.0.9/ /usr/local/php/include/php/ext/memcache/ && cd /usr/local/php/include/php/ext/memcache/ /usr/local/php/bin/phpize && ./configure --with-php-config=/usr/local/php/bin/php-config && make && make install } # 安裝php-memcached擴展模塊 php_memcached(){ # 判斷系統中是否裝了libmemcached test -d /usr/local/php/include/php/ext/memcached/ if [ $? -ne 0 ]; then cd ${SOFTWARE_DIR} && tar zxf libmemcached-1.0.18.tar.gz -C /usr/src/ && cd /usr/src/libmemcached-1.0.18/ && ./configure --prefix=/usr/local/libmemcached --with-memcached && make && make install fi cd ${SOFTWARE_DIR} && tar zxf php_memcached-3.0.3.tgz && rm -rvf package.xml mv memcached-3.0.3/ /usr/local/php/include/php/ext/memcached/ && cd /usr/local/php/include/php/ext/memcached/ /usr/local/php/bin/phpize && ./configure --with-php-config=/usr/local/php/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached/ --enable-memcached && make && make install } # 安裝php-swoole擴展模塊 php_swoole(){ cd ${SOFTWARE_DIR} && tar zxf php_swoole-2.0.7.tgz && rm -rvf package.xml mv swoole-2.0.7/ /usr/local/php/include/php/ext/swoole && cd /usr/local/php/include/php/ext/swoole/ /usr/local/php/bin/phpize && ./configure --enable-swoole-debug --enable-openssl --enable-sockets --with-php-config=/usr/local/php/bin/php-config && make && make install } # 安裝php-yar擴展模塊 php_yar(){ cd ${SOFTWARE_DIR} && tar zxf php_yar-2.0.2.tgz && rm -rvf package.xml && rm -rvf package2.xml mv yar-2.0.2/ /usr/local/php/include/php/ext/yar/ && cd /usr/local/php/include/php/ext/yar/ /usr/local/php/bin/phpize && ./configure --with-php-config=/usr/local/php/bin/php-config && make && make install } # 安裝php-yaf擴展模塊 php_yaf(){ cd ${SOFTWARE_DIR} && tar zxf php_yaf-3.0.4.tgz && rm -rvf package.xml mv yaf-3.0.4/ /usr/local/php/include/php/ext/yaf/ && cd /usr/local/php/include/php/ext/yaf/ /usr/local/php/bin/phpize && ./configure --with-php-config=/usr/local/php/bin/php-config && make && make install } # 添加php.ini配置文件 php_config_add(){ echo '[opcache]' >> /usr/local/php/etc/php.ini echo 'zend_extension=opcache.so' >> /usr/local/php/etc/php.ini echo 'opcache.enable=1' >> /usr/local/php/etc/php.ini echo 'opcache.enable_cli=1' >> /usr/local/php/etc/php.ini echo 'opcache.memory_consumption=512' >> /usr/local/php/etc/php.ini echo 'opcache.interned_strings_buffer=8' >> /usr/local/php/etc/php.ini echo 'opcache.max_accelerated_files=10000' >> /usr/local/php/etc/php.ini echo 'opcache.fast_shutdown=1' >> /usr/local/php/etc/php.ini echo '' >> /usr/local/php/etc/php.ini echo '[redis]' >> /usr/local/php/etc/php.ini echo 'extension = "redis.so"' >> /usr/local/php/etc/php.ini echo '' >> /usr/local/php/etc/php.ini echo '[memcache]' >> /usr/local/php/etc/php.ini echo 'extension = "memcache.so"' >> /usr/local/php/etc/php.ini echo '' >> /usr/local/php/etc/php.ini echo '[memcached]' >> /usr/local/php/etc/php.ini echo 'extension = "memcached.so"' >> /usr/local/php/etc/php.ini echo '' >> /usr/local/php/etc/php.ini echo '[swoole]' >> /usr/local/php/etc/php.ini echo 'extension = "swoole.so"' >> /usr/local/php/etc/php.ini echo '' >> /usr/local/php/etc/php.ini echo '[yar]' >> /usr/local/php/etc/php.ini echo 'extension = "yar.so"' >> /usr/local/php/etc/php.ini echo 'yar.connect_timeout=60000' >> /usr/local/php/etc/php.ini echo '' >> /usr/local/php/etc/php.ini echo '[yaf]' >> /usr/local/php/etc/php.ini echo 'extension = "yaf.so"' >> /usr/local/php/etc/php.ini echo 'yaf.environ = product' >> /usr/local/php/etc/php.ini echo 'yaf.cache_config = 0' >> /usr/local/php/etc/php.ini echo 'yaf.name_suffix = 1' >> /usr/local/php/etc/php.ini echo 'yaf.name_separator = ""' >> /usr/local/php/etc/php.ini echo 'yaf.forward_limit = 5' >> /usr/local/php/etc/php.ini echo 'yaf.use_namespace = 1' >> /usr/local/php/etc/php.ini echo 'yaf.use_spl_autoload = ona' >> /usr/local/php/etc/php.ini } main(){ php_redis; php_memcache; php_memcached; php_swoole; php_yar; php_yaf; php_config_add; /etc/init.d/php-fpm restart if [ $? -eq 0 ]; then echo "php_module load successfully !!!" esle error_echo "php_module load failed !!!" fi } main