您的位置:首页 > 运维架构 > Apache

Apache服务器的编译安装和 LAMP 环境的构建

2010-04-30 16:54 489 查看

Apache服务器的编译安装和 LAMP 环境的构建

[b][b][b][b]以前在做实验的过程中总结和写的一些教程的一些资料,一直没时间发布到博客上面,五一到了,终于有点时间发布啦!关于Linux上面还会有RHCE系列的学习笔记发表[/b][/b][/b][/b]

制作人:wqmsl

一、编译安装过程:

1、制作光盘并挂载光盘,然后将包复制到/root目录下:

[root@cisco ~]# cd /root

[root@cisco ~]# ls

abc login.txt

anaconda-ks.cfg mysql-standard-4.1.7-pc-linux-i686.tar.gz

httpd-2.0.52.tar.gz php-4.3.9.tar.gz

install.log phpBB-2.0.21.tar.gz

install.log.syslog

2、解压缩

[root@cisco ~]# tar -zxvf httpd-2.0.52.tar.gz -C /usr/local/src

[root@cisco ~]# cd /usr/local/src/

[root@cisco src]# ls

httpd-2.0.52

3、编译前准备:

[root@cisco src]# cd httpd-2.0.52/

[root@cisco httpd-2.0.52]# ls

ABOUT_APACHE CHANGES InstallBin.dsp os

acconfig.h config.layout LAYOUT README

acinclude.m4 configure libhttpd.dsp README.platforms

Apache.dsp configure.in LICENSE server

Apache.dsw docs Makefile.in srclib

apachenw.mcp.zip emacs-style Makefile.win support

build httpd.spec modules test

BuildBin.dsp include NOTICE VERSIONING

buildconf INSTALL NWGNUmakefile

[root@cisco httpd-2.0.52]# ./configure --prefix=/usr/local/apache2 \

¾ --enable-so --enable-rewrite

4、编译:

[root@cisco httpd-2.0.52]# make

5、安装:

[root@cisco httpd-2.0.52]# make install

二、系统个人主页的演示:

1、创建用户

2、在用户的家目录下创建 public_html 目录,然后创建 index.html 主页内容

3、启动 apache 服务器

[root@cisco public_html]# /usr/local/apache2/bin/apachectl start

4、然后 windows主机访问,用浏览器,发现报权限的错误

http://192.168.20.1/~cisco/

5、更改用户家目录的权限,给其他用户执行权限即可

批注 [l1]: 规定安装目录

批注 [l2]: 允许动态模块加载

批注 [l3]: 可以使用重写功能

www.wqmsl.cn三、虚拟主机的演示:

1、修改主配置文件:

[root@cisco sina]# vi /usr/local/apache2/conf/httpd.conf

NameVirtualHost 192.168.20.1

<VirtualHost 192.168.20.1>

servername www.baidu.com

documentroot /baidu

</virtualhost>

<virtualhost 192.168.20.1>

servername www.sina.com

documentroot /sina

</virtualhost>

2、创建目录下的首页文件/baidu/index.html /sina/index.html

3、用 windows主机访问即可,没有 dns 可以用 hosts 文件来测试

四、LAMP 环境的搭建

1、先有 Linux 操作系统

2、搭建 apache 服务器

3、搭建 mysql 数据库:

创建 mysql 用户和用户组

[root@cisco sina]# groupadd -g 200 mysql

[root@cisco sina]# useradd -u 200 -g mysql -d /usr/local/mysql/data -M mysql

[root@cisco sina]# id mysql

uid=200(mysql) gid=200(mysql) groups=200(mysql)

解压缩 mysql 数据库文件

[root@cisco ~]# tar zxvf mysql-standard-4.1.7-pc-linux-i686.tar.gz -C /usr/local/

[root@cisco ~]# cd /usr/local/

[root@cisco local]# ls

apache2 etc include libexec sbin src

bin games lib mysql-standard-4.1.7-pc-linux-i686 share

[root@cisco local]# ln -s mysql-standard-4.1.7-pc-linux-i686 mysql

[root@cisco local]# cd mysql

[root@cisco mysql]# ls

bin docs lib scripts tests

configure EXCEPTIONS-CLIENT man share

COPYING include mysql-test sql-bench

data INSTALL-BINARY README support-files

建立用到的库文件并更改权限

[root@cisco mysql]# mkdir /var/lib/mysql

[root@cisco local]# chown -R mysql:mysql /var/lib/mysql/

[root@cisco local]# chown -R mysql:mysql /usr/local/mysql-standard-4.1.7-pc-linux-i686/

创建 mysql 数据库的配置文件

[root@cisco lib]# cd /usr/local/mysql

[root@cisco mysql]# cp support-files/my-medium.cnf /etc/my.cnf

批注 [l4]: 启动一个虚拟主机

批注 [l5]: 添加域名

批注 [l6]: 文件根目录

批注 [l7]: 组ID必须是200

批注 [l8]: 用户ID必须是200

批注 [l9]: 家目录必须是这个

批注 [l10]: 不按默认安装

批注 [l11]: 解压的目录必须

是这个

批注 [l12]: 目的是创建

mysql的家目录

批注 [l13]: 可以看到家目录

已经创建

批注 [l14]: 配置文件目录 初始化数据库服务器:

[root@cisco mysql]# cd /usr/local/mysql

[root@cisco mysql]# ls

bin docs lib scripts tests

configure EXCEPTIONS-CLIENT man share

COPYING include mysql-test sql-bench

data INSTALL-BINARY README support-files

[root@cisco mysql]# ./scripts/mysql_install_db

更改初始化数据库产生的家目录文件

[root@cisco mysql]# cd /usr/local/mysql/data/

[root@cisco data]# ll

total 116

-rw-rw---- 1 root root 8835 Jun 24 11:17 cisco-bin.000001

-rw-rw---- 1 root root 69239 Jun 24 11:17 cisco-bin.000002

-rw-rw---- 1 root root 38 Jun 24 11:17 cisco-bin.index

drwxr-x--- 2 mysql mysql 4096 Jun 24 11:17 mysql

drwxr-x--- 2 mysql mysql 4096 Oct 24 2004 test

[root@cisco data]# chown -R mysql:mysql /usr/local/mysql/data/

[root@cisco data]# ll

total 116

-rw-rw---- 1 mysql mysql 8835 Jun 24 11:17 cisco-bin.000001

-rw-rw---- 1 mysql mysql 69239 Jun 24 11:17 cisco-bin.000002

-rw-rw---- 1 mysql mysql 38 Jun 24 11:17 cisco-bin.index

drwxr-x--- 2 mysql mysql 4096 Jun 24 11:17 mysql

drwxr-x--- 2 mysql mysql 4096 Oct 24 2004 test

启动 mysql 数据库

[root@cisco data]# /usr/local/mysql/bin/safe_mysqld --user=mysql &

[1] 322

[root@cisco data]# Starting mysqld daemon with databases from /usr/local/mysql/data

给数据库管理员设定密码,并登陆数据库,创建一个新数据库

[root@cisco data]# /usr/local/mysql/bin/mysqladmin -u root password '123'

[root@cisco data]# /usr/local/mysql/bin/mysql -u root -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 2 to server version: 4.1.7-standard-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show databases;

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

| Database |

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

| mysql |

批注 [l15]: 初始化名令

批注 [l16]: 就是这三个文件| test |

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

2 rows in set (0.00 sec)

mysql> create database phpbb;

Query OK, 1 row affected (0.00 sec)

mysql> show databases;

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

| Database |

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

| mysql |

| phpbb |

| test |

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

3 rows in set (0.00 sec)

mysql> exit

4、搭建 php 环境

[root@cisco php-4.3.9]# tar zxvf php-4.3.9.tar.gz -C /usr/local/src

[root@cisco php-4.3.9]# cd /usr/local/src

[root@cisco php-4.3.9]# ./configure --prefix=/usr/local/php4 \

> --with-apxs2=/usr/local/apache2/bin/apxs \

> --with-mysql=/usr/local/mysql \

> --with-config-file-path=/usr/local/php4

编译准备过程中会报错,缺少 lex命令,

configure: error: cannot find output from lex; giving up

安装 lex 命令

[root@cisco RPMS]# rpm -ivh flex-2.5.4a-33.i386.rpm

warning: flex-2.5.4a-33.i386.rpm: V3 DSA signature: NOKEY, key ID db42a60e

Preparing... ########################################### [100%]

1:flex ########################################### [100%]

又会报错:

configure: error: Try adding --with-zlib-dir=<DIR>. Please check config.log for more

information.

安装 zlib库

[root@cisco RPMS]# rpm -ivh zlib-devel-1.2.1.2-1.i386.rpm

warning: zlib-devel-1.2.1.2-1.i386.rpm: V3 DSA signature: NOKEY, key ID db42a60e

Preparing... ########################################### [100%]

1:zlib-devel ########################################### [100%]

重新执行命令,并编译和安装

创建 PHP配置文件:

[root@cisco php-4.3.9]# cp php.ini-dist /usr/local/php4/php.ini

批注 [l17]: 作为论坛演示的

数据库使用

批注 [l18]: 指定安装目录

批注 [l19]: 指定php 为

apache服务器提供的模块的

安装位置

批注 [l20]: 设置 mysql服务

器程序的安装位置

批注 [l21]: 设置php 程序的

配置文件所在的位置 5、修改 apache 的配置文件并重新启动:

[root@cisco php-4.3.9]# vi /usr/local/apache2/conf/httpd.conf

LoadModule php4_module modules/libphp4.so

AddType application/x-httpd-php .php

DirectoryIndex index.html index.html.var index.php

[root@cisco php-4.3.9]# /usr/local/apache2/bin/apachectl restart

httpd: Could not determine the server's fully qualified domain name, using 192.168.20.1 for

ServerName

6、创建测试文件:

[root@cisco php-4.3.9]# vi /usr/local/apache2/htdocs/test.php

<?php

phpinfo();

?>

7、搭建论坛

~[root@cisco ~]# tar zxvf phpBB-2.0.21.tar.gz -C /usr/local/apache2/htdocs/

[root@cisco ~]# cd /usr/local/apache2/htdocs/

[root@cisco htdocs]# ls

apache_pb2_ani.gif index.html.et index.html.pt-br

apache_pb2.gif index.html.fr index.html.ru.cp-1251

apache_pb2.png index.html.he.iso8859-8 index.html.ru.cp866

apache_pb.gif index.html.hr.iso8859-2 index.html.ru.iso-ru

apache_pb.png index.html.it index.html.ru.koi8-r

index.html.ca index.html.ja.iso2022-jp index.html.ru.utf8

index.html.cz.iso8859-2 index.html.ko.euc-kr index.html.sv

index.html.de index.html.lb.utf8 index.html.var

index.html.dk index.html.nl index.html.zh-cn.gb2312

index.html.ee index.html.nn index.html.zh-tw.big5

index.html.el index.html.no phpBB2

index.html.en index.html.po.iso8859-2 test.php

index.html.es index.html.pt

[root@cisco htdocs]# chown -R nobody:nobody phpBB2/

进入图形界面安装,安装完成后要删除一些文件

[root@cisco phpBB2]# rm -rf install/ contrib/

这样就可以使用了

http://192.168.20.1/phpBB2
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐