网络安全 频道

服务器apache+mysql+php+ssl之完全安装攻略

<br>好,该试一些确实有用的SQL命令,插入并从数据库中选择数据,现在把几个记录加到新表中。记住这些是简单的书名记录,但是一旦你获得了SQL足够的经验,你可以为一些大的电子商务站点创建确实复杂的数据库。让我们创建2本假想的书的2条记录。第一条记录是我在将来某天写的一本书的名字-“PHP 4 Newbies”,另一本是一个很有用的Linux书,“Red Hat Linux 6 Server”, 由Mohammed J. Kabir所著。

<br>mysql> INSERT INTO books (name) values("PHP 4 Newbies");

Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO books (name) values("Red Hat Linux 6 Server");

Query OK, 1 row affected (0.00 sec)

<br>现在我们可以检查新纪录,发出一条“选择所有”命令

<br>mysql> SELECT * from books;

+----+----------------------------------+

| id | name |

+----+----------------------------------+

| 1 | PHP for Newbies |

| 2 | Red Hat Linux 6 Server |

+----+----------------------------------+

2 rows in set (0.00 sec)

<br>很好,MySQL服务器完全起作用了。我们可以继续加入,但是此时没什么意义。注意到当你向数据库中插入记录时,你怎样不必指定id号,这是因为你创建了启用auto_increment选项的id字段。

<br>让我演示一下如何做一个快速删除。这只是让你知道,记住,你可在MySQL的网站http://www.mysql.com上找到所需的有关mysql命令和服务器的所有信息。

<br>mysql> delete from books where id=1;

Query OK, 1 row affected (0.00 sec)

mysql> select * from books;

+----+-----------------------------------+

| id | name |

+----+-----------------------------------+

| 2 | Red Hat Linux 6 Server |

+----+-----------------------------------+

1 row in set (0.00 sec)

<br>好了,退出MySQL,继续安装。你可在完成所有安装并且一切工作正常后玩MySQL也不迟。

<br>PHP安装(UNIX)

 

现在安装PHP语言。你下载了最新的beta版,但是你可能必须下载非beta版本。记住beta版本需要GNU make。

<br>你仍然假定是root,如果不是,su回到root。

<br>PHP要求你已经预先配置好的Apache,以便它能知道所需的东西在哪儿。在以后你安装Apache服务器时,你将会回到这里。改变到你有源代码的目录。

<br># cd /tmp/DOWNLOAD

# gunzip -c apache_1.3.x.tar.gz | tar xf -

# cd apache_1.3.x

# ./configure

# cd ..

<br>好的,现在你可以开始PHP的安装。提取源代码文件并进入其目录。如果你下载了版本3,在数字和命令上有一个改变,不大的改变。

<br># gunzip -c php-4.0.x.tar.gz | tar xf -

# cd php-4.0.x

<br>如果你正在编译代码,configure将永远是你的朋友。:-) 因此,configure有很多选项。使用configure --help确定你想要增加哪些。我只是需要MySQL和LDAP,并且当然Apache。

<br># ./configure --with-mysql=/usr/local/mysql

--with-xml

--with-apache=../apache_1.3.x

--enable-track-vars

--with-ldap

<br>make并安装二进制代码。

<br># make

# make install

<br>拷贝ini文件到lib目录。

<br># cp php.ini-dist /usr/local/lib/php.ini

<br>你可以编辑PHP文件来设置PHP选项,如你可以通过在你的php.ini文件中插入下列行,增加php的max_execution_time。

<br>max_execution_time = 60;

<br>注意:php3用户将使用php3.ini,而php4用户将使用php.ini文件。

<br>Apache 与 Mod_SSL

 

该配置并安装mod_ssl和Apache了。对此,你将需要有rsaref-2.0文件。在http://ftpsearch.lycos.com/上搜索“rsaref20.tar.Z”。如果你不喜欢Lycos,你可以选择其他搜索引擎来搜索文件。当然只有你在美国才需要这个文件。(管它呢,你也可从别处下载,首先在http://ftpsearch.ntnu.no/查找“rsaref20.tar.Z”,好多啊!。)

<br> 

<br>创建rasref目录,你将在该目录提取文件。注意。这假定你下载了一个临时目录,而你就在此目录。

<br># mkdir rsaref-2.0

# cd rsaref-2.0

# gzip -d -c ../rsaref20.tar.Z | tar xvf -

<br>现在配置并构造OpenSSL库。

<br># cd rsaref-2.0

# cp -rp install/unix local

# cd local

# make

# mv rsaref.a librsaref.a

# cd ../..

<br>安装OpenSSL。记住,你将用它来创建临时证书和CSR文件。--prefix选项指定主安装目录。

<br># cd openssl-0.9.x

# ./config -prefix=/usr/local/ssl

-L`pwd`/../rsaref-2.0/local/ rsaref -fPIC

<br>现在make、测试并安装它。

<br># make

# make test

# make install

# cd ..

<br>我们将配置MOD_SSL模块,然后用Apache配置指定它为一个可装载的模块。

<br># cd mod_ssl-2.5.x-1.3.x

# ./configure

--with-apache=../apache_1.3.x

# cd ..

<br>现在我们可以把更多的Apache模块加到Apache源代码树中。可选的--enable-shared=ssl选项使得mod_ssl构造成为一个DSO“libssl.so”。关于在Apache支持DSO的更多信息,阅读Apache源代码树中的INSTALL和 htdocs/manual/dso.html文档。我强烈建议ISP和软件包装维护者为了最灵活地使用mod_ssl而使用DSO工具,但是注意,DSO不是在所有平台上的Apache都支持。

<br># cd apache_1.3.x

# SSL_BASE=../openssl-0.9.x

RSA_BASE=../rsaref-2.0/local

./configure --enable-module=ssl

--activate-module=src/modules/php4/libphp4.a

--enable-module=php4 --prefix=/usr/local/apache

--enable-shared=ssl

[...你可加入更多的选项...]

<br>生成Apache,然后生成证书,并安装...

<br># make

<br>如果你已正确地完成,你将得到类似于以下的信息:

<br>+-----------------------------------------------------------------------+

| Before you install the package you now should prepare the SSL |

| certificate system by running the "make certificate" command. |

| For different situations the following variants are provided: |

| |

| % make certificate TYPE=dummy (dummy self-signed Snake Oil cert) |

| % make certificate TYPE=test (test cert signed by Snake Oil CA) |

| % make certificate TYPE=custom (custom cert signed by own CA) |

| % make certificate TYPE=existing (existing cert) |

| CRT=/path/to/your.crt [KEY=/path/to/your.key] |

| |

| Use TYPE=dummy when you’re a vendor package maintainer, |

| the TYPE=test when you’re an admin but want to do tests only, |

| the TYPE=custom when you’re an admin willing to run a real server |

| and TYPE=existing when you’re an admin who upgrades a server. |

| (The default is TYPE=test) |

| |

| Additionally add ALGO=RSA (default) or ALGO=DSA to select |

| the signature algorithm used for the generated certificate. |

| |

| Use "make certificate VIEW=1" to display the generated data. |

| |

| Thanks for using Apache & mod_ssl. Ralf S. Engelschall |

| rse@engelschall.com |

| www.engelschall.com |

+-----------------------------------------------------------------------+

 

现在你可以创建一个定制的证书。该选项将提示输入你的地址、公司、和其他一些东西。关于证书,请参阅本文的结尾。

<br># make certificate TYPE=custom

<br>现在安装Apache...

<br># make install

<br>如果一切正常,你应该看到类似于以下的信息:

 

+----------------------------------------------------------------------------------+

| You now have successfully built and installed the |

| Apache 1.3 HTTP server. To verify that Apache actually |

| works correctly you now should first check the |

| (initially created or preserved) configuration files |

| |

| /usr/local/apache/conf/httpd.conf |

| and then you should be able to immediately fire up |

| Apache the first time by running: |

| |

| /usr/local/apache/bin/apachectl start |

| Or when you want to run it with SSL enabled use: |

| |

| /usr/local/apache/bin/apachectl startssl |

| Thanks for using Apache. The Apache Group |

| http://www.apache.org / |

+----------------------------------------------------------------------------------+

 

现在验证Apache和PHP是否正在工作。然而,我们需要编辑srm.conf和httpd.conf保证我们把PHP类型加到了配置中。查看httpd.conf并去掉下列行的注释。如果你精确地遵循了本文的指令,你的httpd.conf文件将位于/usr/local/apache/conf目录。文件有一行针对php4的addtype加了注释,现在就去掉注释。httpd.conf 文件--片断

<br>>

> # And for PHP 4.x, use:

> #

---> AddType application/x-httpd-php .php

---> AddType application/x-httpd-php-source .phps

>

>

 

现在我们准备启动Apache服务器看它是否在工作。首先我们将启动不支持SSL的服务器看它是否启动了。我们将检查对PHP的支持,然后我们将停止服务器并且启动启用了SSL支持的服务器并检查我们是否一切正常。configtest 将检查所有配置是否正确设置。

<br># cd /usr/local/apache/bin

# ./apachectl configtest

Syntax OK

# ./apachectl start

./apachectl start: httpd started

 

测试我们的工作

Apache 正在工作吗?

<br>如果它工作正常,当你用Netscape连接服务器时,你将看见一幅类似于这幅屏幕捕获的屏幕。这是基本上 是Apache缺省安装的页面。

0
相关文章