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



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:



# as web:
cd ~/src/mysql*

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


# become root
make install
/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
WHERE User=’root’;

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

mysql> exit

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

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
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
#port = 3306

#socket = /tmp/mysql.sock
#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
#set-variable = max_allowed_packet=16M

#set-variable = key_buffer=16M
set-variable = ft_min_word_len=3

set-variable = ft_min_word_len=3

time_zone = EDT

Chmod the file

chmod 700 /root/.my.cnf


# 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


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 \


# 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 \


# 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

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