博客 / Others/ 安装openlitespeed服务器&PHP7&mysql5.6服务器

安装openlitespeed服务器&PHP7&mysql5.6服务器

安装openlitespeed服务器&PHP7&mysql5.6服务器

编译安装 OpenLiteSpeed 服务器

如果您选择编译安装,请遵循以下步骤。

1. 安装所需组件

请参照文章《编译安装 openLitespeed 服务器所需依赖的包》安装必要的依赖包。

2. 编译选项说明

编译时,您可以使用以下参数进行微调。如果您不熟悉这些选项,建议使用默认配置。

Fine tuning of the installation directories:
--bindir=DIR            user executables [EPREFIX/bin]
--sbindir=DIR           system admin executables [EPREFIX/sbin]
--libexecdir=DIR        program executables [EPREFIX/libexec]
--sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
--sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
--localstatedir=DIR     modifiable single-machine data [PREFIX/var]
--libdir=DIR            object code libraries [EPREFIX/lib]
--includedir=DIR        C header files [PREFIX/include]
--oldincludedir=DIR     C header files for non-gcc [/usr/include]
--datarootdir=DIR       read-only arch.-independent data root [PREFIX/share]
--datadir=DIR           read-only architecture-independent data [DATAROOTDIR]
--infodir=DIR           info documentation [DATAROOTDIR/info]
--localedir=DIR         locale-dependent data [DATAROOTDIR/locale]
--mandir=DIR            man documentation [DATAROOTDIR/man]
--docdir=DIR            documentation root [DATAROOTDIR/doc/openlitespeed]
--htmldir=DIR           html documentation [DOCDIR]
--dvidir=DIR            dvi documentation [DOCDIR]
--pdfdir=DIR            pdf documentation [DOCDIR]
--psdir=DIR             ps documentation [DOCDIR]

Program names:
--program-prefix=PREFIX prepend PREFIX to installed program names
--program-suffix=SUFFIX append SUFFIX to installed program names
--program-transform-name=PROGRAM run sed PROGRAM on installed program names

System types:
--build=BUILD configure for building on BUILD [guessed]
--host=HOST cross-compile to build programs to run on HOST [BUILD]

Optional Features:
--disable-option-checking ignore unrecognized --enable/--with options
--disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
--enable-FEATURE[=ARG] include FEATURE [ARG=yes]
--enable-silent-rules less verbose build output (undo: "make V=1")
--disable-silent-rules verbose build output (undo: "make V=0")
--enable-dependency-tracking
  do not reject slow dependency extractors
--disable-dependency-tracking
  speeds up one-time build
--enable-shared[=PKGS] build shared libraries [default=yes]
--enable-static[=PKGS] build static libraries [default=yes]
--enable-fast-install[=PKGS]
  optimize for fast installation [default=yes]
--disable-libtool-lock avoid locking (might break parallel builds)
--disable-assert turn off assertions
--enable-adminssl=[yes/no]
  Enable HTTPS for admin console (modify adminssl.conf
  before installation) [default=yes]
--enable-spdy=[yes/no] Enable SPDY and http2 over HTTPS [default=yes]
--enable-http2=[yes/no] Enable SPDY and http2 over HTTPS [default=yes]
--enable-redis Enable redis for cache module (Using redis is
  disabled by default)
--enable-debug Enable debugging symbols (Debug is disabled by
  default)
--enable-profiling Enable cpu profiling (profiling is disabled by
  default)
--disable-rpath Disable rpath (It is 'no' by default)

Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
--without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
--with-pic[=PKGS] try to use only PIC/non-PIC objects [default=use
  both]
--with-gnu-ld assume the C compiler uses GNU ld [default=no]
--with-sysroot=DIR Search for dependent libraries within DIR
  (or the compiler's sysroot if not specified).
--with-user Set user name to run openlitespeed [default: nobody]
--with-group Set group of the user [default: nobody]
--with-admin Set administrator user name [default: admin]
--with-password Set password of administrator [default: 123456]
--with-email Set email of administrator [default: root@localhost]
--with-lua[=DIR] use liblua (located in directory DIR, if supplied) for compiling mod_lua module. [default=no]
--with-libdir Set system lib directory. It is lib or lib64 and
  will be automatically checked by default
--with-zlib=DIR root directory path of zlib installation defaults to
  /usr/local or /usr if not found in /usr/local
--without-zlib to disable zlib usage completely
--with-openssl=DIR root of the OpenSSL directory
--with-pcre[=prefix] compile xmlpcre part (via libpcre check)
--with-expat=[ARG] use Expat XML Parser from given prefix (ARG=path);
  check standard prefixes (ARG=yes); disable (ARG=no)
--with-expat-inc=[DIR] path to Expat XML Parser headers
--with-expat-lib=[ARG] link options for Expat XML Parser libraries

Some influential environment variables:
CXX C++ compiler command
CXXFLAGS C++ compiler flags
LDFLAGS linker flags, e.g. -L if you have libraries in a
  nonstandard directory LIBS libraries to pass to the linker, e.g. -l CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I if
  you have headers in a nonstandard directory
CC C compiler command
CFLAGS C compiler flags
CPP C preprocessor
CXXCPP C++ preprocessor

3. 编译注意事项

使用 Google Cloud Shell 的 gcc 编译时,如果默认用户权限不足,需要切换到 root 用户。但默认情况下 root 密码未设置。请按以下步骤操作:

  1. 设置 root 用户密码:sudo passwd root
  2. 切换到 root 用户:su root

完成上述步骤后,再执行编译命令即可顺利进行。

4. 开放防火墙端口

编译安装完成后,可能无法通过浏览器访问默认的 8088(示例页面)和 7080(管理页面)端口。这是因为默认的防火墙规则未开放这些端口。

您需要在服务器的防火墙或安全组设置中添加规则,允许 TCP 协议访问 7080 和 8088 端口。规则示例如下:

  • 规则名称:allow-openlitespeed-default-port
  • 协议/端口:tcp:7080, tcp:8088
  • 来源:0.0.0.0/0(或根据您的安全需求限制来源 IP)

添加规则后,即可通过浏览器访问管理后台进行配置。

配置 OpenLiteSpeed 虚拟主机

成功访问后台后,需要进行服务器配置。以下是基本步骤:

1. 创建监听器 (Listener)

新建一个监听 80 端口的监听器,命名为 web

2. 创建虚拟主机模板 (Virtual Host Template)

首先,通过 SSH 手动创建模板配置文件:

vi /usr/local/lsws/conf/templates/php-web.conf
chmod 777 /usr/local/lsws/conf/templates/php-web.conf

然后,在管理后台面板中创建虚拟主机模板:

  • Template Name: php-web
  • Template File: $SERVER_ROOT/conf/templates/php-web.conf
  • Mapped Listeners: web

保存并重启服务器。

3. 创建虚拟主机 (Virtual Host)

首先,通过 SSH 创建网站根目录和主机配置文件:

cd /
mkdir -p /wwwroot/html
chmod 755 /wwwroot /wwwroot/html
touch /usr/local/lsws/conf/vhosts/xxxx.conf
chmod 777 /usr/local/lsws/conf/vhosts/xxxx.conf

然后,在管理后台创建虚拟主机:

  • 根目录: $SERVER_ROOT/wwwroot/html/$VH_NAME
  • 配置文件位置: $SERVER_ROOT/conf/vhosts/$VH_NAME.conf

最后,在 Listener web > General 设置中,将刚才创建的虚拟主机绑定到您的域名。

通过 RPM 源安装 PHP 7

1. 安装依赖与 PHP 7 包

执行以下命令添加仓库并安装 PHP 7.0 及相关模块:

yum install epel-release -y
rpm -ivh http://rpms.litespeedtech.com/centos/litespeed-repo-1.1-1.el6.noarch.rpm
yum install lsphp70 lsphp70-common lsphp70-gd lsphp70-process lsphp70-mbstring lsphp70-mysqlnd lsphp70-xml lsphp70-mcrypt lsphp70-pdo lsphp70-imap -y

安装完成后,PHP 二进制文件位于 /usr/local/lsws/lsphp70/bin/lsphp

2. 在 OpenLiteSpeed 中配置 PHP 7

进入管理后台,按以下步骤操作:

  1. 导航至 Server Configuration > External App
  2. 添加一个 LiteSpeed SAPI App
  3. 填写主要配置信息(其他选项可保持默认):
Name: lsphp70
Address: uds://tmp/lshttpd/lsphp70.sock
Max Connections: 35
Environment: PHP_LSAPI_MAX_REQUESTS=500
           PHP_LSAPI_CHILDREN=35
Initial Request Timeout (secs): 60
Retry Timeout : 0
Response Buffering: no
Auto Start: yes
Command: $SERVER_ROOT/lsphp70/bin/lsphp
Back Log: 100
Instances: 1
Memory Soft Limit (bytes): 2047M
Memory Hard Limit (bytes): 2047M
Process Soft Limit: 400
Process Hard Limit: 500

保存并重启服务器。

3. 配置脚本处理器 (Script Handler)

导航至 WebAdmin console > Server > Script Handler

编辑后缀为 php 的处理器,将其 Handler Name 修改为刚才创建的 lsphp70。保存并重启服务器。

备注:PHP 7 的配置文件位于 /usr/local/lsws/lsphp70/etc/php.ini

4. (可选)编译安装 PHP 7 的建议参数

如果您选择编译安装 PHP 7 作为 Web 服务器使用,可以参考以下编译参数:

--with-litespeed --enable-fpm --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pear --enable-libgcc --with-zlib --with-gd --enable-gd-native-ttf --enable-shmop --enable-sockets --enable-sysvsem --enable-sysvshm --enable-mbstring --enable-soap --with-iconv --enable-xml --with-openssl --with-mcrypt --with-xmlrpc --with-bz2 --enable-zip --with-curl --with-png-dir --with-jpeg-dir --with-freetype-dir --disable-ipv6 --disable-rpath --disable-short-tags --without-sqlite3 --without-imap --enable-session

编译安装 MySQL 5.6

1. 安装编译工具和依赖库

yum install gcc gcc-c++ ncurses-devel perl -y

2. 安装 CMake

CMake 官网下载源码并编译安装:

wget http://www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz
tar -xzvf cmake-2.8.10.2.tar.gz
cd cmake-2.8.10.2
./bootstrap
make
make install
cd ~

3. 创建 MySQL 用户和组

groupadd mysql
useradd -r -g mysql mysql

4. 创建安装目录和数据目录

mkdir -p /usr/local/mysql
mkdir -p /usr/local/mysql/mysqldb

5. 下载并编译 MySQL

wget http://www.kakapart.com/files/mysql-5.6.16.tar.gz
tar -zxv -f mysql-5.6.16.tar.gz
cd mysql-5.6.16

使用 CMake 进行配置编译,关键参数如下:

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql 
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock 
-DDEFAULT_CHARSET=utf8 
-DDEFAULT_COLLATION=utf8_general_ci 
-DWITH_INNOBASE_STORAGE_ENGINE=1 
-DWITH_ARCHIVE_STORAGE_ENGINE=1 
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 
-DMYSQL_DATADIR=/usr/local/mysql/mysqldb 
-DMYSQL_TCP_PORT=3306 
-DENABLE_DOWNLOADS=1

6. CMake 参数说明

  • -DCMAKE_INSTALL_PREFIX=dir_name: 设置 MySQL 安装目录。
  • -DMYSQL_UNIX_ADDR=file_name: 设置 MySQL 套接字文件路径,必须为绝对路径,默认为 /tmp/mysql.sock
  • -DDEFAULT_CHARSET=charset_name: 设置服务器默认字符集。
  • -DDEFAULT_COLLATION=collation_name: 设置服务器默认排序规则。
  • -DWITH_*_STORAGE_ENGINE=1: 启用指定的存储引擎(如 InnoDB, ARCHIVE, BLACKHOLE)。MyISAM, MEMORY, CSV 等引擎默认已编译。
  • -DMYSQL_DATADIR=dir_name: 设置 MySQL 数据库文件存放目录。
  • -DMYSQL_TCP_PORT=port_num: 设置 MySQL 服务监听端口,默认为 3306。
  • -DENABLE_DOWNLOADS=bool: 是否在编译过程中下载可选文件(如测试套件)。

配置完成后,执行 make && make install 进行编译和安装。安装后的初始化、配置及启动步骤请参考 MySQL 官方文档。

发表评论

您的邮箱不会公开。必填项已用 * 标注。