- 论坛徽章:
- 0
|
Step 1. Obtaining the Source Packages
I always recommend that you compile via source package (tarballs). The reason
being is that you have control over what goes into your installation. It's
more of the "Advanced" installation where you get to select installation
options. Here's some addresses of the sites. I will not post specific files
here because they may be updated by the
time
you read this tutorial:
Make a directory on your linux box called something like "/usr/local/src/webserver"
Download these files to here. You may do this via SSH and CD to that directory
and type "wget the_url_here" for the respective files.
Apache Web Server - http://www.apache.org/dyn/closer.cgi/httpd/
Look for the [color="#009900"]Apache 1.3.2x series.
At the
time
of writing this tutorial, Apache 2 and PHP are not working properly
unless you do some massive testing with CVS code, but that's not recommened!
PHP - http://www.php.net/downloads.php
Look for the [color="#009900"]4.2.x series under
Complete Source Code.
Step 2. Unpacking the Source Packages
Go to the source directory and type:
tar zxvf apache_1.xxxxx.tar.gz
tar zxvf php_4.xxx.tar.gz
Step 3. Create an Install Script for Apache
You will now have two new directories. Let's start by
creating a simple script that you can edit. For this, I use a program in linux
called "Pico". It's much easier to use than VI but it's up to you.
Type: pico
You'll be brought up into an editor program.
Here we're going to type in exactly what we would type
in the command line, except make it editable so it's easier to manage when
we want to add or remove different configure options. Here's the script I
use for Apache:
cd [color="#ff0000"]apache_1.3.xx (Make sure this matches the proper directory)
./configure \
--prefix=[color="#ff0000"]/www \ (This is where you want to install Apache Server to)
--enable-module=so \
--enable-module=rewrite \
--enable-shared=rewrite \
--enable-module=setenvif \
--enable-shared=setenvif \
--enable-module=mime \
--enable-shared=mime \
--enable-module=mime_magic \
--enable-shared=mime_magic \
--enable-module=speling \
--enable-shared=speling \
--enable-module=dir \
--enable-shared=dir \
--enable-module=auth \
--enable-shared=auth \
--enable-module=access \
--enable-shared=access \
--enable-module=alias \
--enable-shared=alias \
--enable-module=status \
--enable-shared=status \
--enable-module=userdir \
--enable-shared=userdir \
--enable-module=vhost_alias \
--enable-shared=vhost_alias \
--enable-module=env \
--enable-shared=env \
--enable-module=log_referer \
--enable-shared=log_referer \
--enable-module=log_config \
--enable-shared=log_config \
--enable-module=log_agent \
--enable-shared=log_agent \
--enable-module=headers \
--enable-shared=headers
make
make install
[color="red"]
Note: The \ behind every line is important except for the last line in that option. Do not put one for the last line!
Note2: Do not put any of my comments in () your install script!
Decide which modules you need here at the
apache
website
http://httpd.apache.org/docs/mod/index.html
And edit this setup accordingly.
Save this by pressing CTRL X and
you'll be prompted to enter a
file
name. Let's call this [color="#ff0000"]"apache_install".
[color="#000000"]Step 4. Create
an Install Script for PHP
This script will serve the same purpose as creating
an install script for Apache. It saves you
time
when you need to recompile
your server. Here's the script I use: [color="#ff0000"] cd php-4.2.xx
(Check this path with your specific system, wherever you upacked the tarball)
[color="#000000"]
./configure \
--with-mysql \
--with-apxs=/www/bin/apxs \ [color="#ff0000"](This is where you installed Apache to)
--enable-trans-sid \
--enable-ftp
make
install [color="#000000"]
Please check with PHP's website to see what configure
options you need here:
http://www.php.net/manual/en/install.configure.php
After you have determined your installation options, press Ctrl X
[color="#000000"]
[color="#000000"] to get out of pico and save this as "php_install".
Now type:
chmod +x apache_install
chmod
+x php_install
Step 5. Installing Apache and PHP
Now that the scripts are built, we can install them.
For Apache type:
./apache_install
You'll see a bunch of things happening on your screen, it's ok. It's going
to configure the source tree then make the installation files and install
them.
For PHP type:
./php_install
Just like the
apache
script, you'll see a bunch of things happening.
It's ok. Let PHP do it's thing and keep your eyes open for any errors.
Now, cd into your php_4.xxx directory and type:
cp php.ini-dist /usr/local/lib/php.ini
This copies the php.ini to it's proper place.
Step 6. Configuring Apache
Here's the part where we are going to have to edit the Apache Web Server's
configuration
file
because by default it does not support php. That's ok,
but we'll finish up a few things here.
Type:
pico /www/conf/httpd.conf
You'll once again be in the PICO editor and you'll see your Apache configuration
file. Don't get to carried away right now because we want to ensure that things
are working properly before going through alot of configuration, only to find
out we'll have to recompile again to fix errors.
Scroll down to a section where you see some items like this:
LoadModule vhost_alias_module libexec/mod_vhost_alias.so
LoadModule env_module libexec/mod_env.so
LoadModule config_log_module libexec/mod_log_config.so
LoadModule agent_log_module libexec/mod_log_agent.so
LoadModule referer_log_module libexec/mod_log_referer.so
LoadModule mime_module libexec/mod_mime.so
LoadModule autoindex_module libexec/mod_autoindex.so
LoadModule dir_module libexec/mod_dir.so
LoadModule action_module libexec/mod_actions.so
LoadModule speling_module libexec/mod_speling.so
LoadModule userdir_module libexec/mod_userdir.so
LoadModule alias_module libexec/mod_alias.so
LoadModule rewrite_module libexec/mod_rewrite.so
LoadModule access_module libexec/mod_access.so
LoadModule auth_module libexec/mod_auth.so
LoadModule headers_module libexec/mod_headers.so
LoadModule setenvif_module libexec/mod_setenvif.so
[color="#ff0000"] LoadModule php4_module libexec/libphp4.so[color="#ff0000"]
The red line is the one you want to ensure is properly added. It may be in
a different order than this, but if your php installed properly, you'll see
this line here. If it is not there, you'll probably want to go back and check
to see if PHP configured and installed properly.
Next, we want to look at this section. For some reason, especially on SSL
installations, this line is never added but it is required for PHP to run
properly. This is very important to do. This was not in the PHP installation
directions for Apache. If you are having problems with being prompted to download
your PHP scripts in the web browser, this is a 99% probabilty of why:
ClearModuleList
AddModule mod_vhost_alias.c
AddModule mod_env.c
AddModule mod_log_config.c
AddModule mod_log_agent.c
AddModule mod_log_referer.c
AddModule mod_mime.c
AddModule mod_negotiation.c
AddModule mod_status.c
AddModule mod_include.c
AddModule mod_autoindex.c
AddModule mod_dir.c
AddModule mod_cgi.c
AddModule mod_asis.c
AddModule mod_imap.c
AddModule mod_actions.c
AddModule mod_speling.c
AddModule mod_userdir.c
AddModule mod_alias.c
AddModule mod_rewrite.c
AddModule mod_access.c
AddModule mod_auth.c
AddModule mod_headers.c
AddModule mod_so.c
AddModule mod_setenvif.c
[color="#ff0000"]AddModule mod_php4.c
Once again, the red line is the really important one here.
Next, we need to add a handler to Apache to recognize what to do with the
PHP scripts. While still in your PICO editor, Add this somewhere around the
line that says:
AddType application/x-tar .tgz
And add these two lines below it:
[color="#ff0000"]AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
Last, we are going to setup some directory default documents. Look for the
line that says:
DirectoryIndex index.html
Change it to:
DirectoryIndex index.html[color="#ff0000"] index.php default.php
index.htm
This allows any directory with these files to load them by default. Trust
me, you need this.
Press Ctrl X again to exit your PICO editor and hit Y to save the
current
document.
Step 7. Setup a Test PHP Script
This is another great way to test your PHP to see if it's
working. CD to /www/htdocs and type "pico". Once again, in pico
type this:
PHP Example:
(!)
php phpinfo(); ?>
Now, press CTRL X and then save this as "info.php"
Step 8. Start the Apache Web Server
Let's do two things here. One, we'll check if your configuration
is right. Type:
/www/bin/apachectl configtest
Press enter and you should see a [color="#ff0000"]"SYNTAX
OK". If it's ok, let's type this:
/www/bin/apachectl start
Now, let's go to your web browser and type in:[color="#0000ff"]
http://localhost/info.php
You should see an nice formatted page that the PHP engine
generated telling you all of your PHP information. If this is correct, you
can pat yourself on the back and have a coke.
If things did not go well for you, I recommend you go
back and check your configure options in the original scripts we created.
-- Notes --
With this installation, your default Document
Root is /www/htdocs
To restart
apache
type: /www/bin/apachectl
restart
To stop
apache
type: /www/bin/apachectl stop
Stay tuned for more tutorials about how to setup your
own
Virtual
Hosts and DNS server to run off of your home connection.
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/44757/showart_378496.html |
|