# export PKG_PATH=ftp://www.jiarun.org/# pkg_add mysql-servermysql-server-5.1.48:mysql-client-5.1.48: okmysql-server-5.1.48:p5-Net-Daemon-0.43: okmysql-server-5.1.48:p5-PlRPC-0.2018p0: okmysql-server-5.1.48:p5-DBI-1.609: okmysql-server-5.1.48:p5-DBD-mysql-4.014: okmysql-server-5.1.48: ok--- +mysql-server-5.1.48 -------------------You can find detailed instructions on how to install a databasein /usr/local/share/doc/mysql/README.OpenBSD.#
创建默认的数据库:# /usr/local/bin/mysql_install_dbInstalling MySQL system tables...110307 13:36:00 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead.OKFilling help tables...110307 13:36:00 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead.OK PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !To do so, start the server, then issue the following commands: /usr/local/bin/mysqladmin -u root password 'new-password'/usr/local/bin/mysqladmin -u root -h jr.gateway.2wire.net password 'new-password' Alternatively you can run:/usr/local/bin/mysql_secure_installation which will also give you the option of removing the testdatabases and anonymous user created by default.  This isstrongly recommended for production servers. See the manual for more instructions. Please report any problems with the /usr/local/bin/mysqlbug script! #
运行Mysql# mysqld_safe &[1] 8078# 110307 13:37:44 mysqld_safe Logging to '/var/mysql/jr.gateway.2wire.net.err'.110307 13:37:44 mysqld_safe Starting mysqld daemon with databases from /var/mysql #
设定本地mysql的root密码# mysqladmin -u root password 'jiarun.org'
创建Mysql配置文件# cp /usr/local/share/mysql/my-medium.cnf /etc/my.cnf
要让数据库的字符集编码默认是UTF-8,还要修改一下/etc/my.cnf文件,必须包含如下的内容:[client] default-character-set=utf8 [mysqld] default-character-set=utf8 init_connect='SET NAMES utf8'
此外基本设置里的(修改为自己觉得合适的大小)max_allowed_packet = 1M建立Mysql登录级别mysql:\ :openfiles-cur=1024:\ :openfiles-max=2048:\ :tc=daemon:然后重建login.conf.db文件# cap_mkdb /etc/login.conf重新启动系统后建立一个数据库# mysql -pEnter password:jiarunWelcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 1Server version: 5.1.48-log OpenBSD port: mysql-server-5.1.48Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.This software comes with ABSOLUTELY NO WARRANTY. This is free software,and you are welcome to modify and redistribute it under the GPL v2 licenseType 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>CREATE DATABASE `jiarunorg` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;分配用户leo具有数据库jiarunorg的所有权限,操作是本地,密码为jiarun:mysql> grant all on jiarunorg.* to leo@localhost identified by 'jiarun'; Query OK, 0 rows affected (0.00 sec)这里注意,论坛真正运行时并不需要全部的权限,安装完成后读者请根据自己所用软件的要求来自行消减该用户权限。 退出mysqlmysql> quit Bye #安装apache2# export PKG_PATH=ftp://www.jiarun.org/# pkg_add apache-httpdapache-httpd-2.2.15:pcre-8.02p1: okapache-httpd-2.2.15:apr-mt-1.2.11p4: okapache-httpd-2.2.15:db-4.6.21p0: okapache-httpd-2.2.15:libiconv-1.13p1: okapache-httpd-2.2.15:apr-util-mt-1.2.10p4: okapache-httpd-2.2.15: ok--- +apache-httpd-2.2.15 -------------------This is the official httpd distributed by the Apache Server Project,provided as a port for those who, for various reasons, need to runversion 2. OpenBSD provides a custom Apache server, httpd(8), in the base systemwhich has been audited for security and may run in a chroot(2)environment.  Users are STRONGLY encouraged to use the system httpdrather than this port.#如果想在OpenBSD系统启动时自动运行Apache2,在/etc/rc.local文件里加上如下两行:echo "starting apache2..." /usr/local/sbin/apachectl2 startapache2的主目录在 /var/apache2/htdocs/到目前为止安装的pkckages# pkg_infoapache-httpd-2.2.15 apache HTTP serverapr-mt-1.2.11p4     Apache Portable Runtimeapr-util-mt-1.2.10p4 companion library to APRdb-4.6.21p0         Berkeley DB package, revision 4libiconv-1.13p1     character set conversion librarymysql-client-5.1.48 multithreaded SQL database (client)mysql-server-5.1.48 multithreaded SQL database (server)p5-DBD-mysql-4.014  MySQL drivers for the Perl DBIp5-DBI-1.609        unified perl interface for database accessp5-Net-Daemon-0.43  extension for portable daemonsp5-PlRPC-0.2018p0   module for writing rpc servers and clientspcre-8.02p1         perl-compatible regular expression library#安装phpPorts系统内PHP及其所有扩展全是为apache 1.3“量身定制”的,不过我们讨论的是apache2,所以如果直接使用pkg_add安装编译好的php内核和扩展,就会在运行apache2时遇到运行错误。这就需要自己动手修改ports了。需要在以下两个文件内用CONFIGURE_ARG+来定义新的flag,也就是将原来的CONFIGURE_ARGS+= --with-apxs=/usr/sbin/apxs \替换为CONFIGURE_ARGS+= --with-apxs2=/usr/local/sbin/apxs2 \有关CONFIGURE_AGS+的说明请参阅设置工作已经结束了,现在我们的就需要手动编译php内核及其扩展了。# cd /usr/ports/www/php5 # make install上面的命令会按照我们的设定编译PHP内核以及所有的php扩展,如果你不想编译某些模块或者说想进行特殊的设定,自己在/usr/ports/www/php5 里运行# make show=FLAVORS我的实验系统是i386,所以生成的packages文件在 /usr/ports/packages/i386/all/ 里面以下是packages清单:DirectoryIndex index.html设置为DirectoryIndex index.html index.php让apache2支持对.php文件代码的分析在里加上AddType application/x-httpd-php .php添加php的DSO模块支持。LoadModule php5_module /usr/local/lib/php/libphp5.so安装pear# pkg_add pear pear-1.7.2:pear-utils-1.7.2: ok pear-1.7.2: ok安装# pkg_add p5-XML-Parser编辑 /var/www/conf/php.ini找到:; Maximum size of POST data that PHP will accept. post_max_size = 8M这会限制每个帖子的大小,放大一些吧,我是改为50M。找到:; Maximum allowed size for uploaded files. upload_max_filesize = 2M这会限制上传文件大小,请自己根据需要修改找到:; Maximum number of files that can be uploaded via a single request max_file_uploads = 20一次最多上传的文件数,请自行修改。还有两个我是一般要修改的:short_open_tag = On display_errors = On这里请注意,配置文档里强烈建议在生产环境里关闭第二条选项,而以日志文档的方式代替,我打开这个只是因为每种论坛程序需要的php模块可能略有差别,有时候可能因为缺少模块安装过程无法继续或运行不正常,这无法在这里一一列举了,而且就我所尝试的程序也很有限,大家在实际应用中应该结合自己的情况并具体错误提示找出适合的php5插件,一旦你确认运行无误后请自行将第二个参数修改为Off。最后说一下rewrite规则的设定,apache2的配置文件在 /etc/apache2/httpd2.conf, 请确保这里没有被注释掉:LoadModule rewrite_module /usr/local/lib/apache2/mod_rewrite.so此外,再将下列代码里面的红色部分设置为
09-17 21:26