2008-05-02

Freebsd下使用源码安装Apache2+Mysql5+PHP5(1)

Posted in PHP, Apache, FreeBSD/Unix服务器 at 17:14 Author:仲远

标签:

虽然Freebsd下提供Ports安装软件的方式,但是由于Unix下常常出现的版本依赖问题,有可能导致安装最新版的软件时出错。不过还好,Freebsd还支持另一种安装软件的方式,那就是源码安装。下面就介绍一种使用源码编译安装Apache2+Mysql5+PHP5以及PHP扩展的方式。

Download Source


Get the latest source for:

  1. Mysql
  2. Apache
  3. PHP

For each application, download the *.tar.gz source file.

First, I’ll make a /src directory in my home. Then I’ll use the websites above to find the URL for the latest source file and download the tar.gz directly on the web server with wget:
wget http://us2.php.net/get/php-5.1.2.tar.gz/from/this/mirror

# as web:
mkdir ~/src ~/src/tars
cd ~/src

# download source
wget [mysql source]
wget [php source]
wget [apache source]

# uncompress source
tar xvfz mysql*
tar xvfz php*
tar xvfz httpd*

# move compressed source to ~/src/tars
# in case we need them later
mv *.gz tars

Now you’re home directory should look like this:

/home/web
/src/
/httpd…/
/mysql…/
/php…/
/tars/
/httpd…tar.gz
/mysql…tar.gz
/php…tar.gz

MySQL


# as web:
cd ~/src/mysql*

./configure –prefix=/usr/local/mysql \
–without-debug \
–with-charset=gb2312 \
–with-extra-charsets=all \
–enable-local-infile \
–enable-assembler \
–enable-thread-safe-client

make

# become root
su
make install
./scripts/mysql_install_db
/usr/local/mysql/bin/mysqld_safe –user=root &

# Create the MySQL start up script
vi /usr/local/etc/rc.d/mysql.sh

# add the following to your new, blank file
echo -n “Starting MySQL Server”;
/usr/local/mysql/bin/mysqld_safe –user=root &

# write/quit vi

chmod 700 /usr/local/etc/rc.d/mysql.sh
# exit out of root

Now load MySQL and setup the root password and the mysql account. You will still have to set up entries into the db table at a later time to allow access to databases for the mysql user.

Replace ROOT-PWD with a password that you want to use for MySQL’s root user.

/usr/local/mysql/bin/mysql -u root

mysql> UPDATE mysql.user
SET password = PASSWORD(’ROOT-PWD’)
WHERE User=’root’;

mysql> UPDATE mysql.user
SET user = ‘mysql’
WHERE User=”;

mysql> FLUSH PRIVILEGES;
mysql> exit

Create a user options file for root. This file will contain root’s mysql password so he can auto log in.

su
vi ~/.my.cnf

Enter the following text into the .my.cnf file.
Change “ROOT-PWD” to the password you used for MySQL’s root user.

# Add the following
# Example mysql config file.
# You can copy this to one of:
# /usr/local/mysql/etc/my.cnf to set global options,
# mysql-data-dir/my.cnf to set server-specific options (in this
# installation this directory is /usr/local/mysql/var) or

# ~/.my.cnf to set user-specific options.
#
# One can use all long options that the program supports.
# Run the program with –help to get a list of available options

# This will be passed to all mysql clients
[client]
password = “ROOT-PWD”

#port = 3306
#socket = /tmp/mysql.sock
#

# Here is entries for some specific programs
# The following values assume you have at least 32M ram
#
# The MySQL server
[mysqld]
#port = 3306

#socket = /tmp/mysql.sock
#skip-locking
#set-variable = key_buffer=16M
#set-variable = max_allowed_packet=1M

#set-variable = thread_stack=128K
set-variable = max_connections=200
set-variable = ft_min_word_len=3

# Start logging
#log
#
#[mysqldump]
#quick
#set-variable = max_allowed_packet=16M
#

#[mysql]
#no-auto-rehash
#
[isamchk]
#set-variable = key_buffer=16M
set-variable = ft_min_word_len=3

[myisamchk]
set-variable = ft_min_word_len=3

[mysqld_safe]
time_zone = EDT

Chmod the file

chmod 700 /root/.my.cnf

PHP DEPENDENCIES


# as root, run ‘make install’ in the following directories
cd /usr/ports/security/libmcrypt
make install

cd /usr/ports/security/mcrypt
make install

# make install in all the following:
cd /usr/ports/ftp/curl
cd /usr/ports/databases/freetds
cd /usr/ports/textproc/libxml2
cd /usr/ports/textproc/aspell
cd /usr/ports/textproc/libxdiff

APACHE 2.X / PHP 5.X


More PHP/Apache2 install infoApache 2.x
Download apache - http://httpd.apache.org - and install with ’shared-object’ (so) support

# as web:
cd ~/src/httpd-2*

./configure –prefix=/usr/local/apache \
–with-mpm=worker \
–enable-so \
–enable-cgi \
–enable-info \
–enable-rewrite \
–enable-speling \
–enable-usertrack \
–enable-deflate \
–enable-ssl \
–enable-mime-magic \
–enable-module=expires \
–enable-module=proxy

make

# as root:
make install

PHP 5.x

# as web:
cd ~/src/php*

./configure –with-apxs2=/usr/local/apache/bin/apxs \
–with-mysql=/usr/local/mysql \
–enable-calendar \
–enable-trans-sid \
–enable-mbstring \
–with-curl=/usr/local \
–with-sybase=/usr/local/freetds \
–enable-ftp \
–with-mcrypt \
–with-pspell \
–with-xdiff \
–with-zlib

make

# For new installs, create blank references for the config owned by ‘web’
# Become root
touch /usr/local/lib/php.ini
touch /usr/local/lib/php.ini.bak
chown web /usr/local/lib/php.ini*

# as root:
make install

# copy the config file
cp php.ini-dist /usr/local/lib/php.ini
chown web /usr/local/lib/php.ini*

Now PHP and Apache are installed. We still need to edit apache’s config file to parse PHP.

Edit httpd.conf

vi /usr/local/apache/conf/httpd.conf

# look for “AddType”; add the following three lines

# PHP
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

# Remove the default deny access configuration by
# searching for and
# commenting out “Deny from all”

Start Apache

apachectl start

# Create the Apache start up script
vi /usr/local/etc/rc.d/apache.sh

# add the following lines to your new, blank file
echo -n “Starting Apache Web Server”;
/usr/local/apache/bin/apachectl start &

# write/quit vi

chmod 700 /usr/local/etc/rc.d/apache.sh

本文可以自由转载,转载时请保留全文并注明出处:
转载自仲子说 [ http://www.wangzhongyuan.com/ ]
原文链接:

Leave a Comment

*
To prove you're a person (not a spam script), type the security text shown in the picture. Click here to regenerate some new text.
Click to hear an audio file of the anti-spam word