记录我的一些生活写照、无聊的牢骚、内心世界的活动 注册 | 登陆

CentOS下OpenLiteSpeed+Tengine安装及多PHP版本共存教程

CentOS下OpenLiteSpeed+Tengine安装及多PHP版本共存教程

使用自己最熟悉的CentOS系统,我使用的是CentOS 6 x32,最小化安装,然后做适度优化,接下来开始安装吧!

咱们先查看下CPU是几核的,方便之后编译时充分利用CPU资源(注意,在之后所有安装中,make -j 4 均为此例,请各位根据自己的CPU核心数进行相应修改)

  1. cat /proc/cpuinfo | grep processor | wc -l

这里可以看到我的CPU是4核的

1.VPS优化

首先对系统做适当精简,节省VPS资源,这里请各位根据自己的实际情况来进行精简,不要直接复制粘贴,避免运行出错

1.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
  2. 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

  1. sed -i 's/^SELINUX=.*$/SELINUX=disabled/' /etc/selinux/config

1.3.配置yum

为了避免yum时无法找到相应的版本,修改下yum

  1. sed -i 's:exclude=.*:exclude=:g' /etc/yum.conf

1.4.关闭不需要的服务

使用 chkconfig xxx off 和 chkconfig –del xxx 对系统服务进行精简,请各位根据实际情况进行精简,我保留的服务

2.安装前准备

2.1.删除自带Web程序

  1. yum remove httpd* php* mysql-server mysql* php-mysql -y

2.2.安装Epel

因为OpenLiteSpeed编译安装需要使用到geoip,而直接yum可能会找不到,所以咱们需要用到epel

  1. rpm -ivh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm

2.3.安装依赖库

  1. 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.更新系统

  1. yum -y update
  2. yum clean all

2.5.创建源码存放目录

为了方便安装,我在/home/下创建llnmp目录,将所有需要安装的源码包下载并存放到此目录中

  1. mkdir -p /home/llnmp
  2. cd /home/llnmp

3.开始安装

3.1.安装Jemalloc

Jemalloc是一款内存优化组件,可以用它来对数据库等程序进行优化

  1. wget -c http://soft.shuang.ca/jemalloc/jemalloc-3.5.1.tar.bz2 -O /home/llnmp/jemalloc-3.5.1.tar.bz2
  2. tar jxf jemalloc-3.5.1.tar.bz2
  3. cd jemalloc-3.5.1
  4. ./configure && make -j 4 && make install
  5. echo '/usr/local/lib' > /etc/ld.so.conf.d/local.conf
  6. ldconfig
  7. cd /home/llnmp

3.2.安装MariaDB数据库

MariaDB数据库是MySQL作者由于开源问题重新开发的数据库,与MySQL通用,至于说谁好谁坏,其实都差不多,不过基于对开源的支持,咱们可以选择MariaDB进行安装使用

3.2.1.添加用户、创建目录
  1. useradd -M -s /sbin/nologin mysql
  2. rm -f /etc/my.cnf
  3. mkdir -p /data/mysql
3.2.2.下载安装

由于之前安装了Jemalloc,所以在编译时添加一个参数-DCMAKE_EXE_LINKER_FLAGS=’-ljemalloc’

  1. wget -c http://soft.shuang.ca/mariadb/mariadb-5.5.36.tar.gz -O /home/llnmp/mariadb-5.5.36.tar.gz
  2. tar zxf mariadb-5.5.36.tar.gz
  3. cd mariadb-5.5.36
  4. 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'
  5. make -j 4 && make install
  6.  
  7. cp support-files/mysql.server /etc/init.d/mysqld
  8. chmod +x /etc/init.d/mysqld
  9. chkconfig --add mysqld
  10. chkconfig mysqld on
3.2.3.配置并优化

编辑创建配置文件/etc/my.cnf,内容如下

  1. [client]
  2. port = 3306
  3. socket = /tmp/mysql.sock
  4.  
  5. [mysqld]
  6. port = 3306
  7. socket = /tmp/mysql.sock
  8.  
  9. basedir = /usr/local/mysql
  10. datadir = /data/mysql
  11. pid-file = /data/mysql/mysql.pid
  12. user = mysql
  13. bind-address = 127.0.0.1 #无需外部访问数据库,所以直接指定仅本机访问
  14. server-id = 1
  15.  
  16. skip-name-resolve
  17. #skip-networking
  18. back_log = 600
  19.  
  20. max_connections = 1000
  21. max_connect_errors = 6000
  22. open_files_limit = 65535
  23. table_open_cache = 128
  24. max_allowed_packet = 4M
  25. binlog_cache_size = 1M
  26. max_heap_table_size = 8M
  27. tmp_table_size = 16M
  28.  
  29. read_buffer_size = 2M
  30. read_rnd_buffer_size = 8M
  31. sort_buffer_size = 8M
  32. join_buffer_size = 8M
  33. key_buffer_size = 4M
  34.  
  35. thread_cache_size = 8
  36.  
  37. query_cache_size = 8M
  38. query_cache_limit = 2M
  39.  
  40. ft_min_word_len = 4
  41.  
  42. log_bin = mysql-bin
  43. binlog_format = mixed
  44. expire_logs_days = 30
  45.  
  46. log_error = /data/mysql/mysql-error.log
  47. slow_query_log = 1
  48. long_query_time = 1
  49. slow_query_log_file = /data/mysql/mysql-slow.log
  50.  
  51. performance_schema = 0
  52.  
  53. #lower_case_table_names = 1
  54.  
  55. skip-external-locking
  56.  
  57. default_storage_engine = InnoDB
  58. #default-storage-engine = MyISAM
  59. innodb_file_per_table = 1
  60. innodb_open_files = 500
  61. innodb_buffer_pool_size = 64M
  62. innodb_write_io_threads = 4
  63. innodb_read_io_threads = 4
  64. innodb_thread_concurrency = 0
  65. innodb_purge_threads = 1
  66. innodb_flush_log_at_trx_commit = 2
  67. innodb_log_buffer_size = 2M
  68. innodb_log_file_size = 32M
  69. innodb_log_files_in_group = 3
  70. innodb_max_dirty_pages_pct = 90
  71. innodb_lock_wait_timeout = 120
  72.  
  73. bulk_insert_buffer_size = 8M
  74. myisam_sort_buffer_size = 8M
  75. myisam_max_sort_file_size = 10G
  76. myisam_repair_threads = 1
  77.  
  78. interactive_timeout = 28800
  79. wait_timeout = 28800
  80.  
  81. [mysqldump]
  82. quick
  83. max_allowed_packet = 16M
  84.  
  85. [myisamchk]
  86. key_buffer_size = 8M
  87. sort_buffer_size = 8M
  88. read_buffer = 4M
  89. write_buffer = 4M

根据内存大小自动进行优化

  1. Memtatol=`free -m | grep 'Mem:' | awk '{print $2}'`
  2. if [ $Memtatol -gt 1500 -a $Memtatol -le 2500 ]; then
  3. sed -i 's/table_open_cache = 128/table_open_cache = 256/g' /etc/my.cnf
  4. sed -i 's/tmp_table_size = 16M/tmp_table_size = 32M/g' /etc/my.cnf
  5. sed -i 's/thread_cache_size = 8/thread_cache_size = 16/g' /etc/my.cnf
  6. sed -i 's/query_cache_size = 8M/query_cache_size = 16M/g' /etc/my.cnf
  7. sed -i 's/innodb_buffer_pool_size = 64M/innodb_buffer_pool_size = 128M/g' /etc/my.cnf
  8. sed -i 's/myisam_sort_buffer_size = 8M/myisam_sort_buffer_size = 16M/g' /etc/my.cnf
  9. sed -i 's/key_buffer_size = 8M/key_buffer_size = 16M/g' /etc/my.cnf
  10. elif [ $Memtatol -gt 2500 -a $Memtatol -le 3500 ]; then
  11. sed -i 's/table_open_cache = 128/table_open_cache = 512/g' /etc/my.cnf
  12. sed -i 's/tmp_table_size = 16M/tmp_table_size = 64M/g' /etc/my.cnf
  13. sed -i 's/thread_cache_size = 8/thread_cache_size = 32/g' /etc/my.cnf
  14. sed -i 's/query_cache_size = 8M/query_cache_size = 32M/g' /etc/my.cnf
  15. sed -i 's/innodb_buffer_pool_size = 64M/innodb_buffer_pool_size = 512M/g' /etc/my.cnf
  16. sed -i 's/myisam_sort_buffer_size = 8M/myisam_sort_buffer_size = 32M/g' /etc/my.cnf
  17. sed -i 's/key_buffer_size = 8M/key_buffer_size = 64M/g' /etc/my.cnf
  18. elif [ $Memtatol -gt 3500 ];then
  19. sed -i 's/table_open_cache = 128/table_open_cache = 1024/g' /etc/my.cnf
  20. sed -i 's/tmp_table_size = 16M/tmp_table_size = 128M/g' /etc/my.cnf
  21. sed -i 's/thread_cache_size = 8/thread_cache_size = 64/g' /etc/my.cnf
  22. sed -i 's/query_cache_size = 8M/query_cache_size = 64M/g' /etc/my.cnf
  23. sed -i 's/innodb_buffer_pool_size = 64M/innodb_buffer_pool_size = 1024M/g' /etc/my.cnf
  24. sed -i 's/myisam_sort_buffer_size = 8M/myisam_sort_buffer_size = 64M/g' /etc/my.cnf
  25. sed -i 's/key_buffer_size = 8M/key_buffer_size = 256M/g' /etc/my.cnf
  26. fi
  1. /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
  2. chown mysql.mysql -R /data/mysql
  3. chgrp -R mysql /usr/local/mysql/.
  4.  
  5. ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
  6. ln -s /usr/local/mysql/include/mysql /usr/include/mysql
  7. ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
  8. ln -s /usr/local/mysql/bin/mysqldump /usr/bin/mysqldump
  9. ln -s /usr/local/mysql/bin/myisamchk /usr/bin/myisamchk
  10. ln -s /usr/local/mysql/bin/mysqld_safe /usr/bin/mysqld_safe

启动数据库并设置root密码

  1. ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib #若启动失败,请执行这条命令
  2. service mysqld start
  3. /usr/local/mysql/bin/mysqladmin -u root password shuang.ca
  4.  
  5. cat >>/tmp/mysql_sec_script< <EOF
  6. use mysql;
  7. update user set password=password('shuang.ca') where user='root';
  8. delete from user where not (user='root') ;
  9. delete from user where user='root' and password='';
  10. drop database test;
  11. DROP USER ''@'%';
  12. flush privileges;
  13. EOF
  14.  
  15. /usr/local/mysql/bin/mysql -u root -pshuang.ca -h localhost < /tmp/mysql_sec_script
  16. rm -f /tmp/mysql_sec_script
  17.  
  18. service mysqld restart

4.安装OpenLitespeed

OpenLitespeed其实可以使用yum进行安装,不过为了方便配置,我使用源码进行安装

4.1.创建用户

  1. useradd -M -s /sbin/nologin www

4.2.下载并安装

  1. wget -c http://soft.shuang.ca/openlitespeed/openlitespeed-1.2.9.tgz -O /home/llnmp/openlitespeed-1.2.9.tgz
  2. cd /home/llnmp
  3. tar zxf openlitespeed-1.2.9.tgz
  4. cd openlitespeed-1.2.9
  5. ./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为管理员邮箱,请自行修改
  6. make -j 4 && make install

4.3.启动并测试

  1. service lsws restart

打开浏览器,输入:http://ip:8088访问看下是否能够打开了?

由于我使用Tengine作为前端,所以这里就不修改openlitespeed的端口了,若不使用前端,则可以登录openlitespeed管理后台进行修改

5.安装Tengine

这里使用Tengine作为前端,因为Tengine作为淘宝开发改进的Nginx增强版,完全支持Nginx配置,且对于大并发有较强的处理性能

5.1.下载并配置

  1. wget -c http://soft.shuang.ca/tengine/tengine-2.0.2.tar.gz -O /home/llnmp/tengine-2.0.2.tar.gz
  2. cd /home/llnmp
  3. tar zxf tengine-2.0.2.tar.gz
  4. cd tengine-2.0.2

Tengine默认会安装debug,但是对于我们来说是完全没有必要的,安装了反而增加了几M的空间占用,所以我们可以去掉

  1. sed -i 's@CFLAGS="$CFLAGS -g"@#CFLAGS="$CFLAGS -g"@' auto/cc/gcc

同时,我们还可以根据自己的需求隐藏Tengine版本号,甚至修改为自己的定制信息,vi src/core/nginx.h,修改为如下内容

  1. #ifndef _NGINX_H_INCLUDED_
  2. #define _NGINX_H_INCLUDED_
  3.  
  4. #define nginx_version 1004006
  5. #define NGINX_VERSION "1.0"
  6. #define NGINX_VER "Shuang.Ca/"
  7.  
  8. #define TENGINE "Shuang.Ca"
  9. #define tengine_version 2000002
  10. #define TENGINE_VERSION "1.0"
  11. #define TENGINE_VER TENGINE "/" TENGINE_VERSION
  12.  
  13. #define NGINX_VAR "Shuang.Ca"
  14. #define NGX_OLDPID_EXT ".oldbin"

5.2.安装并配置

同样的,我们之前安装了Jemalloc,现在也一样要添加一个参数–with-ld-opt=’-ljemalloc’

  1. ./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'
  2. make -j 4 && make install

删除原始配置文件,使用自己的配置文件

  1. rm -f /usr/local/nginx/conf/nginx.conf
  2. vi /usr/local/nginx/conf/nginx.conf

输入内容

  1. user www www;
  2. worker_processes auto;
  3. worker_cpu_affinity auto;
  4. dso{
  5. load ngx_http_concat_module.so;
  6. }
  7. error_log /usr/local/nginx/logs/nginx_error.log crit;
  8. pid /usr/local/nginx/nginx.pid;
  9.  
  10. worker_rlimit_nofile 51200;
  11.  
  12. events {
  13. use epoll;
  14. worker_connections 51200;
  15. }
  16.  
  17. http {
  18. include mime.types;
  19. default_type application/octet-stream;
  20.  
  21. server_names_hash_bucket_size 128;
  22. client_header_buffer_size 32k;
  23. large_client_header_buffers 4 32k;
  24. client_max_body_size 50m;
  25.  
  26. sendfile on;
  27. tcp_nopush on;
  28.  
  29. keepalive_timeout 60;
  30.  
  31. tcp_nodelay on;
  32.  
  33. fastcgi_connect_timeout 300;
  34. fastcgi_send_timeout 300;
  35. fastcgi_read_timeout 300;
  36. fastcgi_buffer_size 64k;
  37. fastcgi_buffers 4 64k;
  38. fastcgi_busy_buffers_size 128k;
  39. fastcgi_temp_file_write_size 256k;
  40.  
  41. gzip on;
  42. gzip_min_length 1k;
  43. gzip_buffers 4 16k;
  44. gzip_http_version 1.0;
  45. gzip_comp_level 2;
  46. gzip_types text/plain application/x-javascript text/css application/xml image/jpeg image/png image/gif;
  47. gzip_vary on;
  48. gzip_proxied expired no-cache no-store private auth;
  49. gzip_disable "MSIE [1-6].";
  50.  
  51. #limit_zone crawler $binary_remote_addr 10m;
  52.  
  53. #log format
  54. log_format access '$remote_addr - $remote_user [$time_local] "$request" '
  55. '$status $body_bytes_sent "$http_referer" '
  56. '"$http_user_agent" $http_x_forwarded_for';
  57.  
  58. include vhosts/*.conf;
  59. }
  1. vi /usr/local/nginx/conf/proxy.conf

内容如下

  1. proxy_connect_timeout 300s;
  2. proxy_send_timeout 900;
  3. proxy_read_timeout 900;
  4. proxy_buffer_size 32k;
  5. proxy_buffers 4 32k;
  6. proxy_busy_buffers_size 64k;
  7. proxy_redirect off;
  8. proxy_hide_header Vary;
  9. proxy_set_header Accept-Encoding '';
  10. proxy_set_header Host $host;
  11. proxy_set_header Referer $http_referer;
  12. proxy_set_header Cookie $http_cookie;
  13. proxy_set_header X-Real-IP $remote_addr;
  14. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

创建默认站点

  1. mkdir -p /home/wwwroot/default /home/wwwlogs/nginx /usr/local/nginx/conf/vhosts
  2. vi /usr/local/nginx/conf/vhosts/default.conf

内容如下

  1. log_format default '$remote_addr - $remote_user [$time_local] "$request" '
  2. '$status $body_bytes_sent "$http_referer" '
  3. '"$http_user_agent" $http_x_forwarded_for';
  4. server {
  5. listen 80;
  6. server_name shuang.ca;
  7. index index.html index.htm index.php;
  8. root /home/wwwroot/default;
  9.  
  10. error_log /home/wwwlogs/nginx/default_error.log;
  11. access_log /home/wwwlogs/nginx/default_access.log;
  12.  
  13. location / {
  14. try_files $uri @litespeed;
  15. }
  16.  
  17. location @litespeed {
  18. internal;
  19. proxy_pass http://127.0.0.1:8088;
  20. include proxy.conf;
  21. }
  22.  
  23. location ~ .*.(php|php5)?$ {
  24. proxy_pass http://127.0.0.1:8088;
  25. include proxy.conf;
  26. }
  27.  
  28. location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$ {
  29. expires 30d;
  30. }
  31.  
  32. location ~ .*.(js|css)?$ {
  33. expires 12h;
  34. }
  35. }

5.3.添加服务并启动

  1. ln -s /lib/libpcre.so.0.0.1 /lib/libpcre.so.1 #若启动失败请执行命令
  2. vi /etc/init.d/nginx

内容如下

  1. #!/bin/sh
  2. #
  3. # nginx - this script starts and stops the nginx daemon
  4. #
  5. # chkconfig: - 85 15
  6. # description: Nginx is an HTTP(S) server, HTTP(S) reverse
  7. # proxy and IMAP/POP3 proxy server
  8. # processname: nginx
  9. # config: /etc/nginx/nginx.conf
  10. # config: /etc/sysconfig/nginx
  11. # pidfile: /var/run/nginx.pid
  12.  
  13. # Source function library.
  14. . /etc/rc.d/init.d/functions
  15.  
  16. # Source networking configuration.
  17. . /etc/sysconfig/network
  18.  
  19. # Check that networking is up.
  20. [ "$NETWORKING" = "no" ] && exit 0
  21.  
  22. nginx="/usr/local/nginx/sbin/nginx"
  23. prog=$(basename $nginx)
  24.  
  25. NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
  26.  
  27. [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
  28.  
  29. lockfile=/var/lock/subsys/nginx
  30.  
  31. make_dirs() {
  32. # make required directories
  33. user=`$nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=([^ ]*).*/1/g' -`
  34. if [ -z "`grep $user /etc/passwd`" ]; then
  35. useradd -M -s /bin/nologin $user
  36. fi
  37. options=`$nginx -V 2>&1 | grep 'configure arguments:'`
  38. for opt in $options; do
  39. if [ `echo $opt | grep '.*-temp-path'` ]; then
  40. value=`echo $opt | cut -d "=" -f 2`
  41. if [ ! -d "$value" ]; then
  42. # echo "creating" $value
  43. mkdir -p $value && chown -R $user $value
  44. fi
  45. fi
  46. done
  47. }
  48.  
  49. start() {
  50. [ -x $nginx ] || exit 5
  51. [ -f $NGINX_CONF_FILE ] || exit 6
  52. make_dirs
  53. echo -n $"Starting $prog: "
  54. daemon $nginx -c $NGINX_CONF_FILE
  55. retval=$?
  56. echo
  57. [ $retval -eq 0 ] && touch $lockfile
  58. return $retval
  59. }
  60.  
  61. stop() {
  62. echo -n $"Stopping $prog: "
  63. killproc $prog -QUIT
  64. retval=$?
  65. echo
  66. [ $retval -eq 0 ] && rm -f $lockfile
  67. return $retval
  68. }
  69.  
  70. restart() {
  71. configtest || return $?
  72. stop
  73. sleep 1
  74. start
  75. }
  76.  
  77. reload() {
  78. configtest || return $?
  79. echo -n $"Reloading $prog: "
  80. killproc $nginx -HUP
  81. RETVAL=$?
  82. echo
  83. }
  84.  
  85. force_reload() {
  86. restart
  87. }
  88.  
  89. configtest() {
  90. $nginx -t -c $NGINX_CONF_FILE
  91. }
  92.  
  93. rh_status() {
  94. status $prog
  95. }
  96.  
  97. rh_status_q() {
  98. rh_status >/dev/null 2>&1
  99. }
  100.  
  101. case "$1" in
  102. start)
  103. rh_status_q && exit 0
  104. $1
  105. ;;
  106. stop)
  107. rh_status_q || exit 0
  108. $1
  109. ;;
  110. restart|configtest)
  111. $1
  112. ;;
  113. reload)
  114. rh_status_q || exit 7
  115. $1
  116. ;;
  117. force-reload)
  118. force_reload
  119. ;;
  120. status)
  121. rh_status
  122. ;;
  123. condrestart|try-restart)
  124. rh_status_q || exit 0
  125. ;;
  126. *)
  127. echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
  128. exit 2
  129. esac

设置执行权限并添加自启动

  1. chmod +x /etc/init.d/nginx
  2. chkconfig --add nginx
  3. chkconfig nginx on
  4. service nginx start

好了,现在访问http://ip/看看,是不是可以访问了?

6.安装PHP 5.2

重头戏来了,现在将安装两个版本的PHP,首先是PHP 5.2

6.1.安装libiconv

  1. wget -c http://soft.shuang.ca/libiconv/libiconv-1.14.tar.gz -O /home/llnmp/libiconv-1.14.tar.gz
  2. cd /home/llnmp
  3. tar zxf libiconv-1.14.tar.gz
  4. cd libiconv-1.14/
  5. ./configure
  6. make -j 4 && make install
  7. ln -sf /usr/local/lib/libiconv.so.2 /usr/lib/libiconv.so.2

4.2.下载并安装

下载PHP 5.2.17,下载php-litespeed,并解压拷贝到litespeed编辑目录

  1. wget -c http://soft.shuang.ca/php/php-5.2.17.tar.gz -O /home/llnmp/php-5.2.17.tar.gz
  2. wget -c http://soft.shuang.ca/php-litespeed/php-litespeed-6.6.tgz -O /home/llnmp/php-litespeed-6.6.tgz
  3. cd /home/llnmp
  4. tar zxf php-5.2.17.tar.gz
  5. tar zxf php-litespeed-6.6.tgz
  6. mv litespeed php-5.2.17/sapi/litespeed/
  7. mv php-5.2.17 /usr/local/lsws/phpbuild
  8. cd /usr/local/lsws/phpbuild/php-5.2.17

开始编译安装,这里注意将PHP 5.2.17的安装路径设置为/usr/local/lsws/lsphp52

  1. touch ac*
  2. rm -rf autom4te.*
  3. export PHP_AUTOCONF=/usr/bin/autoconf-2.13
  4. ./buildconf --force
  5. ./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'
  6. make ZEND_EXTRA_LIBS='-liconv' -j 4
  7. make install

对PHP 5.2.17进行配置

  1. cp /usr/local/lsws/phpbuild/php-5.2.17/php.ini-dist /usr/local/lsws/lsphp52/lib/php.ini
  2. cd /usr/local/lsws/fcgi-bin
  3. [ -e "lsphp-5.2.17" ] && mv lsphp-5.2.17 lsphp-5.2.17.bak
  4. cp /usr/local/lsws/phpbuild/php-5.2.17/sapi/litespeed/php lsphp-5.2.17
  5. ln -sf lsphp-5.2.17 lsphp52
  6. chmod a+rx lsphp-5.2.17
  7. chown -R lsadm:lsadm /usr/local/lsws/phpbuild/php-5.2.17
  8. sed -i 's/post_max_size = 8M/post_max_size = 50M/g' /usr/local/lsws/lsphp52/lib/php.ini
  9. sed -i 's/short_open_tag = Off/short_open_tag = On/g' /usr/local/lsws/lsphp52/lib/php.ini
  10. sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 50M/g' /usr/local/lsws/lsphp52/lib/php.ini
  11. sed -i 's/;date.timezone =/date.timezone = Asia/Shanghai/g' /usr/local/lsws/lsphp52/lib/php.ini
  12. 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
  13. sed -i 's/display_errors = On/display_errors = Off/g' /usr/local/lsws/lsphp52/lib/php.ini
  14. 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

  1. wget -c http://soft.shuang.ca/php/php-5.4.26.tar.gz -O /home/llnmp/php-5.4.26.tar.gz
  2. cd /home/llnmp
  3. tar zxf php-5.4.26.tar.gz
  4. mv php-5.4.26 /usr/local/lsws/phpbuild
  5. cd /usr/local/lsws/phpbuild/php-5.4.26
  6. touch ac*
  7. rm -rf autom4te.*
  8. ./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'
  9. make ZEND_EXTRA_LIBS='-liconv' -j 4
  10. make -k install

对PHP 5.4.26进行配置

  1. cp /usr/local/lsws/phpbuild/php-5.4.26/php.ini-production /usr/local/lsws/lsphp54/lib/php.ini
  2. cd /usr/local/lsws/fcgi-bin
  3. [ -e "lsphp-5.4.26" ] && mv lsphp-5.4.25 lsphp-5.4.26.bak
  4. cp /usr/local/lsws/phpbuild/php-5.4.26/sapi/litespeed/php lsphp-5.4.26
  5. ln -sf lsphp-5.4.26 lsphp54
  6. chmod a+rx lsphp-5.4.26
  7. chown -R lsadm:lsadm /usr/local/lsws/phpbuild/php-5.4.26
  8. sed -i 's/post_max_size = 8M/post_max_size = 50M/g' /usr/local/lsws/lsphp54/lib/php.ini
  9. sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 50M/g' /usr/local/lsws/lsphp54/lib/php.ini
  10. sed -i 's/short_open_tag = Off/short_open_tag = On/g' /usr/local/lsws/lsphp54/lib/php.ini
  11. sed -i 's/;date.timezone =/date.timezone = Asia/Shanghai/g' /usr/local/lsws/lsphp54/lib/php.ini
  12. 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
  13. sed -i 's/display_errors = On/display_errors = Off/g' /usr/local/lsws/lsphp54/lib/php.ini
  14. 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不添加

  1. useradd -M -s /sbin/nologin memcached
  2. wget http://soft.shuang.ca/memcached/memcached-1.4.17.tar.gz -O /home/llnmp/memcached-1.4.17.tar.gz
  3. wget http://soft.shuang.ca/memcache/memcache-2.2.7.tgz -O /home/llnmp/memcache-2.2.7.tgz
  4. wget http://soft.shuang.ca/libmemcached/libmemcached-1.0.18.tar.gz -O /home/llnmp/libmemcached-1.0.18.tar.gz
  5. wget http://soft.shuang.ca/memcached/lib/memcached-2.1.0.tgz -O /home/llnmp/memcached-2.1.0.tgz
  6. cd /home/llnmp
  7. tar zxvf memcached-1.4.17.tar.gz
  8. cd memcached-1.4.17
  9. ./configure --prefix=/usr/local/memcached
  10. make -j 4 && make install
  11. ln -s /usr/local/memcached/bin/memcached /usr/bin/memcached

配置memcached自启动

  1. vi /etc/init.d/memcached

内容如下

  1. #!/bin/bash
  2. # v.0.0.1
  3. # create by snowolf at 2012.5.25
  4. #
  5. # memcached - This shell script takes care of starting and stopping memcached.
  6. #
  7. # chkconfig: - 90 10
  8. # description: Memcache provides fast memory based storage.
  9. # processname: memcached
  10.  
  11. memcached_path="/usr/local/memcached/bin/memcached"
  12. memcached_pid="/var/run/memcached.pid"
  13. memcached_memory="1024"
  14.  
  15. # Source function library.
  16. . /etc/rc.d/init.d/functions
  17.  
  18. [ -x $memcached_path ] || exit 0
  19.  
  20. RETVAL=0
  21. prog="memcached"
  22.  
  23. # Start daemons.
  24. start() {
  25. if [ -e $memcached_pid -a ! -z $memcached_pid ];then
  26. echo $prog" already running...."
  27. exit 1
  28. fi
  29.  
  30. echo -n $"Starting $prog "
  31. # Single instance for all caches
  32. $memcached_path -m $memcached_memory -l 0.0.0.0 -p 11211 -u memcached -d-P $memcached_pid
  33. RETVAL=$?
  34. [ $RETVAL -eq 0 ] && {
  35. touch /var/lock/subsys/$prog
  36. success $"$prog"
  37. }
  38. echo
  39. return $RETVAL
  40. }
  41.  
  42. # Stop daemons.
  43. stop() {
  44. echo -n $"Stopping $prog "
  45. killproc -d 10 $memcached_path
  46. echo
  47. [ $RETVAL = 0 ] && rm -f $memcached_pid /var/lock/subsys/$prog
  48.  
  49. RETVAL=$?
  50. return $RETVAL
  51. }
  52.  
  53. # See how we were called.
  54. case "$1" in
  55. start)
  56. start
  57. ;;
  58. stop)
  59. stop
  60. ;;
  61. status)
  62. status $prog
  63. RETVAL=$?
  64. ;;
  65. restart)
  66. stop
  67. start
  68. ;;
  69. *)
  70. echo $"Usage: $0 {start|stop|status|restart}"
  71. exit 1
  72. esac
  73. exit $RETVAL
  1. chmod +x /etc/init.d/memcached
  2. chkconfig --add memcached
  3. chkconfig memcached on
  4. service memcached start

安装PHP插件

  1. cd /home/llnmp
  2. tar zxvf memcache-2.2.7.tgz
  3. cd memcache-2.2.7
  4. /usr/local/lsws/lsphp54/bin/phpize
  5. ./configure --with-php-config=/usr/local/lsws/lsphp54/bin/php-config
  6. make -j 4 && make install
  7.  
  8. cd /home/llnmp
  9. tar zxvf libmemcached-1.0.18.tar.gz
  10. cd libmemcached-1.0.18
  11. ./configure --with-memcached=/usr/local/memcached
  12. make -j 4 && make install
  13.  
  14. cd /home/llnmp
  15. tar zxvf memcached-2.1.0.tgz
  16. cd memcached-2.1.0
  17. /usr/local/lsws/lsphp54/bin/phpize
  18. ./configure --with-php-config=/usr/local/lsws/lsphp54/bin/php-config
  19. make -j 4 && make install

配置PHP使其生效

  1. vi /usr/local/lsws/lsphp54/lib/php.ini

修改内容如下

  1. extension_dir = "./" 修改为 extension_dir = "/usr/local/lsws/lsphp54/lib/php/extensions/no-debug-non-zts-20100525/"
  2. 在下面添加
  3. extension = "memcache.so"
  4. extension = "memcached.so"

9.安装Zend Optimizer

因为jieqi需要zend支持,所以给PHP 5.2配置上Zend Optimizer 3.3.9

  1. 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
  2. cd /home/llnmp
  3. tar zxf ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz
  4. mkdir -p /usr/local/lsws/lsphp52/lib/php/Zend
  5. cp ZendOptimizer-3.3.9-linux-glibc23-i386/data/5_2_x_comp/ZendOptimizer.so /usr/local/lsws/lsphp52/lib/php/Zend/
  6.  
  7. cat >>/usr/local/lsws/lsphp52/lib/php.ini < <EOF
  8. [Zend Optimizer]
  9. zend_optimizer.optimization_level=1
  10. zend_extension="/usr/local/lsws/lsphp52/lib/php/Zend/ZendOptimizer.so"
  11. EOF

10.创建测试文件

安装已经完成,但是现在还不能使用,因为还没有配置,在后一篇会对配置进行说明,在这之前咱们先做最后的收尾步骤,创建两个测试文件!

  1. mkdir -p /home/wwwlogs/litespeed #创建litespeed日志目录
  2. mkdir -p /home/wwwroot/php52
  3. mkdir -p /home/wwwroot/php53
  4. cat >/home/wwwroot/php52/index.php < <EOF
  5. <!--?php phpinfo(); ?-->
  6. EOF
  7.  
  8. cat >/home/wwwroot/php53/index.php < <EOF
  9. <!--?php phpinfo(); ?-->
  10. EOF
  11.  
  12. chown -R www.www /home/wwwroot

该装的都装上去了,现在需要做的就是将PHP 5.2与PHP 5.4通过OpenLiteSpeed控制面板整合在一起。

首先登陆OpenLiteSpeed控制面板:http://ip:7080/,输入之前安装时设置的账号密码登陆进去

点击”Configuration”按钮,在其中找到”External App”选项卡,

点击右侧的”Add”连接新建一个,类型选择”LSAPI App”

设置内容如下,未提到的默认即可:

  1. Name: lsphp52
  2. Address: uds://tmp/lshttpd/lsphp52.sock
  3. Max Connections: 35
  4. Environment: PHP_LSAPI_MAX_REQUESTS=10000
  5. PHP_LSAPI_CHILDREN=35
  6. Initial Request Timeout (secs): 60
  7. Retry Timeout (secs): 0
  8. Persistent Connection: Yes
  9. Command: /usr/local/lsws/lsphp52/bin/lsphp
  10. Back Log: 100
  11. Instances: 1
  12. Priority: 0
  13. Memory Soft Limit (bytes): 2047M
  14. Memory Hard Limit (bytes): 2047M
  15. Process Soft Limit: 400
  16. Process Hard Limit: 500

配置完成后点击”Save”保存,然后就会多出来一个”lsphp52″

用同样的方法配置php 5.4,内容如下:

  1. Name: lsphp54
  2. Address: uds://tmp/lshttpd/lsphp54.sock
  3. Max Connections: 35
  4. Environment: PHP_LSAPI_MAX_REQUESTS=10000
  5. PHP_LSAPI_CHILDREN=35
  6. Initial Request Timeout (secs): 60
  7. Retry Timeout (secs): 0
  8. Persistent Connection: Yes
  9. Command: /usr/local/lsws/lsphp54/bin/lsphp
  10. Back Log: 100
  11. Instances: 1
  12. Priority: 0
  13. Memory Soft Limit (bytes): 2047M
  14. Memory Hard Limit (bytes): 2047M
  15. Process Soft Limit: 400
  16. Process Hard Limit: 500

最终如下:

最后咱们添加两个网站,”Configuration”下的”Virtual Hosts”选项卡,点击”Add”新建网站,内容如下:

  1. Virtual Host Name: php52 #网站标识
  2. Virtual Host Root: /home/wwwroot/php52 #网站路径,必须真实存在
  3. Config File: $SERVER_ROOT/conf/php52.xml #配置文件路径
  4. Enable Scripts/ExtApps: Yes
  5. Restrained: Yes
  6. ExtApp Set UID Mode: DocRoot UID

保存后会自动回到网站列表界面,点击刚才创建的网站进去进行修改

选择”General”选项卡,修改内容如下:

  1. Document Root: $VH_ROOT/ #网站路径
  2. Enable GZIP Compression: Yes #启用Gzip压缩

“Script Handler”选项卡添加脚本执行

  1. Suffixes: php #脚本后缀,必要加 "."
  2. Handler Type: LiteSpeed SAPI
  3. Handler Name: lsphp52 #根据需要自己选择

现在网站已经创建好了,但是还没有配置域名对吧?所以呢,现在咱们再为这两个网站配置下域名,”Configuration”下的”Listeners”,点击”Default”也就是默认绑定端口8088,在下方点击”Add”

  1. Virtual Host: php52 #选择自己的网站
  2. Domains: aa.com #要配置的域名,多个域名用英文逗号分隔

OK,到这一步,就算是配置完成了,最后咱们重启一下吧,”Actions” –> “Graceful Restart”,然后使用配置的域名去访问了看看吧!

« 上一篇 | 下一篇 »

发表评论

评论内容 (必填):