在FreeBSD下安装mysql+apache+php

在FreeBSD下安装mysql+apache+php
===============================================
 
作者: Wandering
 

[目录]
 
   1. 安装Mysql
   2. 安装Apache
   3. 安装PHP
   4. 配置httpd.conf
   5. 启动/停止apache
 


1. 安装Mysql
================


《MySQL Reference Manual》手册中提供了标准安装方法,详见"MySQL Reference Manual -> 2. Installing MySQL -> 2.7. Installing MySQL on Other Unix-Like Systems"


1.1 二进制版本的安装方法

# created by wandering 2005/04/09
--------------------------
#
# 目前的Mysql都是编译好的二进制代码,configure后可直接使用,且无需初始化数据库
# 默认情况,我把安装文件放在/usr/src目录中,把应用安装到/usr/local目录中
#
shell> 先创建mysql用户和mysql组
shell> cd /usr/local
shell> tar zxvf mysql-standard-4.1.11-unknown-freebsd4.7-i386.tar.gz
shell> ln -s ./mysql-standard-4.1.11-unknown-freebsd4.7-i386 ./mysql
shell> cd mysql
shell> scripts/mysql_install_db --user=mysql
shell> chown -R root  .
shell> chown -R mysql data
shell> chgrp -R mysql .
shell> bin/mysqld_safe --user=mysql &
shell> /usr/local/mysql/bin/mysqld_safe --user=root &
shell> echo "/usr/local/mysql/bin/mysqld_safe &" >> /etc/rc.local

OK,Mysql已安装完毕。
 
 
 
1.2 源代码版本的编译安装方法

# added by wandering 2005/12/28
-----------------------------
有时我们也需要编译安装, 最近我在FreeBSD6.0上安装Mysql时, 发现Mysql的二进制版本最高只支持FreeBSD5.3, 经测试, 二进制的安装方法没有成功. 只好手工编译安装了.
 
安装之前一定要仔细看看INSTALL-SOURCE这个文件, 非常之有用啊!!!
 
shell> pw group add mysql
shell> pw user add -n mysql -d /usr/local/mysql -s /usr/sbin/nologin
shell> tar zxvf mysql-5.0.18
shell> cd mysql-5.0.18
shell> ./configure --prefix=/usr/local/mysql --localstatedir=/usr/local/mysql/data
shell> make
shell> make install
shell> cp support-files/my-medium.cnf /etc/my.cnf
shell> cd /usr/local/mysql
shell> mkdir data
shell> bin/mysql_install_db --user=mysql
shell> chown -R root  .
shell> chown -R mysql data
shell> chgrp -R mysql .
shell> bin/mysqld_safe --user=mysql &
shell> echo "/usr/local/mysql/bin/mysqld_safe &" >> /etc/rc.local
 
OK, 可以用了.
 
 
用netstat命令可以看到服务器3306端口处于监听状态。

/usr/local/mysql/bin/mysqladmin -u root -p password <new_password>
enter password:
# 修改root口令,root初始密码为空,所以直接回车就可以了

测试一下新的密码:
mysql -u root -p mysql
enter password:<new_password><CR>
 
 
*注意: 有的时候在一些系统上, mysql要求必须要有mysql.host表存在, 才能正常启动mysql服务进程. 只好把别的机子上的mysql.host的三个文件拷贝过来才能解决. 奇怪!
 
 

2. 安装Apache
===============
 
*注意: 建议先安装perl, 再安装apache.
 
# tar zxvf httpd-2.2.0.tar.gz
# cd httpd-2.2.0
# ./configure --prefix=/usr/local/apache --enable-so --enable-mods-shared=all --enable-rewrite=shared --enable-speling=shared && make && make install
#
 
**注: 其中--enable-so选项是配置Apache以共享后安装的模块 
 
 
 
3. 安装PHP
============
 
步骤:
 
   3.1 安装gd-2.0.33.tar.gz
   3.2 安装libxml2-2.6.27.tar.gz
   3.3 安装libiconv-1.9.2.tar.gz
   3.4 安装php
 
 
3.1 安装gd
------------
 
gd需要以下模块:
 
 . zlib-1.2.3.tar.gz
 . libpng-1.2.8-config.tar.gz
 . freetype-2.1.10.tar.gz (可选装)
 . xpm-3.4k.tar.gz (可选装)
 . jpegsrc.v6b.tar.gz (可选装)

 
3.1.1 安装zlib
-----------------
# tar zxvf zlib-1.2.3.tar.gz
# cd zlib-1.2.3
# ./configure && make && make install
 
默认情况zlib被安装到/usr/local/include/
 
 
3.1.2 安装libpng
----------------
# tar zxvf libpng-1.2.12.tar.gz
# cd libpng-1.2.12
# ./configure && make && make install
 
默认情况libpng被安装到/usr/local/include/libpng/
 
 
3.1.3 安装gd
--------------
# tar zxvf gd-2.0.33.tar.gz
# cd gd-2.0.33
# cp /usr/local/include/png.h .
# cp /usr/local/include/pngconf.h .
# ./configure && make && make install
#
 
*** 我遇到过gd_png.c找不到png库文件的情况, 这时要手工把png.h和pngconf.h两个文件拷贝到gd_png.c所在目录就可以了. ***
 
默认情况gd被安装到/usr/local/include/
 
 

3.2 安装libxml2
-----------------
# tar zxvf libxml2-2.6.26.tar.gz
# cd libxml2-2.6.26
# ./configure && make && make install
#
 


3.3 安装libiconv
-------------------
# tar zxvf libiconv-1.9.2.tar.gz
# cd libiconv-1.9.2
# ./configure && make && make install
 



3.4 安装PHP
--------------
# tar zvxf php-5.1.4.tar.gz
# cd php-5.1.4
# vi /usr/local/apache/bin/apxs
 
将"#!/replace/with/path/to/perl/interpreter -w"替换为"#!/usr/bin/perl -w"
 
# ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-apxs2=/usr/local/apache/bin/apxs --with-libxml-dir=/usr/local/include/libxml2/libxml --enable-mbstring --with-gd --with-zlib
 
# make
# make install
# cp php.ini-dist /usr/local/php/lib/php.ini
# vi /usr/local/php/lib/php.ini

php.ini配置:
1、找到;default_charset = "iso-8859-1", 在下面添加default_charset = "gb2312"
2、配置max_execution_time,它的意思为“Maximum execution time of each script, in seconds”,经常需要长时间数据操作或去处的页面应该进行适当调整,这里我设置为300秒。

 
 
这是在redhat下编译的一个配置实例:
# ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-apxs2=/usr/local/apache/bin/apxs --with-libxml-dir=/usr/local/include/libxml2/libxml --with-iconv-dir=/usr/local --enable-mbstring --with-gd --enable-gd-native-ttf --with-jpeg-dir=/usr --with-png-dir=/usr/local --with-zlib-dir=/usr/local --with-ttf=/usr/local --with-freetype-dir=/usr/local
 
 
 
*** 注: 在configure过程中, 可能会遇到下面的错误! Sorry, I cannot run apxs. ***
 
configure: error: Sorry, I cannot run apxs. Either you need to install Perl or you need to pass the absolute path of apxs by using --with-apxs=/absolute/path/to/apxs
 
网上有很多介绍解决方法的, 但最经典的只有Darrell Brogdon在2001/03/15写的<<Installing PHP as an Apache DSO>>, 这篇文章在绿盟有徐永久在2002-03-18翻译的中文版<<在Apache上以DSO方式安装PHP>>, 不过上面著名他本人就是文章的作者, 这点我表示怀疑.
 
我之所以说这么多, 只是想说明目前我看到的方法, 没有能够真正解决这个问题的.
 
OK, 下面我说明一下我是如何解决这个问题的:
 
首先, 通过错误提示, 我们得知"I cannot run apxs". 我一直以为是apxs安装有问题, 但找了很久仍未得到合理的解释和解决方法.
 
于是我直接运行"/usr/local/apache/bin/apxs"这个脚本, 得到下面的错误提示:
 
bash: ./apxs: /replace/with/path/to/perl/interpreter: bad interpreter: No such file or directory
 
哦, 给人的感觉很像仍然是apxs程序有问题, 但问题在哪里呢? "interpreter"是什么呢? interpreter是"解释程序"!
 
嗯, 看来我们接近答案了, 运行"head -1 /usr/local/apache/bin/apxs"得到下面内容:
 
#!/replace/with/path/to/perl/interpreter -w
 
天啊, 这里没有指明正确的perl执行程序的位置! 原来这就才是真正的问题原因所在!!!
 
把这一行更改为"#!/usr/bin/perl -w". 再运行php的configure, 一切正常!
 
至此, 问题已解决.
 
*** Sorry, I cannot run apxs. ***



4. 配置httpd.conf
====================
 
4.1 找到ServerName , 将 替换为本机的域名
------------------------------------------
ServerName freebsd6.local:80
 
 
4.2 找到"DirectoryIndex index.html", 在"index.html"后面加入"index.php"
------------------------------------------------------------------------
<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>
 
 
4.3 找到<IfModule mime_module>, 在AddType application/x-gzip .gz .tgz下面加入
------------------------------------------------------------------------------- 
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
 
 
4.4 找到<Directory "/usr/local/apache/htdocs"> ... </Directory>, 在下面加入
-----------------------------------------------------------------------------
<Directory /data1/apache/htdocs/it>
    Options Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

<Directory /data1/apache/htdocs/it_old>
    Options Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
 
 
4.5 找到<Directory "/usr/local/apache/cgi-bin"> ... </Directory>, 在下面加入
------------------------------------------------------------------------------
<Directory "/data1/apache/htdocs/perl">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
</Directory>
 
 
4.6 找到<IfModule alias_module> ... </IfModule>, 在中间区域加入
----------------------------------------------------------------
Alias /it "/data1/apache/htdocs/it"
Alias /it_old "/data1/apache/htdocs/it_old"
 
ScriptAlias /perl/ "/data1/apache/htdocs/perl/"
 
 
 
 
5. 启动/停止apache
=====================
/usr/local/apache/bin/apachectl start
/usr/local/apache/bin/apachectl stop
 
**注: 要确保主机名能够正常被解析为本机的IP地址.

 
*** 在执行"/usr/local/apache/bin/apachectl start"的时候可能会出现下面错误提示:
 
[Fri Dec 30 09:35:01 2005] [warn] (2)No such file or directory: Failed to enable the 'httpready' Accept Filter 
 
解决方法:
 
step 1
-------
编辑/etc/hosts和/etc/rc.conf, 配置主机域名. 例如:
 
shell> cat /etc/hosts
127.0.0.1               localhost
192.168.177.130         freebsd6 freebsd6.local
 
shell> cat /etc/rc.conf
hostname="freebsd6.local"
...
 
step 2
-------
on FreeBSD, you need to add a kernelmodule

kldload accf_http

grep accf /boot/defaults/loader.conf
accf_data_load="NO" # Wait for data accept filter
accf_http_load="NO" # Wait for full HTTP request accept filter

add the second to /boot/loader.conf with 'YES' to enable this permenately.

 
 
 
-----------------------------------------------------------------------------

# 2005/04/09 16:00 - 2005/04/10 13:16 Created by Wandering
# 2005/12/29 23:28 Modified by Wandering
# 2006/03/12 19:31 Modified by Wandering
# 2006/03/18 00:45 Modified by Wandering
# 2006/07/17 23:56 Modified by Wandering
 





附录:
 
*Apache 2.0的DSO功能简要说明:
-------------------------------
编译并安装已发布的Apache模块,比如编译mod_foo.c为mod_foo.so的DSO模块:
$ ./configure --prefix=/path/to/install --enable-foo=shared
$ make install

编译并安装第三方Apache模块, 比如编译mod_foo.c为mod_foo.so的DSO模块:
$ ./configure --add-module=module_type:/path/to/3rdparty/mod_foo.c --enable-foo=shared
$ make install

配置Apache以共享后安装的模块:
$ ./configure --enable-so
$ make install

用apxs在Apache源代码树以外编译并安装第三方Apache模块,比如编译mod_foo.c为mod_foo.so的DSO模块:
$ cd /path/to/3rdparty
$ apxs -c mod_foo.c
$ apxs -i -a -n foo mod_foo.la

共享模块编译完毕以后,都必须在httpd.conf中用LoadModule指令使Apache激活该模块。


 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值