您的位置:首页 > 数据库 > Memcache

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

2016-10-27 01:15 501 查看
公司的服务器基于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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  memcached lnmp