apache服务安装并实现基于虚拟主机的实践

apache2.2.31+php5.3.27+mysql5.5.49

1、安装apache

wget http://archive.apache.org/dist/httpd/httpd-2.2.31.tar.gz

tar xf httpd-2.2.31.tar.gz

cd httpd-2.2.31

yum install zlib zlib-devel -y

./configure --prefix=/application/apache2.2.31 --enable-deflate --enable-expires --enable-headers --enable-modules=most --enable-so --with-mpm=worker --enable-rewrite

make

make install

ln -s /application/apache2.2.31/ /application/apache

ll /application/apache

 

虚拟主机配置:

     域名                         站点目录

www.etiantian.org      /application/apache/htdocs/www

bbs.etiantian.org      /application/apache/htdocs/bbs

blog.etiantian.org     /application/apache/htdocs/blog

 

 

cd /application/apache/htdocs/

mkdir www bbs blog

echo 'apache www' >/application/apache/htdocs/www/index.html

echo 'apache bbs' >/application/apache/htdocs/bbs/index.html

echo 'apache blog' >/application/apache/htdocs/blog/index.html

vim /application/apache/conf/httpd.conf

/hosts #搜索hosts

Include conf/extra/httpd-vhosts.conf   #将这行注释去了

vim /application/apache/conf/extra/httpd-vhosts.conf

<VirtualHost *:80>  #*表示所有网卡,80代表端口号

    ServerAdmin [email protected]  #邮箱设置

    DocumentRoot "/application/apache2.2.31/docs/dummy-host.example.com"  #站点设置

    ServerName dummy-host.example.com  #域名

    ServerAlias www.dummy-host.example.com  #别名

    ErrorLog "logs/dummy-host.example.com-error_log"  #错误日志

    CustomLog "logs/dummy-host.example.com-access_log" common  #访问日志

</VirtualHost>

配置后的内容:

vim /application/apache/conf/extra/httpd-vhosts.conf

<VirtualHost *:80>

    ServerAdmin [email protected]

    DocumentRoot "/application/apache2.2.31/htdocs/www"

    ServerName www.etiantian.org

    ServerAlias etiantian.org

    ErrorLog "logs/www-error_log"

    CustomLog "logs/www-access_log" common

</VirtualHost>

#

<VirtualHost *:80>

    ServerAdmin [email protected]

    DocumentRoot "/application/apache2.2.31/htdocs/bbs"

    ServerName bbs.etiantian.org

    ErrorLog "logs/bbs-error_log"

    CustomLog "logs/bbs-access_log" common

</VirtualHost>

#

<VirtualHost *:80>

    ServerAdmin [email protected]

    DocumentRoot "/application/apache2.2.31/htdocs/blog"

    ServerName blog.etiantian.org

    ErrorLog "logs/blog-error_log"

    CustomLog "logs/blog-access_log" common

</VirtualHost>

/application/apache/bin/apachectl -t

 

检查语法时出现的问题

[root@web02 conf]# /application/apache/bin/apachectl -t

httpd: apr_sockaddr_info_get() failed for web02

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

Syntax OK

解决办法:

[root@web02 conf]# vim /application/apache/conf/httpd.conf

将#ServerName www.example.com:80修改为ServerName 127.0.0.1:80

[root@web02 conf]# /application/apache/bin/apachectl -t

Syntax OK

 

/application/apache/bin/apachectl start  #启动apache

/application/apache/bin/apachectl graceful  #平滑重启apache

 

vim /application/apache/conf/httpd.conf

Options Indexes FollowSymLinks更改为Options -Indexes FollowSymLinks

目的是取消客户端访问列表目录

 

客户端:

[root@web01 tools]#vim /etc/hosts  #配置hosts

172.16.1.7   web02 www.etiantian.org etiantian.org bbs.etiantian.org blog.etiantian.org  #添加的内容,做解析

测试:

[root@web01 tools]# curl www.etiantian.org

apache www

[root@web01 tools]# curl bbs.etiantian.org

apache bbs

[root@web01 tools]# curl blog.etiantian.org

apache blog

 

安装PHP基础库

yum install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libiconv-devel -y

 

cd /home/ceshi/tools

wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz

tar xzf libiconv-1.14.tar.gz

cd libiconv-1.14

./configure --prefix=/usr/local/libiconv

make && make install

cd ../

 

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo

yum -y install libmcrypt-devel

yum -y install mhash

yum -y install mcrypt

rpm -qa libmcrypt-devel mhash mcrypt

 

PHP安装

wget http://mirrors.sohu.com/php/php-5.3.27.tar.xz

tar xf php-5.3.27.tar.xz

cd php-5.3.27

./configure --prefix=/application/php5.3.27 --with-apxs2=/application/apache/bin/apxs --with-mysql=mysqlnd --with-xmlrpc --with-openssl --with-zlib --with-freetype-dir --with-gd --with-jpeg-dir --with-png-dir --with-iconv=/usr/local/libiconv --enable-short-tags --enable-sockets --enable-zend-multibyte --enable-soap --enable-mbstring  --enable-static --enable-gd-native-ttf --with-curl --with-xsl --enable-ftp --with-libxml-dir

 

./configure --prefix=/application/php5.3.27 --with-apxs2=/application/apache/bin/apxs --with-mysqli=mysqlnd  --with-pdo-mysql=mysqlnd --with-openssl --with-iconv-dir=/usr/local/libiconv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-xmlrpc --enable-zip --enable-soap --enable-short-tags --enable-static --with-xsl --enable-ftp

 

提示:

--with-mysqli=mysqlnd 使用此参数本地可以不安装mysql软件包

 

编译中出现的错误:

configure: error: Cannot find OpenSSL's <evp.h>

解决办法:

yum install -y openssl-devel

 

make

make install

ln -s /application/php5.3.27/ /application/php

 

配置Apache实现与PHP的整合:

useradd -u 890 www   

vim /application/apache/conf/httpd.conf

1、311gg  切换到311行添加以下内容

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

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

2、/DirectoryIndex  搜索到DirectoryIndex行

<IfModule dir_module>

    DirectoryIndex index.php index.html   #添加index.php

</IfModule>

3、用户名及组名修改,/67gg

User daemon

Group daemon修改为

User www

Group www

 

/application/apache/bin/apachectl -t   #检查语法

/application/apache/bin/apachectl start  #启动apache

vi /application/apache/htdocs/www/test.php  #编辑test.php,做测试,测试完毕要记得删除,避免出错

<?php

phpinfo();

?>

/application/apache/bin/apachectl graceful  #优雅重启

猜你喜欢

转载自blog.csdn.net/qq_41816540/article/details/81292692