LNMP在Linux中運行多個PHP(PHP7 +PHP5.4 with memcached.so)

公司的服務器基於LNMP
並且需要使用PHP7+PHP5.4

安裝步驟

1.下載完整版lnmp,下載版可能會出問題.
2.正常安裝lnmp
3.正常安裝addons.sh的memcached
4.安裝PHP5.4並添加自啓動
5.安裝5.4的memcached與opcache擴展

安裝PHP5.4

通過參考php5.2.17.sh.編寫了以下腳本,
保存放置到lnmp安裝目錄運行即可,
注意添加執行權限:

#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH

# Check if user is root
if [ $(id -u) != "0" ]; then
    echo "Error: You must be root to run this script, please use root to install lnmp"
    exit 1
fi

. lnmp.conf
. include/version.sh
. include/main.sh
. include/init.sh
. include/php.sh

clear
echo "+-----------------------------------------------------------------------+"
echo "|           Install PHP 5.4.45 for LNMP, Written by Licess              |"
echo "+-----------------------------------------------------------------------+"
echo "|                 A tool to install PHP 5.4.45 for LNMP                 |"
echo "+-----------------------------------------------------------------------+"
echo "|          For more information please visit http://www.lnmp.org        |"
echo "+-----------------------------------------------------------------------+"

cur_dir=$(pwd)
Php_Ver='php-5.4.45'
Get_OS_Bit
Get_Dist_Name
Check_DB
Get_PHP_Ext_Dir
if echo "${Cur_PHP_Version}" | grep -Eqi '^5.4.'; then
    echo "Do NOT need to install PHP 5.4.45!"
    exit 1
fi

echo "=================================================="
echo "You will install PHP 5.4.45"
echo "=================================================="

Press_Start

Pear_Pecl_Set5445()
{
    pear config-set php_ini /usr/local/php54/etc/php.ini
    pecl config-set php_ini /usr/local/php54/etc/php.ini
}



Install_PHP_5445()
{
    Echo_Blue "[+] Installing ${Php_Ver}..."
    Tar_Cd ${Php_Ver}.tar.gz ${Php_Ver}

        ./configure --prefix=/usr/local/php54 --with-config-file-path=/usr/local/php54/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir=/usr/local/freetype --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --disable-fileinfo --enable-intl --with-xsl ${PHP_Modules_Options}


    make ZEND_EXTRA_LIBS='-liconv'
    make install



    echo "Copy new php configure file..."
    mkdir -p /usr/local/php54/etc
    \cp php.ini-production /usr/local/php54/etc/php.ini

    cd ${cur_dir}
    # php extensions
    echo "Modify php.ini......"
    sed -i 's/post_max_size =.*/post_max_size = 50M/g' /usr/local/php54/etc/php.ini
    sed -i 's/upload_max_filesize =.*/upload_max_filesize = 50M/g' /usr/local/php54/etc/php.ini
    sed -i 's/;date.timezone =.*/date.timezone = PRC/g' /usr/local/php54/etc/php.ini
    sed -i 's/short_open_tag =.*/short_open_tag = On/g' /usr/local/php54/etc/php.ini
    sed -i 's/;cgi.fix_pathinfo=.*/cgi.fix_pathinfo=0/g' /usr/local/php54/etc/php.ini
    sed -i 's/max_execution_time =.*/max_execution_time = 300/g' /usr/local/php54/etc/php.ini
    sed -i 's/disable_functions =.*/disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,popen,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server/g' /usr/local/php54/etc/php.ini
   #Pear_Pecl_Set54
    Install_Composer

    echo "Install ZendGuardLoader for PHP 5.4..."
    cd ${cur_dir}/src
    if [ "${Is_64bit}" = "y" ] ; then
        Download_Files ${Download_Mirror}/web/zend/ZendGuardLoader-70429-PHP-5.4-linux-glibc23-x86_64.tar.gz
        tar zxf ZendGuardLoader-70429-PHP-5.4-linux-glibc23-x86_64.tar.gz
        mkdir -p /usr/local/zend/
        \cp ZendGuardLoader-70429-PHP-5.4-linux-glibc23-x86_64/php-5.4.x/ZendGuardLoader.so /usr/local/zend/
    else
        Download_Files ${Download_Mirror}/web/zend/ZendGuardLoader-70429-PHP-5.4-linux-glibc23-i386.tar.gz
        tar zxf ZendGuardLoader-70429-PHP-5.4-linux-glibc23-i386.tar.gz
        mkdir -p /usr/local/zend/
        \cp ZendGuardLoader-70429-PHP-5.4-linux-glibc23-i386/php-5.4.x/ZendGuardLoader.so /usr/local/zend/
    fi

    echo "Write ZendGuardLoader to php.ini..."
    cat >>/usr/local/php54/etc/php.ini<<EOF

;eaccelerator

;ionCube

;opcache

[Zend ZendGuard Loader]
zend_extension=/usr/local/zend/ZendGuardLoader.so
zend_loader.enable=1
zend_loader.disable_licensing=0
zend_loader.obfuscation_level_support=3
zend_loader.license_path=

;xcache

EOF

    echo "Creating new php-fpm configure file..."
    cat >/usr/local/php54/etc/php-fpm.conf<<EOF
[global]
pid = /usr/local/php54/var/run/php-fpm.pid
error_log = /usr/local/php54/var/log/php-fpm.log
log_level = notice

[www]
listen = /tmp/php-cgi54.sock
listen.backlog = -1
listen.allowed_clients = 127.0.0.1
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.max_children = 10
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 6
request_terminate_timeout = 100
request_slowlog_timeout = 0
slowlog = var/log/slow.log
EOF

    echo "Copy php-fpm init.d file..."
    \cp ${cur_dir}/src/${Php_Ver}/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm54
    chmod +x /etc/init.d/php-fpm54

}

Install_PHP_5445

添加自啓動PHP5.4

chkconfig --add php-fpm54
chkconfig php-fpm54 on

安裝memcached擴展

wget http://pecl.php.net/get/memcached-2.2.0.tgz
tar xzf memcached-2.2.0.tgz
cd memcached-2.2.0
/usr/local/php54/bin/phpize
./configure --with-php-config=/usr/local/php54/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached/
make
make install

安裝opcache擴展

wget  ftp://soft.vpser.net/web/opcache/zendopcache-7.0.5.tgz
tar zvxf zendopcache-7.0.5.tgz
cd zendopcache-7.0.5
/usr/local/php54/bin/phpize
 ./configure --with-php-config=/usr/local/php54/bin/php-config
make&&make install

添加擴展

修改/usr/local/php54/etc/php.ini
此處的zend相關的擴展需要用絕對路徑

xtension=memcached.so
[Zend Opcache]
zend_extension=/usr/local/php54/lib/php/extensions/no-debug-non-zts-20100525/opcache.so
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable_cli=1
[Zend ZendGuard Loader]
zend_extension=/usr/local/zend/ZendGuardLoader.so
zend_loader.enable=1
zend_loader.disable_licensing=0
zend_loader.obfuscation_level_support=3
zend_loader.license_path=

PHP檢查命令

 /usr/local/php54/bin/php -v
 /usr/local/php54/bin/php -m

能夠看見memcached模塊

添加到nginx

保存以下內容到/usr/local/nginx/conf/enable-php5.4.45.conf

        {
            try_files $uri =404;
            fastcgi_pass  unix:/tmp/php-cgi54.sock;
            fastcgi_index index.php;
            include fastcgi.conf;
        }

其他注意事項

1.PHP7 開啓Opcache
2.PHP5.4 開啓Opcache

可能會用到命令:

腳本提示非法字符:
sed -i 's,\r,,;s, *$,,' php5.4.45.sh
發佈了63 篇原創文章 · 獲贊 30 · 訪問量 31萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章