CentOS下OpenLiteSpeed+Tengine安装及多PHP版本共存教程
使用自己最熟悉的CentOS系统,我使用的是CentOS 6 x32,最小化安装,然后做适度优化,接下来开始安装吧!
咱们先查看下CPU是几核的,方便之后编译时充分利用CPU资源(注意,在之后所有安装中,make -j 4 均为此例,请各位根据自己的CPU核心数进行相应修改)
- cat /proc/cpuinfo | grep processor | wc -l
这里可以看到我的CPU是4核的
1.VPS优化
首先对系统做适当精简,节省VPS资源,这里请各位根据自己的实际情况来进行精简,不要直接复制粘贴,避免运行出错
1.1.删除不必要的程序
- yum -y remove Deployment_Guide-en-US finger cups-libs cups ypbind bluez-libs desktop-file-utils ppp rp-pppoe wireless-tools irda-utils sendmail*samba* talk-server finger-server bind* xinetd nfs-utils nfs-utils-lib rdate fetchmail eject ksh mkbootdisk mtools syslinux tcsh startup-notification talk apmd rmt dump setserial portmap yp-tools
- yum -y groupremove "Mail Server" "Games and Entertainment" "X Window System" "X Software Development" "Development Libraries" "Dialup Networking Support" "Games and Entertainment" "Sound and Video" "Graphics" "Editors" "Text-based Internet" "GNOME Desktop Environment" "GNOME Software Development"
1.2.禁用Selinux
- sed -i 's/^SELINUX=.*$/SELINUX=disabled/' /etc/selinux/config
1.3.配置yum
为了避免yum时无法找到相应的版本,修改下yum
- sed -i 's:exclude=.*:exclude=:g' /etc/yum.conf
1.4.关闭不需要的服务
使用 chkconfig xxx off 和 chkconfig –del xxx 对系统服务进行精简,请各位根据实际情况进行精简,我保留的服务
2.安装前准备
2.1.删除自带Web程序
- yum remove httpd* php* mysql-server mysql* php-mysql -y
2.2.安装Epel
因为OpenLiteSpeed编译安装需要使用到geoip,而直接yum可能会找不到,所以咱们需要用到epel
- rpm -ivh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
2.3.安装依赖库
- yum -y install ncurses ncurses-devel glibc wget flex re2c unzip bison gcc autoconf autoconf213 automake mhash-devel cmake ruby file bzip2 bzip2-devel diff* libtool libtool-libs gcc-c++ libjpeg libjpeg-devel libpng libpng-devel libxml2 libxml2-devel curl curl-devel libmcrypt-devel freetype freetype-devel patch make zlib zlib-devel libtool-ltdl-devel expat-devel pcre-devel geoip-devel openssl-devel openldap-devel e2fsprogs e2fsprogs-devel krb5-devel libidn libidn-devel vixie-cron libevent libevent-devel
2.4.更新系统
- yum -y update
- yum clean all
2.5.创建源码存放目录
为了方便安装,我在/home/下创建llnmp目录,将所有需要安装的源码包下载并存放到此目录中
- mkdir -p /home/llnmp
- cd /home/llnmp
3.开始安装
3.1.安装Jemalloc
Jemalloc是一款内存优化组件,可以用它来对数据库等程序进行优化
- wget -c http://soft.shuang.ca/jemalloc/jemalloc-3.5.1.tar.bz2 -O /home/llnmp/jemalloc-3.5.1.tar.bz2
- tar jxf jemalloc-3.5.1.tar.bz2
- cd jemalloc-3.5.1
- ./configure && make -j 4 && make install
- echo '/usr/local/lib' > /etc/ld.so.conf.d/local.conf
- ldconfig
- cd /home/llnmp
3.2.安装MariaDB数据库
MariaDB数据库是MySQL作者由于开源问题重新开发的数据库,与MySQL通用,至于说谁好谁坏,其实都差不多,不过基于对开源的支持,咱们可以选择MariaDB进行安装使用
3.2.1.添加用户、创建目录
- useradd -M -s /sbin/nologin mysql
- rm -f /etc/my.cnf
- mkdir -p /data/mysql
3.2.2.下载安装
由于之前安装了Jemalloc,所以在编译时添加一个参数-DCMAKE_EXE_LINKER_FLAGS=’-ljemalloc’
- wget -c http://soft.shuang.ca/mariadb/mariadb-5.5.36.tar.gz -O /home/llnmp/mariadb-5.5.36.tar.gz
- tar zxf mariadb-5.5.36.tar.gz
- cd mariadb-5.5.36
- cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DWITH_ARIA_STORAGE_ENGINE=1 -DWITH_XTRADB_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_FEDERATEDX_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EMBEDDED_SERVER=OFF -DCMAKE_EXE_LINKER_FLAGS='-ljemalloc'
- make -j 4 && make install
- cp support-files/mysql.server /etc/init.d/mysqld
- chmod +x /etc/init.d/mysqld
- chkconfig --add mysqld
- chkconfig mysqld on
3.2.3.配置并优化
编辑创建配置文件/etc/my.cnf,内容如下
- [client]
- port = 3306
- socket = /tmp/mysql.sock
- [mysqld]
- port = 3306
- socket = /tmp/mysql.sock
- basedir = /usr/local/mysql
- datadir = /data/mysql
- pid-file = /data/mysql/mysql.pid
- user = mysql
- bind-address = 127.0.0.1 #无需外部访问数据库,所以直接指定仅本机访问
- server-id = 1
- skip-name-resolve
- #skip-networking
- back_log = 600
- max_connections = 1000
- max_connect_errors = 6000
- open_files_limit = 65535
- table_open_cache = 128
- max_allowed_packet = 4M
- binlog_cache_size = 1M
- max_heap_table_size = 8M
- tmp_table_size = 16M
- read_buffer_size = 2M
- read_rnd_buffer_size = 8M
- sort_buffer_size = 8M
- join_buffer_size = 8M
- key_buffer_size = 4M
- thread_cache_size = 8
- query_cache_size = 8M
- query_cache_limit = 2M
- ft_min_word_len = 4
- log_bin = mysql-bin
- binlog_format = mixed
- expire_logs_days = 30
- log_error = /data/mysql/mysql-error.log
- slow_query_log = 1
- long_query_time = 1
- slow_query_log_file = /data/mysql/mysql-slow.log
- performance_schema = 0
- #lower_case_table_names = 1
- skip-external-locking
- default_storage_engine = InnoDB
- #default-storage-engine = MyISAM
- innodb_file_per_table = 1
- innodb_open_files = 500
- innodb_buffer_pool_size = 64M
- innodb_write_io_threads = 4
- innodb_read_io_threads = 4
- innodb_thread_concurrency = 0
- innodb_purge_threads = 1
- innodb_flush_log_at_trx_commit = 2
- innodb_log_buffer_size = 2M
- innodb_log_file_size = 32M
- innodb_log_files_in_group = 3
- innodb_max_dirty_pages_pct = 90
- innodb_lock_wait_timeout = 120
- bulk_insert_buffer_size = 8M
- myisam_sort_buffer_size = 8M
- myisam_max_sort_file_size = 10G
- myisam_repair_threads = 1
- interactive_timeout = 28800
- wait_timeout = 28800
- [mysqldump]
- quick
- max_allowed_packet = 16M
- [myisamchk]
- key_buffer_size = 8M
- sort_buffer_size = 8M
- read_buffer = 4M
- write_buffer = 4M
根据内存大小自动进行优化
- Memtatol=`free -m | grep 'Mem:' | awk '{print $2}'`
- if [ $Memtatol -gt 1500 -a $Memtatol -le 2500 ]; then
- sed -i 's/table_open_cache = 128/table_open_cache = 256/g' /etc/my.cnf
- sed -i 's/tmp_table_size = 16M/tmp_table_size = 32M/g' /etc/my.cnf
- sed -i 's/thread_cache_size = 8/thread_cache_size = 16/g' /etc/my.cnf
- sed -i 's/query_cache_size = 8M/query_cache_size = 16M/g' /etc/my.cnf
- sed -i 's/innodb_buffer_pool_size = 64M/innodb_buffer_pool_size = 128M/g' /etc/my.cnf
- sed -i 's/myisam_sort_buffer_size = 8M/myisam_sort_buffer_size = 16M/g' /etc/my.cnf
- sed -i 's/key_buffer_size = 8M/key_buffer_size = 16M/g' /etc/my.cnf
- elif [ $Memtatol -gt 2500 -a $Memtatol -le 3500 ]; then
- sed -i 's/table_open_cache = 128/table_open_cache = 512/g' /etc/my.cnf
- sed -i 's/tmp_table_size = 16M/tmp_table_size = 64M/g' /etc/my.cnf
- sed -i 's/thread_cache_size = 8/thread_cache_size = 32/g' /etc/my.cnf
- sed -i 's/query_cache_size = 8M/query_cache_size = 32M/g' /etc/my.cnf
- sed -i 's/innodb_buffer_pool_size = 64M/innodb_buffer_pool_size = 512M/g' /etc/my.cnf
- sed -i 's/myisam_sort_buffer_size = 8M/myisam_sort_buffer_size = 32M/g' /etc/my.cnf
- sed -i 's/key_buffer_size = 8M/key_buffer_size = 64M/g' /etc/my.cnf
- elif [ $Memtatol -gt 3500 ];then
- sed -i 's/table_open_cache = 128/table_open_cache = 1024/g' /etc/my.cnf
- sed -i 's/tmp_table_size = 16M/tmp_table_size = 128M/g' /etc/my.cnf
- sed -i 's/thread_cache_size = 8/thread_cache_size = 64/g' /etc/my.cnf
- sed -i 's/query_cache_size = 8M/query_cache_size = 64M/g' /etc/my.cnf
- sed -i 's/innodb_buffer_pool_size = 64M/innodb_buffer_pool_size = 1024M/g' /etc/my.cnf
- sed -i 's/myisam_sort_buffer_size = 8M/myisam_sort_buffer_size = 64M/g' /etc/my.cnf
- sed -i 's/key_buffer_size = 8M/key_buffer_size = 256M/g' /etc/my.cnf
- fi
- /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
- chown mysql.mysql -R /data/mysql
- chgrp -R mysql /usr/local/mysql/.
- ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
- ln -s /usr/local/mysql/include/mysql /usr/include/mysql
- ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
- ln -s /usr/local/mysql/bin/mysqldump /usr/bin/mysqldump
- ln -s /usr/local/mysql/bin/myisamchk /usr/bin/myisamchk
- ln -s /usr/local/mysql/bin/mysqld_safe /usr/bin/mysqld_safe
启动数据库并设置root密码
- ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib #若启动失败,请执行这条命令
- service mysqld start
- /usr/local/mysql/bin/mysqladmin -u root password shuang.ca
- cat >>/tmp/mysql_sec_script< <EOF
- use mysql;
- update user set password=password('shuang.ca') where user='root';
- delete from user where not (user='root') ;
- delete from user where user='root' and password='';
- drop database test;
- DROP USER ''@'%';
- flush privileges;
- EOF
- /usr/local/mysql/bin/mysql -u root -pshuang.ca -h localhost < /tmp/mysql_sec_script
- rm -f /tmp/mysql_sec_script
- service mysqld restart
4.安装OpenLitespeed
OpenLitespeed其实可以使用yum进行安装,不过为了方便配置,我使用源码进行安装
4.1.创建用户
- useradd -M -s /sbin/nologin www
4.2.下载并安装
- wget -c http://soft.shuang.ca/openlitespeed/openlitespeed-1.2.9.tgz -O /home/llnmp/openlitespeed-1.2.9.tgz
- cd /home/llnmp
- tar zxf openlitespeed-1.2.9.tgz
- cd openlitespeed-1.2.9
- ./configure --prefix=/usr/local/lsws --with-user=www --with-group=www --with-admin=admin --with-password=shuang.ca --with-email=admin@shuang.ca --enable-adminssl=no --enable-spdy #admin为登录用户,shuang.ca为密码,admin@shuang.ca为管理员邮箱,请自行修改
- make -j 4 && make install
4.3.启动并测试
- service lsws restart
打开浏览器,输入:http://ip:8088访问看下是否能够打开了?
由于我使用Tengine作为前端,所以这里就不修改openlitespeed的端口了,若不使用前端,则可以登录openlitespeed管理后台进行修改
5.安装Tengine
这里使用Tengine作为前端,因为Tengine作为淘宝开发改进的Nginx增强版,完全支持Nginx配置,且对于大并发有较强的处理性能
5.1.下载并配置
- wget -c http://soft.shuang.ca/tengine/tengine-2.0.2.tar.gz -O /home/llnmp/tengine-2.0.2.tar.gz
- cd /home/llnmp
- tar zxf tengine-2.0.2.tar.gz
- cd tengine-2.0.2
Tengine默认会安装debug,但是对于我们来说是完全没有必要的,安装了反而增加了几M的空间占用,所以我们可以去掉
- sed -i 's@CFLAGS="$CFLAGS -g"@#CFLAGS="$CFLAGS -g"@' auto/cc/gcc
同时,我们还可以根据自己的需求隐藏Tengine版本号,甚至修改为自己的定制信息,vi src/core/nginx.h,修改为如下内容
- #ifndef _NGINX_H_INCLUDED_
- #define _NGINX_H_INCLUDED_
- #define nginx_version 1004006
- #define NGINX_VERSION "1.0"
- #define NGINX_VER "Shuang.Ca/"
- #define TENGINE "Shuang.Ca"
- #define tengine_version 2000002
- #define TENGINE_VERSION "1.0"
- #define TENGINE_VER TENGINE "/" TENGINE_VERSION
- #define NGINX_VAR "Shuang.Ca"
- #define NGX_OLDPID_EXT ".oldbin"
5.2.安装并配置
同样的,我们之前安装了Jemalloc,现在也一样要添加一个参数–with-ld-opt=’-ljemalloc’
- ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-http_concat_module=shared --with-ld-opt='-ljemalloc'
- make -j 4 && make install
删除原始配置文件,使用自己的配置文件
- rm -f /usr/local/nginx/conf/nginx.conf
- vi /usr/local/nginx/conf/nginx.conf
输入内容
- user www www;
- worker_processes auto;
- worker_cpu_affinity auto;
- dso{
- load ngx_http_concat_module.so;
- }
- error_log /usr/local/nginx/logs/nginx_error.log crit;
- pid /usr/local/nginx/nginx.pid;
- worker_rlimit_nofile 51200;
- events {
- use epoll;
- worker_connections 51200;
- }
- http {
- include mime.types;
- default_type application/octet-stream;
- server_names_hash_bucket_size 128;
- client_header_buffer_size 32k;
- large_client_header_buffers 4 32k;
- client_max_body_size 50m;
- sendfile on;
- tcp_nopush on;
- keepalive_timeout 60;
- tcp_nodelay on;
- fastcgi_connect_timeout 300;
- fastcgi_send_timeout 300;
- fastcgi_read_timeout 300;
- fastcgi_buffer_size 64k;
- fastcgi_buffers 4 64k;
- fastcgi_busy_buffers_size 128k;
- fastcgi_temp_file_write_size 256k;
- gzip on;
- gzip_min_length 1k;
- gzip_buffers 4 16k;
- gzip_http_version 1.0;
- gzip_comp_level 2;
- gzip_types text/plain application/x-javascript text/css application/xml image/jpeg image/png image/gif;
- gzip_vary on;
- gzip_proxied expired no-cache no-store private auth;
- gzip_disable "MSIE [1-6].";
- #limit_zone crawler $binary_remote_addr 10m;
- #log format
- log_format access '$remote_addr - $remote_user [$time_local] "$request" '
- '$status $body_bytes_sent "$http_referer" '
- '"$http_user_agent" $http_x_forwarded_for';
- include vhosts/*.conf;
- }
- vi /usr/local/nginx/conf/proxy.conf
内容如下
- proxy_connect_timeout 300s;
- proxy_send_timeout 900;
- proxy_read_timeout 900;
- proxy_buffer_size 32k;
- proxy_buffers 4 32k;
- proxy_busy_buffers_size 64k;
- proxy_redirect off;
- proxy_hide_header Vary;
- proxy_set_header Accept-Encoding '';
- proxy_set_header Host $host;
- proxy_set_header Referer $http_referer;
- proxy_set_header Cookie $http_cookie;
- proxy_set_header X-Real-IP $remote_addr;
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
创建默认站点
- mkdir -p /home/wwwroot/default /home/wwwlogs/nginx /usr/local/nginx/conf/vhosts
- vi /usr/local/nginx/conf/vhosts/default.conf
内容如下
- log_format default '$remote_addr - $remote_user [$time_local] "$request" '
- '$status $body_bytes_sent "$http_referer" '
- '"$http_user_agent" $http_x_forwarded_for';
- server {
- listen 80;
- server_name shuang.ca;
- index index.html index.htm index.php;
- root /home/wwwroot/default;
- error_log /home/wwwlogs/nginx/default_error.log;
- access_log /home/wwwlogs/nginx/default_access.log;
- location / {
- try_files $uri @litespeed;
- }
- location @litespeed {
- internal;
- proxy_pass http://127.0.0.1:8088;
- include proxy.conf;
- }
- location ~ .*.(php|php5)?$ {
- proxy_pass http://127.0.0.1:8088;
- include proxy.conf;
- }
- location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$ {
- expires 30d;
- }
- location ~ .*.(js|css)?$ {
- expires 12h;
- }
- }
5.3.添加服务并启动
- ln -s /lib/libpcre.so.0.0.1 /lib/libpcre.so.1 #若启动失败请执行命令
- vi /etc/init.d/nginx
内容如下
- #!/bin/sh
- #
- # nginx - this script starts and stops the nginx daemon
- #
- # chkconfig: - 85 15
- # description: Nginx is an HTTP(S) server, HTTP(S) reverse
- # proxy and IMAP/POP3 proxy server
- # processname: nginx
- # config: /etc/nginx/nginx.conf
- # config: /etc/sysconfig/nginx
- # pidfile: /var/run/nginx.pid
- # Source function library.
- . /etc/rc.d/init.d/functions
- # Source networking configuration.
- . /etc/sysconfig/network
- # Check that networking is up.
- [ "$NETWORKING" = "no" ] && exit 0
- nginx="/usr/local/nginx/sbin/nginx"
- prog=$(basename $nginx)
- NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
- [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
- lockfile=/var/lock/subsys/nginx
- make_dirs() {
- # make required directories
- user=`$nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=([^ ]*).*/1/g' -`
- if [ -z "`grep $user /etc/passwd`" ]; then
- useradd -M -s /bin/nologin $user
- fi
- options=`$nginx -V 2>&1 | grep 'configure arguments:'`
- for opt in $options; do
- if [ `echo $opt | grep '.*-temp-path'` ]; then
- value=`echo $opt | cut -d "=" -f 2`
- if [ ! -d "$value" ]; then
- # echo "creating" $value
- mkdir -p $value && chown -R $user $value
- fi
- fi
- done
- }
- start() {
- [ -x $nginx ] || exit 5
- [ -f $NGINX_CONF_FILE ] || exit 6
- make_dirs
- echo -n $"Starting $prog: "
- daemon $nginx -c $NGINX_CONF_FILE
- retval=$?
- echo
- [ $retval -eq 0 ] && touch $lockfile
- return $retval
- }
- stop() {
- echo -n $"Stopping $prog: "
- killproc $prog -QUIT
- retval=$?
- echo
- [ $retval -eq 0 ] && rm -f $lockfile
- return $retval
- }
- restart() {
- configtest || return $?
- stop
- sleep 1
- start
- }
- reload() {
- configtest || return $?
- echo -n $"Reloading $prog: "
- killproc $nginx -HUP
- RETVAL=$?
- echo
- }
- force_reload() {
- restart
- }
- configtest() {
- $nginx -t -c $NGINX_CONF_FILE
- }
- rh_status() {
- status $prog
- }
- rh_status_q() {
- rh_status >/dev/null 2>&1
- }
- case "$1" in
- start)
- rh_status_q && exit 0
- $1
- ;;
- stop)
- rh_status_q || exit 0
- $1
- ;;
- restart|configtest)
- $1
- ;;
- reload)
- rh_status_q || exit 7
- $1
- ;;
- force-reload)
- force_reload
- ;;
- status)
- rh_status
- ;;
- condrestart|try-restart)
- rh_status_q || exit 0
- ;;
- *)
- echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
- exit 2
- esac
设置执行权限并添加自启动
- chmod +x /etc/init.d/nginx
- chkconfig --add nginx
- chkconfig nginx on
- service nginx start
好了,现在访问http://ip/看看,是不是可以访问了?
6.安装PHP 5.2
重头戏来了,现在将安装两个版本的PHP,首先是PHP 5.2
6.1.安装libiconv
- wget -c http://soft.shuang.ca/libiconv/libiconv-1.14.tar.gz -O /home/llnmp/libiconv-1.14.tar.gz
- cd /home/llnmp
- tar zxf libiconv-1.14.tar.gz
- cd libiconv-1.14/
- ./configure
- make -j 4 && make install
- ln -sf /usr/local/lib/libiconv.so.2 /usr/lib/libiconv.so.2
4.2.下载并安装
下载PHP 5.2.17,下载php-litespeed,并解压拷贝到litespeed编辑目录
- wget -c http://soft.shuang.ca/php/php-5.2.17.tar.gz -O /home/llnmp/php-5.2.17.tar.gz
- wget -c http://soft.shuang.ca/php-litespeed/php-litespeed-6.6.tgz -O /home/llnmp/php-litespeed-6.6.tgz
- cd /home/llnmp
- tar zxf php-5.2.17.tar.gz
- tar zxf php-litespeed-6.6.tgz
- mv litespeed php-5.2.17/sapi/litespeed/
- mv php-5.2.17 /usr/local/lsws/phpbuild
- cd /usr/local/lsws/phpbuild/php-5.2.17
开始编译安装,这里注意将PHP 5.2.17的安装路径设置为/usr/local/lsws/lsphp52
- touch ac*
- rm -rf autom4te.*
- export PHP_AUTOCONF=/usr/bin/autoconf-2.13
- ./buildconf --force
- ./configure '--disable-fileinfo' '--prefix=/usr/local/lsws/lsphp52' '--with-pdo-mysql=/usr/local/mysql/bin/mysql_config' '--with-mysql=/usr/local/mysql' '--with-mysqli=/usr/local/mysql/bin/mysql_config' '--with-zlib''--with-gd' '--enable-shmop' '--enable-exif' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-magic-quotes' '--enable-mbstring' '--with-iconv=/usr/local' '--with-curl' '--with-curlwrappers' '--with-mcrypt' '--with-mhash' '--with-openssl' '--with-freetype-dir=/usr/lib' '--with-jpeg-dir=/usr/lib' '--with-png-dir' '--with-libxml-dir=/usr' '--enable-xml' '--disable-rpath' '--enable-bcmath' '--enable-mbregex' '--enable-gd-native-ttf' '--enable-pcntl' '--with-ldap' '--with-ldap-sasl' '--with-xmlrpc' '--enable-zip' '--enable-inline-optimization' '--enable-soap' '--disable-ipv6' '--enable-ftp' '--disable-debug' '--with-gettext' '--with-litespeed'
- make ZEND_EXTRA_LIBS='-liconv' -j 4
- make install
对PHP 5.2.17进行配置
- cp /usr/local/lsws/phpbuild/php-5.2.17/php.ini-dist /usr/local/lsws/lsphp52/lib/php.ini
- cd /usr/local/lsws/fcgi-bin
- [ -e "lsphp-5.2.17" ] && mv lsphp-5.2.17 lsphp-5.2.17.bak
- cp /usr/local/lsws/phpbuild/php-5.2.17/sapi/litespeed/php lsphp-5.2.17
- ln -sf lsphp-5.2.17 lsphp52
- chmod a+rx lsphp-5.2.17
- chown -R lsadm:lsadm /usr/local/lsws/phpbuild/php-5.2.17
- sed -i 's/post_max_size = 8M/post_max_size = 50M/g' /usr/local/lsws/lsphp52/lib/php.ini
- sed -i 's/short_open_tag = Off/short_open_tag = On/g' /usr/local/lsws/lsphp52/lib/php.ini
- sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 50M/g' /usr/local/lsws/lsphp52/lib/php.ini
- sed -i 's/;date.timezone =/date.timezone = Asia/Shanghai/g' /usr/local/lsws/lsphp52/lib/php.ini
- sed -i 's/disable_functions =.*/disable_functions = passthru,exec,system,chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server/g' /usr/local/lsws/lsphp52/lib/php.ini
- sed -i 's/display_errors = On/display_errors = Off/g' /usr/local/lsws/lsphp52/lib/php.ini
- sed -i 's/expose_php = On/expose_php = Off/g' /usr/local/lsws/lsphp52/lib/php.ini
7.安装PHP 5.4
4.2.下载并安装
这里同样注意,将PHP 5.4.26的安装路径设置为/usr/local/lsws/lsphp54
- wget -c http://soft.shuang.ca/php/php-5.4.26.tar.gz -O /home/llnmp/php-5.4.26.tar.gz
- cd /home/llnmp
- tar zxf php-5.4.26.tar.gz
- mv php-5.4.26 /usr/local/lsws/phpbuild
- cd /usr/local/lsws/phpbuild/php-5.4.26
- touch ac*
- rm -rf autom4te.*
- ./configure '--disable-fileinfo' '--prefix=/usr/local/lsws/lsphp54' '--with-pdo-mysql=/usr/local/mysql/bin/mysql_config' '--with-mysql=/usr/local/mysql' '--with-mysqli=/usr/local/mysql/bin/mysql_config' '--with-zlib''--with-gd' '--enable-shmop' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-magic-quotes' '--enable-mbstring' '--with-iconv-dir=/usr/local' '--enable-inline-optimization' '--with-curl' '--with-curlwrappers' '--with-mcrypt' '--with-mhash' '--with-openssl' '--with-freetype-dir=/usr/lib' '--with-jpeg-dir=/usr/lib' '--with-png-dir' '--with-libxml-dir=/usr' '--enable-xml' '--disable-rpath' '--enable-bcmath' '--enable-mbregex' '--enable-gd-native-ttf' '--enable-pcntl' '--with-ldap' '--with-ldap-sasl' '--with-xmlrpc' '--enable-zip' '--enable-soap' '--enable-ftp' '--disable-debug' '--with-gettext' '--with-litespeed'
- make ZEND_EXTRA_LIBS='-liconv' -j 4
- make -k install
对PHP 5.4.26进行配置
- cp /usr/local/lsws/phpbuild/php-5.4.26/php.ini-production /usr/local/lsws/lsphp54/lib/php.ini
- cd /usr/local/lsws/fcgi-bin
- [ -e "lsphp-5.4.26" ] && mv lsphp-5.4.25 lsphp-5.4.26.bak
- cp /usr/local/lsws/phpbuild/php-5.4.26/sapi/litespeed/php lsphp-5.4.26
- ln -sf lsphp-5.4.26 lsphp54
- chmod a+rx lsphp-5.4.26
- chown -R lsadm:lsadm /usr/local/lsws/phpbuild/php-5.4.26
- sed -i 's/post_max_size = 8M/post_max_size = 50M/g' /usr/local/lsws/lsphp54/lib/php.ini
- sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 50M/g' /usr/local/lsws/lsphp54/lib/php.ini
- sed -i 's/short_open_tag = Off/short_open_tag = On/g' /usr/local/lsws/lsphp54/lib/php.ini
- sed -i 's/;date.timezone =/date.timezone = Asia/Shanghai/g' /usr/local/lsws/lsphp54/lib/php.ini
- sed -i 's/disable_functions =.*/disable_functions = passthru,exec,system,chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server/g' /usr/local/lsws/lsphp54/lib/php.ini
- sed -i 's/display_errors = On/display_errors = Off/g' /usr/local/lsws/lsphp54/lib/php.ini
- sed -i 's/expose_php = On/expose_php = Off/g' /usr/local/lsws/lsphp54/lib/php.ini
8.安装Memcached
为PHP 5.4.26添加Memcached缓存插件,PHP 5.2.17不添加
- useradd -M -s /sbin/nologin memcached
- wget http://soft.shuang.ca/memcached/memcached-1.4.17.tar.gz -O /home/llnmp/memcached-1.4.17.tar.gz
- wget http://soft.shuang.ca/memcache/memcache-2.2.7.tgz -O /home/llnmp/memcache-2.2.7.tgz
- wget http://soft.shuang.ca/libmemcached/libmemcached-1.0.18.tar.gz -O /home/llnmp/libmemcached-1.0.18.tar.gz
- wget http://soft.shuang.ca/memcached/lib/memcached-2.1.0.tgz -O /home/llnmp/memcached-2.1.0.tgz
- cd /home/llnmp
- tar zxvf memcached-1.4.17.tar.gz
- cd memcached-1.4.17
- ./configure --prefix=/usr/local/memcached
- make -j 4 && make install
- ln -s /usr/local/memcached/bin/memcached /usr/bin/memcached
配置memcached自启动
- vi /etc/init.d/memcached
内容如下
- #!/bin/bash
- # v.0.0.1
- # create by snowolf at 2012.5.25
- #
- # memcached - This shell script takes care of starting and stopping memcached.
- #
- # chkconfig: - 90 10
- # description: Memcache provides fast memory based storage.
- # processname: memcached
- memcached_path="/usr/local/memcached/bin/memcached"
- memcached_pid="/var/run/memcached.pid"
- memcached_memory="1024"
- # Source function library.
- . /etc/rc.d/init.d/functions
- [ -x $memcached_path ] || exit 0
- RETVAL=0
- prog="memcached"
- # Start daemons.
- start() {
- if [ -e $memcached_pid -a ! -z $memcached_pid ];then
- echo $prog" already running...."
- exit 1
- fi
- echo -n $"Starting $prog "
- # Single instance for all caches
- $memcached_path -m $memcached_memory -l 0.0.0.0 -p 11211 -u memcached -d-P $memcached_pid
- RETVAL=$?
- [ $RETVAL -eq 0 ] && {
- touch /var/lock/subsys/$prog
- success $"$prog"
- }
- echo
- return $RETVAL
- }
- # Stop daemons.
- stop() {
- echo -n $"Stopping $prog "
- killproc -d 10 $memcached_path
- echo
- [ $RETVAL = 0 ] && rm -f $memcached_pid /var/lock/subsys/$prog
- RETVAL=$?
- return $RETVAL
- }
- # See how we were called.
- case "$1" in
- start)
- start
- ;;
- stop)
- stop
- ;;
- status)
- status $prog
- RETVAL=$?
- ;;
- restart)
- stop
- start
- ;;
- *)
- echo $"Usage: $0 {start|stop|status|restart}"
- exit 1
- esac
- exit $RETVAL
- chmod +x /etc/init.d/memcached
- chkconfig --add memcached
- chkconfig memcached on
- service memcached start
安装PHP插件
- cd /home/llnmp
- tar zxvf memcache-2.2.7.tgz
- cd memcache-2.2.7
- /usr/local/lsws/lsphp54/bin/phpize
- ./configure --with-php-config=/usr/local/lsws/lsphp54/bin/php-config
- make -j 4 && make install
- cd /home/llnmp
- tar zxvf libmemcached-1.0.18.tar.gz
- cd libmemcached-1.0.18
- ./configure --with-memcached=/usr/local/memcached
- make -j 4 && make install
- cd /home/llnmp
- tar zxvf memcached-2.1.0.tgz
- cd memcached-2.1.0
- /usr/local/lsws/lsphp54/bin/phpize
- ./configure --with-php-config=/usr/local/lsws/lsphp54/bin/php-config
- make -j 4 && make install
配置PHP使其生效
- vi /usr/local/lsws/lsphp54/lib/php.ini
修改内容如下
- extension_dir = "./" 修改为 extension_dir = "/usr/local/lsws/lsphp54/lib/php/extensions/no-debug-non-zts-20100525/"
- 在下面添加
- extension = "memcache.so"
- extension = "memcached.so"
9.安装Zend Optimizer
因为jieqi需要zend支持,所以给PHP 5.2配置上Zend Optimizer 3.3.9
- wget -c http://soft.shuang.ca/zend/ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz -O /home/llnmp/ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz
- cd /home/llnmp
- tar zxf ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz
- mkdir -p /usr/local/lsws/lsphp52/lib/php/Zend
- cp ZendOptimizer-3.3.9-linux-glibc23-i386/data/5_2_x_comp/ZendOptimizer.so /usr/local/lsws/lsphp52/lib/php/Zend/
- cat >>/usr/local/lsws/lsphp52/lib/php.ini < <EOF
- [Zend Optimizer]
- zend_optimizer.optimization_level=1
- zend_extension="/usr/local/lsws/lsphp52/lib/php/Zend/ZendOptimizer.so"
- EOF
10.创建测试文件
安装已经完成,但是现在还不能使用,因为还没有配置,在后一篇会对配置进行说明,在这之前咱们先做最后的收尾步骤,创建两个测试文件!
- mkdir -p /home/wwwlogs/litespeed #创建litespeed日志目录
- mkdir -p /home/wwwroot/php52
- mkdir -p /home/wwwroot/php53
- cat >/home/wwwroot/php52/index.php < <EOF
- <!--?php phpinfo(); ?-->
- EOF
- cat >/home/wwwroot/php53/index.php < <EOF
- <!--?php phpinfo(); ?-->
- EOF
- chown -R www.www /home/wwwroot
该装的都装上去了,现在需要做的就是将PHP 5.2与PHP 5.4通过OpenLiteSpeed控制面板整合在一起。
首先登陆OpenLiteSpeed控制面板:http://ip:7080/,输入之前安装时设置的账号密码登陆进去
点击”Configuration”按钮,在其中找到”External App”选项卡,
点击右侧的”Add”连接新建一个,类型选择”LSAPI App”
设置内容如下,未提到的默认即可:
- Name: lsphp52
- Address: uds://tmp/lshttpd/lsphp52.sock
- Max Connections: 35
- Environment: PHP_LSAPI_MAX_REQUESTS=10000
- PHP_LSAPI_CHILDREN=35
- Initial Request Timeout (secs): 60
- Retry Timeout (secs): 0
- Persistent Connection: Yes
- Command: /usr/local/lsws/lsphp52/bin/lsphp
- Back Log: 100
- Instances: 1
- Priority: 0
- Memory Soft Limit (bytes): 2047M
- Memory Hard Limit (bytes): 2047M
- Process Soft Limit: 400
- Process Hard Limit: 500
配置完成后点击”Save”保存,然后就会多出来一个”lsphp52″
用同样的方法配置php 5.4,内容如下:
- Name: lsphp54
- Address: uds://tmp/lshttpd/lsphp54.sock
- Max Connections: 35
- Environment: PHP_LSAPI_MAX_REQUESTS=10000
- PHP_LSAPI_CHILDREN=35
- Initial Request Timeout (secs): 60
- Retry Timeout (secs): 0
- Persistent Connection: Yes
- Command: /usr/local/lsws/lsphp54/bin/lsphp
- Back Log: 100
- Instances: 1
- Priority: 0
- Memory Soft Limit (bytes): 2047M
- Memory Hard Limit (bytes): 2047M
- Process Soft Limit: 400
- Process Hard Limit: 500
最终如下:
最后咱们添加两个网站,”Configuration”下的”Virtual Hosts”选项卡,点击”Add”新建网站,内容如下:
- Virtual Host Name: php52 #网站标识
- Virtual Host Root: /home/wwwroot/php52 #网站路径,必须真实存在
- Config File: $SERVER_ROOT/conf/php52.xml #配置文件路径
- Enable Scripts/ExtApps: Yes
- Restrained: Yes
- ExtApp Set UID Mode: DocRoot UID
保存后会自动回到网站列表界面,点击刚才创建的网站进去进行修改
选择”General”选项卡,修改内容如下:
- Document Root: $VH_ROOT/ #网站路径
- Enable GZIP Compression: Yes #启用Gzip压缩
“Script Handler”选项卡添加脚本执行
- Suffixes: php #脚本后缀,必要加 "."
- Handler Type: LiteSpeed SAPI
- Handler Name: lsphp52 #根据需要自己选择
现在网站已经创建好了,但是还没有配置域名对吧?所以呢,现在咱们再为这两个网站配置下域名,”Configuration”下的”Listeners”,点击”Default”也就是默认绑定端口8088,在下方点击”Add”
- Virtual Host: php52 #选择自己的网站
- Domains: aa.com #要配置的域名,多个域名用英文逗号分隔
OK,到这一步,就算是配置完成了,最后咱们重启一下吧,”Actions” –> “Graceful Restart”,然后使用配置的域名去访问了看看吧!