1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > LAMP基础环境的搭建 即Linux Apache MySQL PHP环境

LAMP基础环境的搭建 即Linux Apache MySQL PHP环境

时间:2018-11-25 04:35:12

相关推荐

LAMP基础环境的搭建 即Linux Apache MySQL PHP环境

LAMP基础环境的搭建,即Linux、Apache、MySQL、PHP环境

测试环境:

主机:windows server R2 64位

虚拟机:VMware Workstation 11.0.0

linux版本:CentOS release 5.5 (Final)

目标:搭建LAMP基础环境。

参考内容:

centOS Linux下用yum安装mysql

/database/05/208114.html

linux下查看mysql、apache是否安装,并卸载

/kb/shownews765.html

APACHE配置文件中文详解

/bukebushuo/articles/229103.html

Linux下安装mysql-5.6.4 的图文教程

/article/39190.htm

#开始准备安装

Last login: Thu Sep 10 16:45:32 from 192.168.3.12

[root@localhost ~]# ls

anaconda-ks.cfg Desktop install.log install.log.syslog

#mysql 没有安装

[root@localhost ~]# service mysqld start

mysqld: unrecognized service

#Apache默认已安装

[root@localhost ~]# rpm -q httpd

httpd-2.2.3-43.el5.centos

#Apache版本

[root@localhost ~]# httpd -v

Server version: Apache/2.2.3

Server built: Apr 4 17:19:54

[root@localhost ~]# apachectl -v

Server version: Apache/2.2.3

Server built: Apr 4 17:19:54

#Apache安装文件位置

[root@localhost ~]# whereis httpd

httpd: /usr/sbin/httpd.event /usr/sbin/httpd.worker /usr/sbin/httpd /etc/httpd

/usr/lib/httpd /usr/share/man/man8/httpd.8.gz

#Apache运行文件目录位置

[root@localhost ~]# which httpd

/usr/sbin/httpd

#查询当前linux版本

[root@localhost ~]# lsb_release -a

LSB Version: :core-3.1-ia32:core-3.1-noarch:graphics-3.1-ia32:graphics-3.1-noarch

Distributor ID: CentOS

Description: CentOS release 5.5 (Final)

Release: 5.5

Codename: Final

#yum 安装 Mysql

[root@localhost ~]# yum -y install mysql-server

Loaded plugins: fastestmirror

Loading mirror speeds from cached hostfile

* addons:

* base:

* extras:

* updates:

Setting up Install Process

Resolving Dependencies

--> Running transaction check

---> Package mysql-server.i386 0:5.0.95-5.el5_9 set to be updated

--> Processing Dependency: mysql = 5.0.95-5.el5_9 for package: mysql-server

--> Processing Dependency: perl-DBD-MySQL for package: mysql-server

--> Processing Dependency: perl(DBI) for package: mysql-server

--> Processing Dependency: libmysqlclient.so.15(libmysqlclient_15) for package: mysql-server

--> Processing Dependency: perl-DBI for package: mysql-server

--> Processing Dependency: libmysqlclient_r.so.15(libmysqlclient_15) for package: mysql-

server

--> Processing Dependency: libmysqlclient.so.15 for package: mysql-server

--> Processing Dependency: libmysqlclient_r.so.15 for package: mysql-server

--> Running transaction check

---> Package mysql.i386 0:5.0.95-5.el5_9 set to be updated

---> Package perl-DBD-MySQL.i386 0:3.0007-2.el5 set to be updated

---> Package perl-DBI.i386 0:1.52-2.el5 set to be updated

--> Finished Dependency Resolution

Dependencies Resolved

================================================================================

Package ArchVersion Repository Size

================================================================================

Installing:

mysql-serveri3865.0.95-5.el5_9base9.8 M

Installing for dependencies:

mysql i3865.0.95-5.el5_9base4.9 M

perl-DBD-MySQLi3863.0007-2.el5base148 k

perl-DBI i3861.52-2.el5 base600 k

Transaction Summary

================================================================================

Install 4 Package(s)

Upgrade 0 Package(s)

Total download size: 15 M

Downloading Packages:

(1/4): perl-DBD-MySQL-3.0007-2.el5.i386.rpm | 148 kB 00:00

(2/4): perl-DBI-1.52-2.el5.i386.rpm | 600 kB 00:04

(3/4): mysql-5.0.95-5.el5_9.i386.rpm | 4.9 MB 01:18

(4/4): mysql-server-5.0.95-5.el5_9.i386.rpm | 9.8 MB 02:20

--------------------------------------------------------------------------------

Total 70 kB/s | 15 MB 03:45

warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID e8562897

base/gpgkey | 1.5 kB 00:00

Importing GPG key 0xE8562897 "CentOS-5 Key (CentOS 5 Official Signing Key) <centos-5-

key@>" from /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

Running rpm_check_debug

Running Transaction Test

Finished Transaction Test

Transaction Test Succeeded

Running Transaction

Installing : perl-DBI1/4

Installing : mysql2/4

Installing : perl-DBD-MySQL 3/4

Installing : mysql-server 4/4

Installed:

mysql-server.i386 0:5.0.95-5.el5_9

Dependency Installed:

mysql.i386 0:5.0.95-5.el5_9perl-DBD-MySQL.i386 0:3.0007-2.el5

perl-DBI.i386 0:1.52-2.el5

Complete!

#yum 安装 php-mysql

[root@localhost ~]# yum -y install php-mysql

Loaded plugins: fastestmirror

Loading mirror speeds from cached hostfile

* addons:

* base:

* extras:

* updates:

Setting up Install Process

Resolving Dependencies

--> Running transaction check

---> Package php-mysql.i386 0:5.1.6-45.el5_11 set to be updated

--> Processing Dependency: php-common = 5.1.6-45.el5_11 for package: php-mysql

--> Processing Dependency: php-pdo for package: php-mysql

--> Running transaction check

---> Package php-common.i386 0:5.1.6-45.el5_11 set to be updated

---> Package php-pdo.i386 0:5.1.6-45.el5_11 set to be updated

--> Finished Dependency Resolution

Dependencies Resolved

================================================================================

PackageArchVersion Repository Size

================================================================================

Installing:

php-mysqli3865.1.6-45.el5_11updates88 k

Installing for dependencies:

php-commoni3865.1.6-45.el5_11updates155 k

php-pdoi3865.1.6-45.el5_11updates67 k

Transaction Summary

================================================================================

Install 3 Package(s)

Upgrade 0 Package(s)

Total download size: 309 k

Downloading Packages:

(1/3): php-pdo-5.1.6-45.el5_11.i386.rpm | 67 kB 00:00

(2/3): php-mysql-5.1.6-45.el5_11.i386.rpm | 88 kB 00:00

(3/3): php-common-5.1.6-45.el5_11.i386.rpm | 155 kB 00:01

--------------------------------------------------------------------------------

Total 156 kB/s | 309 kB 00:01

Running rpm_check_debug

Running Transaction Test

Finished Transaction Test

Transaction Test Succeeded

Running Transaction

Installing : php-common 1/3

Installing : php-pdo2/3

Installing : php-mysql 3/3

Installed:

php-mysql.i386 0:5.1.6-45.el5_11

Dependency Installed:

php-common.i386 0:5.1.6-45.el5_11 php-pdo.i386 0:5.1.6-45.el5_11

Complete!

#mysql安装文件目录位置

[root@localhost ~]# whereis mysql

mysql: /usr/bin/mysql /usr/lib/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz

#mysql 运行文件目录位置

[root@localhost ~]# which mysql

/usr/bin/mysql

#查看服务是否已经添加到linux上

[root@localhost ~]# chkconfig --list mysqld

mysqld0:off 1:off 2:off 3:off 4:off 5:off 6:off

#重启与停止mysql服务

启动方式1 service mysql start

启动方式2 /etc/init.d/mysql start

停止方式1 service mysql stop

停止方式2 /etc/init.d/mysql stop

重启方式1 service mysql restart

重启方式2 /etc/init.d/mysql restart

#启动mysql数据库

[root@localhost ~]# /etc/rc.d/init.d/mysqld start

Initializing MySQL database: Installing MySQL system tables...

OK

Filling help tables...

OK

To start mysqld at boot time you have to copy

support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !

To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password'

/usr/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'

Alternatively you can run:

/usr/bin/mysql_secure_installation

which will also give you the option of removing the test

databases and anonymous user created by default. This is

strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:

cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl

cd mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/bin/mysqlbug script!

The latest information about MySQL is available on the web at

Support MySQL by buying support/licenses at

[ OK ]

Starting mysqld: [ OK ]

#为MySQL的root用户设置密码

MySQL在刚刚被安装的时候,它的root用户是没有被设置密码的。首先来设置MySQL的root密码。

在没设置密码之时,用root用户登录MySQL服务器

[root@localhost ~]# mysql -u root

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

Your MySQL connection id is 2

Server version: 5.0.95 Source distribution

Copyright (c) 2000, , Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select user,host,password from mysql.user;

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

| user | host | password |

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

| root | localhost ||

| root | localhost.localdomain ||

| root | 127.0.0.1 ||

| | localhost ||

| | localhost.localdomain ||

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

5 rows in set (0.00 sec)

mysql>

#mysql设置密码

mysql> set password for root@localhost=password ('在这里填入root密码'); ← 设置root密码

[root@localhost ~]#

#安装PHP

[root@localhost ~]# yum install php

Loaded plugins: fastestmirror

Loading mirror speeds from cached hostfile

* addons:

* base:

* extras:

* updates:

addons| 1.9 kB 00:00

base | 1.1 kB 00:00

extras| 2.1 kB 00:00

updates| 1.9 kB 00:00

Setting up Install Process

Resolving Dependencies

--> Running transaction check

---> Package php.i386 0:5.1.6-45.el5_11 set to be updated

--> Processing Dependency: php-cli = 5.1.6-45.el5_11 for package: php

--> Running transaction check

---> Package php-cli.i386 0:5.1.6-45.el5_11 set to be updated

--> Finished Dependency Resolution

Dependencies Resolved

================================================================================

PackageArchVersion Repository Size

================================================================================

Installing:

php i3865.1.6-45.el5_11updates2.3 M

Installing for dependencies:

php-clii3865.1.6-45.el5_11updates2.1 M

Transaction Summary

================================================================================

Install 2 Package(s)

Upgrade 0 Package(s)

Total download size: 4.4 M

Is this ok [y/N]: y

Downloading Packages:

(1/2): php-cli-5.1.6-45.el5_11.i386.rpm | 2.1 MB 00:03

(2/2): php-5.1.6-45.el5_11.i386.rpm | 2.3 MB 00:02

--------------------------------------------------------------------------------

Total 97 kB/s | 4.4 MB 00:46

Running rpm_check_debug

Running Transaction Test

Finished Transaction Test

Transaction Test Succeeded

Running Transaction

Installing : php-cli1/2

Installing : php 2/2

Installed:

php.i386 0:5.1.6-45.el5_11

Dependency Installed:

php-cli.i386 0:5.1.6-45.el5_11

Complete!

[root@localhost ~]# yum install php-devel

Loaded plugins: fastestmirror

Loading mirror speeds from cached hostfile

* addons:

* base:

* extras:

* updates:

Setting up Install Process

Resolving Dependencies

--> Running transaction check

---> Package php-devel.i386 0:5.1.6-45.el5_11 set to be updated

--> Finished Dependency Resolution

Dependencies Resolved

================================================================================

PackageArchVersionRepository Size

================================================================================

Installing:

php-develi3865.1.6-45.el5_11updates505 k

Transaction Summary

================================================================================

Install 1 Package(s)

Upgrade 0 Package(s)

Total download size: 505 k

Is this ok [y/N]: y

Downloading Packages:

php-devel-5.1.6-45.el5_11.i386.rpm | 505 kB 00:01

Running rpm_check_debug

Running Transaction Test

Finished Transaction Test

Transaction Test Succeeded

Running Transaction

Installing : php-devel 1/1

Installed:

php-devel.i386 0:5.1.6-45.el5_11

Complete!

#查看php设置文件

[root@localhost ~]# cd /etc/httpd/conf.d

[root@localhost conf.d]# ll *.conf

-rw-r--r-- 1 root root 771 Nov 6 php.conf

-rw-r--r-- 1 root root 566 Apr 4 proxy_ajp.conf

-rw-r--r-- 1 root root 299 Apr 4 welcome.conf

#启动Apache

[root@localhost /]# /etc/init.d/httpd start

Starting httpd: [ OK ]

[root@localhost ~]# /etc/init.d/httpd stop

Stopping httpd: [ OK ]

#配置apache

[root@localhost ~]# vi /etc/httpd/conf/httpd.conf

配置文件目录:/etc/httpd/conf/httpd.conf

修改一下配置:

ExtendedStatus On

<Location /server-status>

SetHandler server-status

Order deny,allow

Deny from all

Allow from .

Allow from 192.168.3.0/24

Allow from 127.0.0.1

Allow from 192.168.3.150

</Location>

#查看主机的目前状态回复网页

http://192.168.3.150/server-status

网页内容:

Apache Server Status for 192.168.3.150

Server Version: Apache/2.2.3 (CentOS)

Server Built: Apr 4 17:19:54

。。。。。后面省略

#编辑/etc/logrotate.d/httpd文件,启用备份日志压缩

/var/log/httpd/*log {

missingok

notifempty

sharedscripts

postrotate

/sbin/service httpd reload > /dev/null 2>/dev/null || true

endscript

compress //压缩备份日志

}

#用户端正常要求的记录日志

[root@localhost ~]# cat /var/log/httpd/access_log

#用户错误要求的数据,包括主机设置错误的信息等

[root@localhost ~]# cat /var/log/httpd/error_log

#重启apache

[root@localhost ~]# apachectl restart

#测试php

[root@localhost ~]# cat /var/www/html/phpinfo.php

<html>

<head>

<title>PHP ??</title>

</head>

<body>

<?php echo '<p>Hello World</p>'; ?>

</body>

</html>

#测试成功。就不上图了。

#关闭防火墙

[root@localhost ~]# service iptables stop

Flushing firewall rules: [ OK ]

Setting chains to policy ACCEPT: filter[ OK ]

Unloading iptables modules:[ OK ]

#apache 监听

[root@localhost ~]# netstat -tnl | grep 80

tcp 0 0 :::80 :::* LISTEN

#启动mysql

[root@localhost ~]# /etc/init.d/mysqld start

Starting mysqld: [ OK ]

#查看mysql监听端口

[root@localhost ~]# netstat -tnl | grep 3306

tcp 0 0 0.0.0.0:3306 0.0.0.0:*LISTEN

#登录mysql,查询用户,修改用户密码

[root@localhost ~]# mysql -u root

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

Your MySQL connection id is 2

Server version: 5.0.95 Source distribution

Copyright (c) 2000, , Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;

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

| Database|

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

| information_schema |

| mysql |

| test |

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

3 rows in set (0.04 sec)

mysql>

mysql> select user,host,password from mysql.user;

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

| user | host | password |

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

| root | localhost ||

| root | localhost.localdomain ||

| root | 127.0.0.1 ||

| | localhost ||

| | localhost.localdomain ||

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

5 rows in set (0.00 sec)

mysql> set password for root@localhost=password('123456');

Query OK, 0 rows affected (0.00 sec)

mysql> set password for root@127.0.0.1=password('123456');

Query OK, 0 rows affected (0.00 sec)

mysql> set password for root@localhost.localdomain=password('123456');

Query OK, 0 rows affected (0.00 sec)

mysql> select user,host,password from mysql.user;

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

| user | host | password|

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

| root | localhost | 565491d704013245 |

| root | localhost.localdomain | 565491d704013245 |

| root | 127.0.0.1 | 565491d704013245 |

| | localhost | |

| | localhost.localdomain | |

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

5 rows in set (0.00 sec)

mysql> exit

Bye

#用空密码登录失败

[root@localhost ~]# mysql -u root

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

#通过密码登录

[root@localhost ~]# mysql -u root -p

Enter password:

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

Your MySQL connection id is 7

Server version: 5.0.95 Source distribution

Copyright (c) 2000, , Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

mysql> select user,host from mysql.user;

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

| user | host |

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

| root | 127.0.0.1 |

| | localhost |

| root | localhost |

| | localhost.localdomain |

| root | localhost.localdomain |

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

5 rows in set (0.00 sec)

#删除匿名用户

mysql> delete from mysql.user where user='';

Query OK, 2 rows affected (0.00 sec)

mysql> select user,host from mysql.user;

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

| user | host |

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

| root | 127.0.0.1 |

| root | localhost |

| root | localhost.localdomain |

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

3 rows in set (0.01 sec)

#刷新,使以上操作生效

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

//-------------------------------------//

#发现主机连不上虚拟机的mysql数据库

注意需要在防火墙中开放3306的端口。

参考内容:

mysql远程连接 Host * is not allowed to connect to this MySQL server

/database/mysql/45230.htm

解决此问题有以下2个方法:

localhost改成%

进入mysql的BIN目录

mysql> use mysql;

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

mysql> update user set host='%' where user='root';

ERROR 1062 (23000): Duplicate entry '%-root' for key 1

mysql> select user,host from mysql.user;

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

| user | host |

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

| root | % |

| root | 127.0.0.1 |

| root | localhost.localdomain |

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

3 rows in set (0.00 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

mysql> select host,user from user where user='root';

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

| host | user |

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

| % | root |

| 127.0.0.1 | root |

| localhost.localdomain | root |

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

3 rows in set (0.00 sec)

参考内容:

查询mysql版本信息

//0106/358.html

#查询mysql版本

mysql> status;

--------------

mysql Ver 14.12 Distrib 5.0.95, for redhat-linux-gnu (i386) using readline 5.1

Connection id:7

Current database: mysql

Current user:root@localhost

SSL:Not in use

Current pager:stdout

Using outfile:''

Using delimiter: ;

Server version:5.0.95 Source distribution

Protocol version: 10

Connection: Localhost via UNIX socket

Server characterset: latin1

Db characterset: latin1

Client characterset: latin1

Conn. characterset: latin1

UNIX socket:/var/lib/mysql/mysql.sock

Uptime: 26 min 58 sec

Threads: 3 Questions: 93 Slow queries: 0 Opens: 23 Flush tables: 1 Open tables: 17

Queries per second avg: 0.057

--------------

mysql> select version();

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

| version() |

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

| 5.0.95 |

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

1 row in set (0.00 sec)

mysql>

mysql> exit

Bye

[root@localhost ~]# mysql -V

mysql Ver 14.12 Distrib 5.0.95, for redhat-linux-gnu (i386) using readline 5.1

#查看mysql日志

[root@localhost ~]# cat /var/log/mysqld.log

#查看端口

[root@localhost ~]# netstat -tupln

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address Foreign Address State

PID/Program name

tcp 0 0 0.0.0.0:3306 0.0.0.0:*LISTEN

6120/mysqld

tcp 0 0 0.0.0.0:111 0.0.0.0:*LISTEN

3466/portmap

tcp 0 0 0.0.0.0:721 0.0.0.0:*LISTEN

3507/rpc.statd

tcp 0 0 127.0.0.1:631 0.0.0.0:*LISTEN

3714/cupsd

tcp 0 0 127.0.0.1:25 0.0.0.0:*LISTEN

3814/sendmail: acce

tcp 0 0 :::80 :::* LISTEN

5061/httpd

tcp 0 0 :::22 :::* LISTEN

...........

#测试php连接mysql数据库

#创建测试脚本

[root@localhost ~]# vi /var/www/html/testdb.php

<?php

$con = mysql_connect("localhost","root","123456");

if (!$con)

{

die('Could not connect: ' . mysql_error());

}

// some code

$result = mysql_query("SHOW databases");

while($row = mysql_fetch_array($result))

{

echo $row[0].",";

}

mysql_free_result($result);

"/var/www/html/testdb.php" 24L, 304C written

#重启apache服务

[root@localhost ~]# service mysqld start

Starting mysqld:

[ OK ]

[root@localhost ~]#

网页显示:

information_schema,mysql,test,

#关机

[root@localhost ~]# halt

测试结束。

总结:

1. 手动启动服务:

#启动mysql数据库

[root@localhost ~]# /etc/rc.d/init.d/mysqld start

#启动Apache

[root@localhost /]# /etc/init.d/httpd start

#重启apache

[root@localhost ~]# apachectl restart

2.配置apache

#配置apache

[root@localhost ~]# vi /etc/httpd/conf/httpd.conf

配置文件目录:/etc/httpd/conf/httpd.conf

3. 防火墙

#关闭防火墙

[root@localhost ~]# service iptables stop

[root@localhost ~]# service iptables start

4. mysql

#用空密码登录失败

[root@localhost ~]# mysql -u root

#通过密码登录

[root@localhost ~]# mysql -u root -p

//--------------------------------------------------------------//

Apache的配置其实比较复杂,本文只是搭建了一个基础平台,实践工作中需要根据需求进行进一步的配置。

Apache配置目录下的httpd.conf比较重要,认真研究的话,里面有许多参数需要进行调整的,这个等以后有机会再去研究了。

以下摘抄了一份资料,以备日后查阅。

/html/ITjs/fwqjs/6724.html

apache主要目录结构及主要配置文件

本文主要讲述apache主要目录结构及主要配置文件

1.apache目录结构

[root@test apache]# tree -L 1

.

|-- bin 程序命令目录

|-- build

|-- cgi-bin

|-- conf 配置文件目录

|-- error

|-- htdocs 编译安装时站点目录

|-- icons

|-- include

|-- lib

|-- logs 默认日志文件存放包括错误日志(error_log)和访问日志(access_log) tail -f access_log可以随时看访问记录, 里面httpd.pid还会记录主进程号

|-- man

|-- manual

`-- modules 模块目录 例如PHP MEMCACHE编译后的模块在这里面

bin目录

[root@test bin]# tree

.

|-- ab apache http服务器性能压力测试工具,类似的jmeter loadrunner webbench

|-- apachectl apache的启动命令

|-- apr-1-config

|-- apu-1-config

|-- apxs apache服务器编译和安装扩展的工具,在进行DSO方式模块编译时会用到例如编译PHP时就用到:--with-apxs2=/usr/local/apache/bin/apxs

|-- checkgid

|-- dbmmanage

|-- envvars

|-- envvars-std

|-- htcacheclean 清理磁盘缓存区的命令,一般少用

|-- htdbm

|-- htdigest

|-- htpasswd 建立更新基本认证文件 例如配置nagio监控时候会用到

|-- httpd 为apache的控制命令程序,apachectl执行的时候会调用到httpd

|-- httxt2dbm

|-- logresolve

`-- rotatelogs apache自带日志轮换工具 ,也可以用到cronolog代替。

(本文来自/html/ITjs/fwqjs/6724.html)

conf目录

[root@test conf]# tree

.

|-- extra 辅助apache配置文件

| |-- httpd-autoindex.conf

| |-- httpd-dav.conf dav支持配置

| |-- httpd-default.conf apache相关服务配置 如超时时间 保持连接时间

| |-- httpd-info.conf

| |-- httpd-languages.conf 语言支持

| |-- httpd-manual.conf

| |-- httpd-mpm.conf 服务器池管理,如apache模式配置 连接等

| |-- httpd-multilang-errordoc.conf

| |-- httpd-ssl.conf 支持SSL加密配置

| |-- httpd-userdir.conf

| `-- httpd-vhosts.conf 虚拟机配置文件

|-- httpd.conf 主配置文件

|-- magic

|-- mime.types

`-- original

2 httpd.conf主配置文件

[root@test apache]# egrep -v "#.*|^$" /usr/local/apache/conf/httpd.conf

ServerRoot "/usr/local/apache2.2.22" apache安装目录

Listen 80 apache端口

<IfModule !mpm_netware_module>

<IfModule !mpm_winnt_module>

User daemon apache运行用户

Group daemon apache运行组

</IfModule>

</IfModule>

ServerAdminyou@ 管理员邮箱

DocumentRoot "/usr/local/apache2.2.22/htdocs" 站点目录,注意最后不要加/线

<Directory /> 根目录权限

Options FollowSymLinks 可以使用符号链接

AllowOverride None

Order deny,allow

Deny from all

</Directory>

<Directory "/usr/local/apache2.2.22/htdocs"> 目录权限 注意Indexes的作用是允许浏览目录

Options Indexes FollowSymLinks

AllowOverride None 禁止用户对目录配置文件.htaccess修改,一般为none

Order allow,deny

Allow from all

</Directory>

<IfModule dir_module>

DirectoryIndex index.html 站点目录首页文件多个文件用空格隔开

</IfModule>

<FilesMatch "^\.ht"> 防止WEB用户查看以.ht开头的隐藏文件

Order allow,deny

Deny from all

Satisfy All

</FilesMatch>

ErrorLog "logs/error_log" 错误日志

LogLevel warn 警告级别

<IfModule log_config_module>

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined 复合日志格式

LogFormat "%h %l %u %t \"%r\" %>s %b" common 常规日志格式

<IfModule logio_module>

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio 复合日志格式

</IfModule>

CustomLog "logs/access_log" common 默认访问日志格式

</IfModule>

<IfModule alias_module>

ScriptAlias /cgi-bin/ "/usr/local/apache2.2.22/cgi-bin/" CGI别名配置

</IfModule>

<IfModule cgid_module>

</IfModule>

<Directory "/usr/local/apache2.2.22/cgi-bin"> CGI权限访问路径

AllowOverride None

Options None

Order allow,deny

Allow from all

</Directory>

DefaultType text/plain 定义不能确定MIME类型时候使用默认MIME类型,如果服务主要包含text或HTML ,text/plain是一个好选择

<IfModule mime_module>

TypesConfig conf/mime.types

AddType application/x-compress .Z 允许信息在传输中使用mosaic/x 2.1+解压信息 但不是所有浏览器都支持

AddType application/x-gzip .gz .tgz

</IfModule>

<IfModule ssl_module>

SSLRandomSeed startup builtin

SSLRandomSeed connect builtin

</IfModule>

(桌面图标有蓝底怎么去掉:电脑桌面图标有蓝色阴影/html/xwzx/6590.html)

3.虚拟主机http_vhost.conf配置文件

NameVirtuaHost *:80

表示基于名称的虚拟主机 *:80表示监听本机所有IP的80端口上提供HTTP服务,*可以设置为具体IP

<VirtualHost *:80>

serveradmin 管理员邮箱

servername 域名

serveralias 别名 可以设置多个域名指向同一个站点

errorlog 错误日志

customlog 访问日志

</VirtualHost>

虚拟主机的配置是局部优先原则,也就是http_vhost.conf配置了,那么就不会从主配置文件http.conf中读取了

apache主要目录结构及主要配置文件来自:/html/ITjs/fwqjs/6724.html

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。