Apache

1 # 源码安装 2 yum install apr-devel apr-util-devel pcre-devel 3 Wget http://mirrors.hust.edu.cn/apache/httpd/httpd-2.4.29.tar.bz2 4 Apache WEB服务器安装步骤如下: 5 tar -xjvf httpd-2.4.29.tar.bz2 tar工具解压httpd包; 6 cd httpd-2.4.29/ 进入解压后目录 7 ./configure --prefix=/usr/local/apache2/ --enable-rewrite --enable-so //预编译Apache,启用rewrite规则、启用动态加载库; 8 编译的时候可以通过configure的参数来指定--with-mpm=prefork|worker|event() 9 也可以编译为三种都支持,通过修改配置来更换。--enable-mpms-shared=all 10 make //编译 11 make install //安装Apache2.4.29 12 13 # YUM安装 14 yum install httpd apr-devel apr-util-devel php php-devel pcre-devel -y 15 16 # 相关依赖包安装 17 yum install apr apr-devel apr-util apr-util-devel pcre pcre-devel -y //安装ARP相关优化模块 18 APR(Apache portable Run-time libraries,Apache可移植运行库) 19 如其名称一样,主要为上层的应用程序提供一个可以跨越多操作系统平台使用的底层支持接口库 20 21 # 语法检查 22 /usr/local/apache/bin/apachectl configtest

1 # 源码版 2 # vim conf/extra/httpd-vhosts.conf 3 <VirtualHost *:81> 4 ServerAdmin webmaster@dummy-host.example.com 5 DocumentRoot "/usr/local/apache/htdocs/host1" 6 ServerName host1.com 7 ServerAlias www.dummy-host.example.com 8 ErrorLog "logs/dummy-host.example.com-error_log" 9 CustomLog "logs/dummy-host.example.com-access_log" common 10 </VirtualHost> 11 # vim conf/httpd.conf 12 Listen 80 13 Listen 81 14 Listen 82 //添加监听端口 15 ...... 16 # Virtual hosts 17 #Include conf/extra/httpd-vhosts.conf //删除开头注释,使vhost.conf生效 18 #/usr/local/apache/bin/apachectl start //重启服务 19 20 # YUM版: 21 # cp /usr/share/doc/httpd/httpd-vhosts.conf /etc/httpd/conf.d/ 22 # vi /etc/httpd/conf.d/httpd-vhosts.conf 23 <VirtualHost *:80> 24 ServerAdmin webmaster@dummy-host.example.com 25 DocumentRoot "/var/www/html/host1" 26 ServerName host1.com //域名 27 ServerAlias host(1).com //关联域名host(1)和host1 28 ErrorLog "/var/log/httpd/dummy-host.example.com-error_log" 29 CustomLog "/var/log/httpd/dummy-host.example.com-access_log" common 30 </VirtualHost> 31 # vi /etc/httpd/conf/httpd.conf 32 #Listen 12.34.56.78:80 33 Listen 80 34 Listen 81 //增加监听端口 35 # systemctl restart httpd.service

1 [root@iscsi-client ~] # vim /etc/httpd/conf/httpd.conf 2 [root@iscsi-client ~] #DocumentRoot "/var/www/html" 3 DocumentRoot "/data/test" //注释原始发布目录,添加新发布目录 4 <Directory "/data"> 5 Require all granted //给新的发布目录授权 6 </Directory> 7 8 [root@iscsi-client ~]# ls -lZd /var/www/html 9 drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 /var/www/html 10 [root@iscsi-client ~]# ls -lZd /data/test 11 drwxrwxrwx. root root unconfined_u:object_r:unlabeled_t:s0 /data/test 12 # 查看默认发布目录与新建目录安全上下文不一致,修改新目录安全上下文 13 [root@iscsi-client ~]# semanage fcontext -a -t httpd_sys_content_t "/data/test(/.*)?" 14 [root@iscsi-client ~]# ls -lZd /data/test 15 drwxrwxrwx. root root unconfined_u:object_r:unlabeled_t:s0 /data/test 16 [root@iscsi-client ~]# restorecon -FvvR /data/ 17 restorecon reset /data context system_u:object_r:unlabeled_t:s0->system_u:object_r:default_t:s0 18 restorecon reset /data/test context unconfined_u:object_r:unlabeled_t:s0->system_u:object_r:httpd_sys_content_t:s0 19 restorecon reset /data/test/index.html context unconfined_u:object_r:unlabeled_t:s0->system_u:object_r:httpd_sys_content_t:s0 20 restorecon reset /data/lost+found context system_u:object_r:unlabeled_t:s0->system_u:object_r:default_t:s0 21 [root@iscsi-client ~]# ls -lZd /data/test 22 drwxrwxrwx. root root system_u:object_r:httpd_sys_content_t:s0 /data/test 23 [root@iscsi-client ~]# curl 127.0.0.1 24 <h1>test</h1>
ERROR

1 缺失相关依赖包(查找相关路径并指明): 2 #apr-1-config --bindir //查找pcre路径 3 #pcre-config --prefix //查找pcre路径 4 # ./configure --prefix=/usr/local/apache/ --enable-rewrite --enable-so --with-apr=/usr/bin --with-pcre=/usr 5 6 PHP不能解析之判断故障 7 1. /usr/local/apache/bin/apachectl -M //查看有没有加载php5_module(shared)模块; 8 2. 在/usr/local/apache2/modules/ 目录下,查看有没有加载libphp5.so模块; 9 3. 复查编译的配置文件有否有误:/usr/local/apache2/conf/httpd.conf 10 修改apache的配置文件httpd.conf 11 vim /usr/local/apache2/conf/httpd.conf 12 在httpd.conf中找到: “AddType application/x-gzip .gz .tgz” 在该行下面添加 13 “AddType application/x-httpd-php .php” 14 再找继续找到:“DirectoryIndex index.html”,把此行修改成 15 “DirectoryIndex index.html index.htm index.php” 16 再找到: “#ServerName www.example.com:80”把此行修改成 17 “ServerName localhost:80” 保存后退 18 4. 使用命令查看主配置文件是否有误:/usr/local/apache2/bin/apachectl -t 19 5. 在编译安装apache时,建议加上两个参数(以后用到就不需要再编译): 20 --enable-modes-shared=most //编译加载最多的模块 21 --enalbe-modes-shared=all //编译加载所有模块 22 总之出现故障后,先要判断问题的原因,这样才有办法应对。 23 24 ·/usr/local/apache2/bin/apachectl -M:查看安装了哪些模块 25 ·/usr/local/apache/bin/apachectl -V:查看使用的模式 26 ·/usr/local/apache2/bin/apachectl -t:检查语法错误 27 ·/usr/local/apache2/bin/apachectl -l:查看安装的库文件 28 ·/usr/local/apache2/bin/apachectl graceful:重新加载配置 29 ·/usr/local/apache2/htcocs 主页存放目录 30 ·/usr/local/apache2/bin/apachectl 启动文件目录