编译安装mysql+apache+php

编译安装mysql+apache+php
=================================

作者: Wandering


*注1:文章原名为<<
在FreeBSD下安装mysql+apache+php >>
*注2:2008/11/22重新整理修订,更改文章名



[目录]
 
   1. 安装Mysql
   2. 安装Apache
   3. 安装PHP
   4. 配置httpd.conf



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


参考文档1: 《MySQL Reference Manual》 -> " Installing MySQL on Other Unix-Like Systems"
参考文档2:源代码自带的 INSTALL-SOURCE 文件


1.1 编译安装

# groupadd mysql
# useradd -g mysql -d /usr/local/lib/mysql -s /sbin/nologin mysql

# tar zxvf mysql-x.x.x
# cd mysql-x.x.x
# ./configure --prefix=/usr/local/
lib/ mysql --localstatedir=/usr/local/ lib/ mysql/data --with-charset=utf8 --with-extra-charsets=all 
# make
# make install


# cp support-files/my-medium.cnf /etc/my.cnf

# cd /usr/local/
lib/ mysql
# mkdir data
# bin/mysql_install_db --user=mysql
# chown -R root  .
# chown -R mysql data
# chgrp -R mysql .

# echo "/usr/local/
lib/ mysql/bin/mysqld_safe &" >> /etc/rc.local
# 
/usr/local/ lib/ mysql/ bin/mysqld_safe --user=mysql &


1.2 进入mysql的DBMS

# /usr/local/
lib/ mysql/bin/mysql -u root -p
enter password: <Enter>

*注:默认mysql的root用户口令为空


1.3 mysql数据在页面显示为中文乱码的问题

--with-extra-charsets=all是解决中文乱码的关键参数,它的作用是安装额外的字符集,其中即包括gbk等中文字符集。 在创建数据库时手工指定字符集为gbk,这样就可以保证同样使用gbk字符集的HTML 页面正常地显示中文了:
create database <db_name> default character set gbk collate gbk_chinese_ci;




2. 安装Apache
===============


2.1 编译安装

# tar zxvf httpd-x.x.x.tar.gz
# cd httpd-x.x.x
# ./configure --prefix=/usr/local/
lib/ apache --enable-so --enable-mods-shared=all --enable-rewrite=shared --enable-speling=shared
# 
make
# 
make install


2.2 
apache 启动停止命令

# /usr/local/ lib/ apache/bin/apachectl start
# /usr/local/
lib/ apache/bin/apachectl stop
# /usr/local/ lib/ apache/bin/apachectl restart


2.3 自动运行

# echo "
/usr/local/ lib/ apache/bin/apachectl start" >> /etc/rc.local


2.4 apache启动时可能出现的错误
 
[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, 配置主机域名. 例如:
 
# cat /etc/hosts
127.0.0.1               localhost
192.168.177.130         freebsd6 freebsd6.local
 
# 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.




3. 安装PHP
============
 
步骤:
 
   3.1 安装libxml2-x.x.x.tar.gz
   3.2 安装libiconv-x.x.x.tar.gz

   3.3 安装gd-x.x.x.tar.gz

   3.4 安装php



3.1 安装libxml2

# tar zxvf libxml2-
x.x.x .tar.gz
# cd libxml2-
x.x.x
# ./configure && make && make install
 
[url]http://xmlsoft.org/[/url]


3.2 安装libiconv

# tar zxvf libiconv-
x.x.x .tar.gz
# cd libiconv-
x.x.x
# ./configure && make && make install
 
[url]http://www.gnu.org/software/libiconv/[/url]


3.3 安装gd
 
gd需要以下模块:
 
 . zlib-
x.x.x .tar.gz
 . libpng-
x.x.x .tar.gz


3.3.1 安装zlib

# tar zxvf zlib-
x.x.x .tar.gz
# cd zlib-
x.x.x
# ./configure && make && make install
 
默认情况zlib被安装到/usr/local/include/

[url]http://directory.fsf.org/zlib.html[/url]
[url]http://www.zlib.net/[/url]


3.3.2 安装libpng

# tar zxvf libpng-
x.x.x .tar.gz
# cd libpng-
x.x.x
# ./configure && make && make install
 
默认情况libpng被安装到/usr/local/include/libpng/

[url]http://www.libpng.org/pub/png/libpng.html[/url]


3.3.3 安装gd

# tar zxvf gd-
x.x.x .tar.gz
# cd gd-
x.x.x
# ./configure && make && make install

默认情况gd被安装到/usr/local/include/

 
[url]http://www.boutell.com/gd/[/url]

*注:我遇到过gd_png.c找不到png库文件的情况, 这时要手工把png.h和pngconf.h两个文件拷贝到gd_png.c所在目录就可以了。


3.4 安装PHP

# tar zvxf php-
x.x.x .tar.gz
# cd php-
x.x.x
# ./configure --prefix=/usr/local/
lib/ php --with-mysql=/usr/local/ lib/ mysql --with-apxs2=/usr/local/ lib/ 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/
lib/ php/lib/php.ini


3.5 配置 php.ini

# vi /usr/local/ lib/ php/lib/php.ini
...
default_charset = "gbk"
session.auto_start = 1
max_execution_time = 300  (满足长时间数据计算页面的需要,默认为30)
...



4. 配置httpd.conf
====================


4.1 修改ServerName

ServerName 127.0.0.1:80    (
这个选项影响apache的启动 )
 
 
4.2 支持index.php

找到"DirectoryIndex index.html"
在"index.html"后面加入"index.php"


<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>

 
4.3 支持php

找到<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/ lib/ apache/htdocs"> ... </Directory>, 在下面加入

<Directory 
/usr/local/ lib/ apache/htdocs/new-doc>
    Options Indexes FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
 
 
4.5 增加新的脚本目录

找到<Directory "/usr/local/ lib/ apache/cgi-bin"> ... </Directory>, 在下面加入

<Directory " /usr/local/ lib/ apache/htdocs/new-cgi">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
</Directory>


4.6 增加目录别名(alias)

找到<IfModule alias_module> ... </IfModule>, 在中间区域加入

Alias /new-doc " /usr/local/ lib/ apache/htdocs/new-doc"
 
ScriptAlias /new-cgi "
/usr/local/ lib/ apache/htdocs/new-cgi"

你可能感兴趣的:(apache,mysql,PHP,cgi,FreeBSD)