您的位置:首页 > 理论基础 > 计算机网络

原创-在Debian 5.0下的使用源代码安装LAMP笔记[完整版,带HTTPS]

2009-09-07 21:07 549 查看

原创-在Debian 5.0下的使用源代码安装LAMP笔记[完整版,带HTTPS]

document.body.oncopy = function() {
if (window.clipboardData) {
setTimeout(function() {
var text = clipboardData.getData("text");
if (text && text.length>300) {
text = text + "/r/n/n本文来自CSDN博客,转载请标明出处:" + location.href;
clipboardData.setData("text", text);
}
}, 100);
}
}

function StorePage(){d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(keyit=window.open('<a class="moz-txt-link-freetext" href="http://www.365key.com/storeit.aspx?t='+escape(d.title)+'&u='+escape(d.location.href)+'&c='+escape(t),'keyit','scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes'));keyit.focus()">http://www.365key.com/storeit.aspx?t='+escape(d.title)+'&u='+escape(d.location.href)+'&c='+escape(t),'keyit','scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes'));keyit.focus()</a>;}
作者:何祖彬[RobinHe] Mail:zubin.he@gmail.com

Skype ID : pto_robin QQ : 57623579

始于2009年2月21日 PM

版本号:Debian-LAMP-V2.0-20090907, 2009年2月21日首版 2009年9月7日第一次更新--加入https功能



转载请注明出处,谢谢!

本文中难免有不足、遗漏、错别字和句子不通之处,如发现、或者有更新改变之处,请与我联系以及时修正和完善!

系统环境 :
Debian
GNU/Linux 5.0



使用说明:

绿色加粗字体的绝大部分是输入的命令和系统输出显示的结果。


LAMP即由Linux+Apache+Mysql+PHP组成的一个WEB开发平台,以Linux为
OS,我们这里选择Debian 5.0


因环境需要,我只安装Debian GNU/Linux
5.0的最基本的系统,因此在装完Debian后,为了安装apache,mysql,php以及使用的一些工具等就安装了以下所需要软件:

#apt-get install
vim elinks gcc g++ make libncurses5-dev libpng12-dev libjpeg62-dev
zlib1g-dev libxml2-dev libssl-dev openssl



上述所安装的软件介绍:

vim : vim编辑器完整版

elinks : linux shell下的纯文本浏览器,类似IE、FireFox,命令格式 : elinks www.apache.org" target=_blank>

gcc g++ make : 编译源代码时使用

libncurses5-dev : 安装mysql时需要的一个lib

libpng12-dev libjpeg62-dev
zlib1g-dev libxml2-dev : php扩展的一些lib

libssl-dev : apache ssl扩展的lib

1,安装apache

到官方网站下载apache : [url=http://www.apache.org/]www.apache.org


[url=http://httpd.apache.org/download.cgi]http://httpd.apache.org/download.cgi

apache版本:httpd-2.2.11

server:/#cd /usr/local/src

server:/usr/local/src/# wget
http://apache.freelamp.com/httpd/httpd-2.2.11.tar.gz

server:/usr/local/src/# tar -zxvf httpd-2.2.11.tar.gz


配置apaceh,根据需要将相关文件安装到相关的目录中去。依个人需要而定,请了解以下各参数的作用后再进行下一步:

server:/usr/local/src/lamp/httpd-2.2.11#./configure
--prefix=/usr/local/apache2
--sysconfdir=/home/service/web/config/apache/conf --enable-so
--enable-ssl --enable-rewrite --with-mpm=worker --enable-dav
--enable-maintainer-mode --enable-cgi


server:/usr/local/src/lamp/httpd-2.2.11#make
& make install

server:/usr/local/src/lamp/httpd-2.2.11#cp
/usr/local/apache2/bin/apachectl /etc/init.d/apache2


编辑http.conf文件进行相关文件的配置:

#vi
/home/service/web/config/apache/conf/httpd.conf


根据你自已的需求更改相关参数:

比如:

DocumentRoot "/home/www/html"
#这个目录你先需先创建,否则下面在启动apache过程中会出错.

<Directory "/home/www/html">

User www

Group www


等...

启动apache:

#/etc/init.d/apache2 start

访问测试 :

打开你的IE、FireFox或Elink: http://youserveripaddress/

若有问题,请检查你的安装步骤以及配置文件。

配置https:

首先使用openssl为apache制作ssl证书:

步骤1:生成密钥

命令:

#openssl genrsa 1024 > server.key

说明:这是用128位rsa算法生成密钥,得到server.key文件

步骤2: 生成证书请求

命令:

#openssl req -new -key server.key >
server.csr


说明:这是用步骤1的密钥生成证书请求文件server.csr, 这一步提很多问题,根据你的资料一一输入:

得注意一项:Common Name (eg, YOUR name) []:*.3322.org
这个要跟你的域名后缀相附,否则在客户端请求证书时会提示“服务器名称与证书名称匹配”。

步骤3: 生成证书请求

命令:

#openssl req -x509 -days 365 -key server.key
-in server.csr > server.crt


说明:这是用步骤1,2的的密钥和证书请求生成证书server.crt,-days参数指明证书有效期,单位为天。

把得到的server.key和server.crt文件拷贝到apache的对应目录:

#mkdir /home/service/web/config/apache/conf/certificate

#cp server.key /home/service/web/config/apache/conf/servercertificate

#cp server.csr /home/service/web/config/apache/conf/servercertificate

#cp server.crt /home/service/web/config/apache/conf/servercertificate


编辑apache配置文件,启用https[ssl]扩展功能:

#vi
/home/service/web/config/apache/conf/httpd.conf


找到:

#Include conf/extra/httpd-ssl.conf

把注释去除:

Include conf/extra/httpd-ssl.conf

然后编辑ssl配置文件:

#vi
/home/service/web/config/apache/conf/extra/httpd-ssl.conf


根据自已情况更改以下内容:

1,用ssl启动的虚拟主机:

<VirtualHost _default_:443>

# General setup for the virtual host

DocumentRoot "/home/www/html"

ServerName youdoman.name.org:443

ServerAdmin zubin@itcht.com

ErrorLog "/usr/local/apache2/logs/error_log"

TransferLog "/usr/local/apache2/logs/access_log"



2,指定证书的相关文件:

# Server Certificate:

# Point SSLCertificateFile at a PEM encoded certificate. If

# the certificate is encrypted, then you will be prompted for a

# pass phrase. Note that a kill -HUP will prompt again. Keep

# in mind that if you have both an RSA and a DSA certificate you

# can configure both in parallel (to also allow the use of DSA

# ciphers, etc.)

#SSLCertificateFile "/usr/local/apache2/conf/server.crt"

SSLCertificateFile "/home/service/web/config/apache/conf/extra/certificate/server.crt"


#SSLCertificateFile "/usr/local/apache2/conf/server-dsa.crt"

# Server Private Key:

# If the key is not combined with the certificate, use this

# directive to point at the key file. Keep in mind that if

# you've both a RSA and a DSA private key you can configure

# both in parallel (to also allow the use of DSA ciphers, etc.)

#SSLCertificateKeyFile "/usr/local/apache2/conf/server.key"

SSLCertificateKeyFile "/home/service/web/config/apache/conf/extra/certificate/server.key"

#SSLCertificateKeyFile "/usr/local/apache2/conf/server-dsa.key"

重启apahce:

#/etc/init.d/apache2 restart

在浏览器输入:

https://youdoman.name.org/



就会看到相关信息。

2,安装mysql

到mysql官方下载: www.mysql.com

http://dev.mysql.com/downloads/mysql/5.0.html

http://dev.mysql.com/downloads/mysql/5.0.html#source

mysql版本:mysql-5.0.77

server:/#cd /usr/local/src

server:/usr/local/src/#wget
http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-5.0.77.tar.gz/from/http://mirrors.24-7-solutions.net/pub/mysql/

server:/usr/local/src# tar -zxvf mysql-5.0.77.tar.gz

server:/usr/local/src# cd mysql-5.0.77


请看INSTALL-SOURCE文件,它会教你如何一步一步安装Mysql

server:/usr/local/src/mysql-5.0.77#vi
INSTALL-SOURCE


增加运行mysql的用户mysql和组mysql:

server:/usr/local/src/mysql-5.0.77#groupadd
mysql

server:/usr/local/src/mysql-5.0.77#useradd -g mysql mysql



配置mysql:根据需要将相关文件安装到相关的目录中去。依个人需要而定,请了解以下各参数的作用后再进行下一步:

server:/usr/local/src/mysql-5.0.77#./configure
--prefix=/usr/local/mysql --enable-thread-safe-client
--localstatedir=/home/service/mysql/data/var
--sysconfdir=/home/service/mysql/config/etc

server:/usr/local/src/mysql-5.0.77#make & make install

server:/usr/local/src/mysql-5.0.77#cp support-files/my-medium.cnf
/home/service/mysql/config/etc/my.cnf

server:/usr/local/src/mysql-5.0.77#cd /usr/local/mysql

server:/usr/local/mysql#chown -R mysql .

server:/usr/local/mysql#chgrp -R mysql .

server:/usr/local/mysql#./bin/mysql_install_db --user=mysql

server:/usr/local/mysql#chown -R root .

server:/usr/local/mysql#chown -R mysql /home/service/mysql/data/var

server:/usr/local/mysql#cp share/mysql/mysql.server /etc/init.d/mysqld


启动mysql:

server:/usr/local/mysql#/etc/init/mysqld start

查看mysql是否启动成功:

server:/usr/local/mysql#netstat -tnlp | grep
mysql


如果有看到这一行:

tcp 0 0 0.0.0.0:3306
0.0.0.0:*
LISTEN 1328/mysqld


恭喜你,这说明mysql启动成功.

3,安装PHP

到php官方网站下载 : www.php.net

http://cn.php.net/get/php-5.2.8.tar.gz/from/a/mirror

server:/#cd /usr/local/src

server:/usr/local/src#wget
http://cn.php.net/get/php-5.2.8.tar.gz/from/this/mirror

server:/usr/local/src#cd php-5.2.8


请先看INSTALL文件,它将协助你如何安装PHP

server:/usr/local/src/#vi INSTALL

server:/usr/local/src#cd php-5.2.8


配置php,将php与mysql以及apache关联,根据需要将相关文件安装到相关的目录中去。依个人需要而定,请了解以下各参数的作用后再进行下一
步:

server:/usr/local/src/php-5.2.8#./configure
--with-mysql=/usr/local/mysql --with-apxs2=/usr/local/apache2/bin/apxs
--with-gd --with-zlib --with-gettext --with-zlib-dir --with-jpeg-dir
--enable-mbstring --with-iconv-dir --with-pdo-mysql=/usr/local/mysql
--prefix=/usr/local/php
--with-config-file-path=/home/service/web/config/php/lib

server:/usr/local/src/php-5.2.8# make & make install

server:/usr/local/src/php-5.2.8# cp php.ini-dist
/home/service/web/config/php/php.ini



编辑apache的配置文件,并加入php相关参数:

server:/usr/local/src/php-5.2.8# vi
/home/service/web/config/apache/conf/httpd.conf

在: AddType application/x-compress .Z

AddType application/x-gzip .gz .tgz

下面增加:

AddType application/x-httpd-php .php

以及在:

<IfModule dir_module>

DirectoryIndex index.html

</IfModule>

加入index.php,以便让php的程序成为默认运行的程序:

<IfModule dir_module>

DirectoryIndex index.html index.php

</IfModule>


重启apache,以便让apache载入php模块:

server:/usr/local/src/php-5.2.8#
/etc/init.d/apache2 restart


测试php是否安装成功,是否跟mysql连接成功:


DocumentRoot,我们这里是:/home/www/html下,编辑phpinfo程序,即phpinfo.php,内容为:

<?php

phpinfo();

?>



打开你的IE、FireFox或Elink: http://youserveripaddress/phpinfo.php

如果你看到完整的phpinfo信息时,说明你安装成功了,恭喜,恭喜!呵。

例:

PHP Version 5.2.8
System Linux server 2.6.26-1-686 #1 SMP Sat Jan 10
18:29:31 UTC 2009 i686
Build Date Feb 22 2009 05:08:57
Configure Command './configure'
'--with-mysql=/usr/local/mysql'
'--with-apxs2=/usr/local/apache2/bin/apxs' '--with-gd' '--with-zlib'
'--with-gettext' '--with-zlib-dir' '--with-jpeg-dir'
'--enable-mbstring' '--with-iconv-dir'
'--with-pdo-mysql=/usr/local/mysql' '--prefix=/usr/local/php'
'--with-config-file-path=/home/service/web/config/php/lib'
Server API Apache 2.0 Handler
Virtual Directory Support enabled
Configuration File (php.ini) Path /home/service/web/config/php/lib
Loaded Configuration File (none)
Scan this dir for additional .ini files (none)
......

于2009年2月21日 晚 23:06完成本篇文章。

于2009年9月7日 晚 21:03更新本篇文章:加入https功能。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: