Apache 笔记

☆ 查看系统 CentOS 自带的 Apache 安装版本

[root@httpd ~]# rpm -qa httpd
httpd-2.2.15-26.el6.centos.x86_64

☆ 卸载 Apache 

[root@httpd ~]# rpm -e --allmatches --nodeps httpd-2.2.15-26.el6.centos.x86_64
[root@httpd ~]# rpm -qa httpd
[root@httpd ~]# rpm -e --allmatches --nodeps httpd-2.2.15-26.el6.centos.x86_64
error: package httpd-2.2.15-26.el6.centos.x86_64 is not installed

☆ 安装 Apache

tar -zxvf httpd-2.2.27.tar.gz 
cd httpd-2.2.27

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

make
make install
cd /application/
ll
ln -s /application/apache2.2.27/ /application/apache
cd application/
ll
ln -s /application/apache2.2.27/ /application/apache
rm -fr /application/apache
ll
ln -s /application/apache2.2.27/ /application/apache

ll

☆ 启动并访问

cd /application/apache/bin
./apachectl -t
./apachectl start
lsof -i :80
ps -ef|grep httpd

☆ 服务器内部测试
wget localhost
curl localhost
服务器外部测试

http://server ip/


☆ 修改项目首页

cd /application/apache/conf
vi httpd.conf 

<IfModule dir_module>
    DirectoryIndex default.html index.html
</IfModule>

以上配置片段,把默认首页修改为,第一首页是 [ default.html ] , 第二首页是 [ index.html ] 。
优先使用第一首页,找不到第一首页,使用第二首页,二者都找不懂,项目无首页。

优雅地重启 Apache
cd /application/apache/bin
./apachectl graceful

 

☆ 获取一份纯净的 Apache 配置文件

把 Apache 配置文件的注释和空行去掉,新内容输出到新文件 httpd.conf.ori ,
源文件保持不变。
grep -Ev "#|^$" httpd.conf >httpd.conf.ori
 
☆ 项目无首页时,不要列出网站文件

默认情况下,项目无首页, Apache 列出网站的所有文件,
修改配置文件,禁用此功能。

vi httpd.conf 

<Directory "/application/apache2.2.27/htdocs">
    Options FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

以上配置片段把把原先的 Indexes 去掉,优雅重启 Apache

./apachectl graceful

☆ 设置 Apache 虚拟主机(部署多个 Apache 项目)
mkdir -p /var/html/{www,blog,bbs}  [花括号内的三个目录名称之间不能有空格]
touch /var/html/{www,blog,bbs}/index.html
for name in www blog bbs;do echo "http://$name.test.com/" >/var/html/$name/index.html; done
for name in www blog bbs;do cat /var/html/$name/index.html;done
tree /var/html


vi /application/apache/conf/extra/httpd-vhosts.conf  
新增如下配置:


<VirtualHost *:80>
    ServerAdmin 7987423@qq.com
    DocumentRoot "/var/html/www"
    ServerName www.test.com
    ServerAlias www.test.com
    ErrorLog "logs/www-error_log"
    CustomLog "logs/www-access_log" common
</VirtualHost>


<VirtualHost *:80>
    ServerAdmin 123456@qq.com
    DocumentRoot "/var/html/blog"
    ServerName blog.test.com
    ServerAlias blog.test.com
    ErrorLog "logs/blog-error_log"
    CustomLog "logs/blog-access_log" common
</VirtualHost>


<VirtualHost *:80>
    ServerAdmin 09985773@qq.com
    DocumentRoot "/var/html/bbs"
    ServerName bbs.test.com
    ServerAlias bbs.test.com
    ErrorLog "logs/bbs-error_log"
    CustomLog "logs/bbs-access_log" common
</VirtualHost>


vi /application/apache/conf/httpd.conf
a.把下面配置片段的注释打开
Include conf/extra/httpd-mpm.conf
Include conf/extra/httpd-vhosts.conf


b.增加如下配置
<Directory "/var/html">
    Options  FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>


检查配置文件的语法
cd /application/apache/bin
./apachectl -t


优雅地重启 Apache
./apachectl graceful


配置客户端机器的 hosts
修改文件 C:\Windows\System32\drivers\etc\hosts ,增加如下配置
10.1.3.53 www.test.com blog.test.com bbs.test.com


☆ 解决异常-无法可靠地确认服务器的完全限定域名
httpd: Could not reliably determine the server's fully qualified domain name, 
using ::1 for ServerName


vi httpd.conf
打开注释并修改他的内容,如下所示

ServerName 127.0.0.1:80


☆ Apache 日志轮询

安装 cronolog

tar -zxvf cronolog
cd cronolog
./configure
make 
make install

安装完毕,生成如下工具
ll /usr/local/sbin/cronolog

vi  httpd-vhosts.conf
修改配置片段

<VirtualHost *:80>
    ServerAdmin 7987423@qq.com
    DocumentRoot "/var/html/www"
    ServerName www.test.com
    ServerAlias www.test.com
    ErrorLog "|/usr/local/sbin/cronolog /application/apache/logs/www-error-%Y%m%d.log"
    CustomLog "|/usr/local/sbin/cronolog /application/apache/logs/www-access-%Y%m%d.log" combined
</VirtualHost>

其中, ErrorLog 是错误日志轮询,CustomLog 是访问日志轮询。

vi /application/apache/conf/httpd.conf
a.把
CustomLog "logs/access_log" common
修改为
CustomLog "|/usr/local/sbin/cronolog /application/apache/logs/default-access-%Y%m%d.log" combined

b.把
ErrorLog "logs/error_log"
修改为
ErrorLog "|/usr/local/sbin/cronolog /application/apache/logs/default-error-%Y%m%d.log"

优雅地重启 Apache
cd /application/apache/bin

./apachectl graceful


☆ 安装 PHP 并结合 Apache


rpm -q zlib libxml2 \
libjpeg-turbo  freetype libpng gd \
curl zlib-devel libxml2-devel \
libjpeg-turbo-devel freetype-devel \
libpng-devel  gd-devel \


yum install zlib libxml2 \
libjpeg-turbo  freetype libpng gd \
curl zlib-devel libxml2-devel \
libjpeg-turbo-devel freetype-devel \
libpng-devel  gd-devel -y \


rpm -q zlib libxml2 \
libjpeg-turbo  freetype libpng gd \
curl zlib-devel libxml2-devel \
libjpeg-turbo-devel freetype-devel \
libpng-devel  gd-devel \


tar -zxvf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local/libiconv
make
make install


tar -zxvf php-5.3.27.tar.gz 
cd php-5.3.27
mkdir -p /application/php5.3.27


./configure \
--prefix=/application/php5.3.27 \
--with-apxs2=/application/apache/bin/apxs \
--with-mysql=/usr/local/mysql \
--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


make
make install
ln -s /application/php5.3.27/ /application/php
cd /application/apache/modules
ll
grep php /application/apache/conf/httpd.conf
cp php.ini-production /application/php/lib/php.ini


vi /application/apache/conf/httpd.conf
找到配置片段
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
在这个配置片段增加如下配置片段
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
找到配置片段
User daemon
Group daemon
把他们修改为
User www
Group www
找到配置片段
<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>
把他们修改为
<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>


groupadd www
useradd www -g www -M -s /sbin/lologin
./apachectl -t
./apachectl restart


index.php
<?php
 phpinfo();
?>


mysql.php
<?php
$link_id=mysql_connect('10.1.1.3','root','test') or mysql_error();


if($link_id){
echo "mysql successful by root !";
}else{
echo mysql_error();
}
?>










  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值