Openbsd 3.8上安装配置 APACHE + MYSQL + PHP + mod_limitipco
本文旨在用openbsd自己提供的软件安装包来搭建服务器环境,当然你也可以下载原代码包编译安装,但这样就费时费力了。实际上openbsd给我们提供了大量的编译好的二进制安装包,利用这些二进制安装包我们可以快速部署我们需要的服务器环境,不仅省时还可以保障openbsd的安全性,还可以自动解决各个安装包之间的包依赖问题(用pkg_add来安装远程服务器上的软件包,包依赖问题会自动处理不需要认为干预,这个有点像通过port安装)。下面的文档在一个e文的文档基础上经过整理补充后形成的,那个e文档找不到了。
# export pkg_path=ftp://ftp.openbsd.org/pub/openbsd/3.8/packages/i386/
1. 配置apache服务器:
因为apache是系统默认安装的,这里就省去了安装过程,下面配置apache这样就可以开机运行http了因为在/etc/rc脚本中已经有了httpd服务的启动设置
# vi /etc/rc.conf
改:
httpd_flags=no
为:
httpd_flags=""
对apache做一初步设置
# vi /var/www/conf/httpd.conf
extendedstatus on
serveradmin
servername llzqq.3322.org
servertokens prod
serversignature off
options indexes followsymlinks 改为 options followsymlinks
2. 安装mysql-server-4.0.24p1:
# pkg_add -v mysql-server-4.0.24p1.tgz
# cp /usr/local/share/mysql/my-medium.cnf /etc/my.cnf
如果不想让其他机器连接mysql,可以通过下面的操作实现:
# vi /etc/my.cnf
bind-address = 127.0.0.1
启动mysql-server服务器:
# /usr/local/bin/mysqld_safe &
设置root的mysql密码:
# /usr/local/bin/mysqladmin -u root password mypass
对于chroot下的 mysql:
#mkdir /var/www/var
#chmod -r 1777(或者777) /var/www/var
#vi /etc/my.conf
mysql启动后会产生/var/www/var/run目录,还需要chmod -r 777 /var/www/var/run
自行建立/var/www/var/run
[client]
socket = /var/www/var/run/mysql/mysql.sock
[mysqld]
socket = /var/www/var/run/mysql/mysql.sock
open-files-limit = 8192
open-files = 1000
了方便启动和关闭mysql服务建立了下面的脚本:
# vi /etc/rc.d/mysqld.sh
========================================================
#!/bin/sh
# made by llzqq
# mail:openbsd@163.com
# mysql startup scripts
case "$1" in
start)
if [ -x /usr/local/bin/mysqld_safe ]; then
/usr/local/bin/mysqld_safe &
fi
;;
stop)
pkill mysqld &
rm -f /var/run/mysql/mysql.sock &
;;
*)
echo "$0 start | stop"
;;
esac
exit 0
========================================================
# chmod 555 /etc/rc.d/mysqld.sh
设置开机启动mysql
# vi /etc/rc.local
if [ -f /etc/my.cnf ]; then
/etc/rc.d/mysqld.sh start
fi
3. 安装配置php-4.4.1
# pkg_add -v php4-core-4.4.1p0.tgz
运行下面的命令使其生效
# cp /usr/local/share/examples/php4/php.ini-recommended /var/www/conf/php.ini
# /usr/local/sbin/phpxs -s
由于openbsd上的apache采用了chroot机制,要保证php正常工作就要建下面的目录php工作目录:
# mkdir /var/www/tmp
# chmod 1777 /var/www/tmp
下面选择安装几个php组件:
# pkg_add -v php4-gd-4.4.1p0-no_x11.tgz
# /usr/local/sbin/phpxs -a gd
# pkg_add -v php4-mysql-4.4.1p0.tgz
# /usr/local/sbin/phpxs -a mysql
# pkg_add -v php4-ncurses-4.4.1p0.tgz
# /usr/local/sbin/phpxs -a ncurses
# pkg_add -v php4-imap-4.4.1p0.tgz
# /usr/local/sbin/phpxs -a imap
# pkg_add -v php4-curl-4.4.1p0.tgz
# /usr/local/sbin/phpxs -a curl
# pkg_add -v php4-dbx-4.4.1p0.tgz
# /usr/local/sbin/phpxs -a dbx
# pkg_add -v php4-ldap-4.4.1p0.tgz
# /usr/local/sbin/phpxs -a ldap
# pkg_add -v php4-pdf-4.4.1p0.tgz
# /usr/local/sbin/phpxs -a pdf
# pkg_add -v php4-snmp-4.4.1p0.tgz
# /usr/local/sbin/phpxs -a snmp
设置apache支持php:
# vi /var/www/conf/httpd.conf
directoryindex index.html index.php
addtype application/x-httpd-php .php
addtype application/x-httpd-php-source .phps
# vi /var/www/conf/php.ini
doc_root= "/htdocs"
register_globals = on
建立测试php页面
# vi /var/www/htdocs/test.php
<?php phpinfo(); ?>
测试一下:
# pkill httpd
# /usr/sbin/httpd
在浏览器中输入http://ip/test.php实验一下
4. 安装mod_limitipconn模块来限制单ip的并发连接数
# wget
# tar xzf mod_limitipconn-0.04.tar.gz
# cd mod_limitipconn-0.04
# vi makefile
apxs = /usr/sbin/apxs
# make
# make install
让apache支持这个模块:
# vi /var/www/conf/httpd.conf
<ifmodule mod_limitipconn.c>
<location />
maxconnperip 5
</location>
</ifmodule>
到次整个安装过程结束。
附件部分:
我们为让apache支持ssl传输配置apache:
# vi /var/www/conf/httpd.conf
添加下面两行:
sslcertificatefile /etc/ssl/server.crt
sslcertificatekeyfile /etc/ssl/private/server.key
为了使apache启动时启用ssl,设置一下apache启动选项:
# vi /etc/rc.conf.local
改:
httpd_flags="" # or it could have httpd_flags=no
为:
httpd_flags="-dssl # or it could have httpd_flags=no
手动启动和关闭apache这样做就可以了:
# apachectl startssl
# apachectl stop
下面是设置apache+ssl的过程:
1. 创建服务器key文件 (1024 bit) :
# /usr/sbin/openssl genrsa -out /etc/ssl/private/server.key 1024
2. 创建服务器csr文件(certificate signing request)
# /usr/sbin/openssl req -new -key /etc/ssl/private/server.key -out /etc/ssl/private/server.csr
这里自己填写一些注册信息
3. 生成签名证书(365天有效证书):
# /usr/sbin/openssl x509 -req -days 365 -in /etc/ssl/private/server.csr -signkey /etc/ssl/private/server.key -out /etc/ssl/server.crt
4. 虚拟主机部分:
namevirtualhost 192.168.10.1:*
<virtualhost 192.168.10.1:443>
serveradmin
documentroot /var/www/llzqq
servername llzqq.home.com
errorlog logs/llzqq.home.com-error_log
customlog logs/llzqq.home.com-access_log common
sslengine on
sslciphersuite all:!adh:rc4+rsa:+high:+medium:+low:+sslv2:+exp
sslcertificatefile /etc/ssl/virtualsite.com.crt
sslcertificatekeyfile /etc/ssl/private/server.key
</virtualhost>
<virtualhost 192.168.10.1:80>
serveradmin
documentroot /var/www/llzgg
servername llzgg.home.com
errorlog logs/llzgg.home.com-error_log
customlog logs/llzgg.home.com-access_log common
</virtualhost>
其他部分待续(现在没pc装openbsd了有些资料不好整理了)
推荐阅读
-
CentOS 6.4安装配置LAMP服务器(Apache+PHP5+MySQL)
-
lanmp(Linux Apache Nginx Mysql Php) 的安装配置
-
Ubuntu 18.04上安装Apache、MySQL、PHP、LAMP的完整教程
-
CentOS 5.4 服务器配置 yum安装Apache+php+Mysql
-
Win2003下APACHE+PHP5+MYSQL4+PHPMYADMIN 的简易安装配置
-
Windows下IIS6/Apache2.2.4+MySQL5.2+PHP5.2.1安装配置方法
-
Ubuntu Server 11.10安装配置lamp(Apache+MySQL+PHP)
-
CentOS 5.11服务器安装配置LAMP服务器(Apache+PHP5+MySQL)
-
OPENBSD-3.8上快速安装和配置apache+mysql+php+ssl
-
Freebsd7.0 Apache2.2+MySQL5+PHP5安装和配置方法