Chinaunix首页 | 论坛 | 博客
  • 博客访问: 160619
  • 博文数量: 45
  • 博客积分: 2582
  • 博客等级: 少校
  • 技术积分: 620
  • 用 户 组: 普通用户
  • 注册时间: 2006-02-10 18:32
文章分类

全部博文(45)

文章存档

2020年(3)

2018年(1)

2017年(20)

2013年(1)

2012年(1)

2007年(3)

2006年(16)

我的朋友

分类: LINUX

2017-05-31 16:40:42

Apache在Linux系统中,其实叫“httpd”,可以使用yum来安装。

1、查看httpd包是否可用:
# yum list | grep httpd

2、安装Apache
# yum install httpd


3、配置ServerName
# vi /etc/httpd/conf/httpd.conf
如果没有域名,则:ServerName localhost:80

启动
# httpd
停止
# httpd -k stop

设置开机自动启动:
chkconfig httpd on

安装目录介绍
Apache默认将网站的根目录指向/var/www/html 目录
默认的主配置文件是/etc/httpd/conf/httpd.conf
配置存储在的/etc/httpd/conf.d/目录

如果Firewalld正在运行,请允许HTTP服务。
HTTP使用80/ TCP
[root@linuxprobe~]# firewall-cmd --add-service=http --permanent
success
[root@linuxprobe~]# firewall-cmd --reload
success

vi /etc/httpd/conf/httpd.conf
# line 86: 改变管理员的邮箱地址
ServerAdmin root@linuxprobe.org
# line 95: 改变域名信息
ServerName
# line 151: none变成All
AllowOverride All
# line 164: 添加只能使用目录名称访问的文件名
DirectoryIndex index.html index.cgi index.php
# add follows to the end
# server's response header(安全性)
ServerTokens Prod
# keepalive is ON
KeepAlive On

支持Perl

  • 启用CGI执行并使用Perl脚本

[1] 安装Perl.
[root@linuxprobe~]# yum -y install perl perl-CGI

[2] 默认情况下,在“/var/www/cgi-bin”目录下允许CGI。 可以使用Perl Scripts放在目录下。然而,它下面的所有文件都被处理为CGI。
# 下面的设置是CGI的设置
[root@linuxprobe~]# grep -n "^ *ScriptAlias" /etc/httpd/conf/httpd.conf
247: ScriptAlias/cgi-bin/"/var/www/cgi-bin/"

[3] 如果你想允许在其他目录中的CGI,配置如下。
例如,在“/var/www/html/cgi-enabled”中允许。
[root@linuxprobe~]# vi /etc/httpd/conf.d/cgi-enabled.conf
# create new
# processes .cgi and .pl as CGI scripts

Options +ExecCGI
AddHandler cgi-script .cgi .pl

[root@linuxprobe~]# systemctl restart httpd

[4] 如果SELinux被启用,并且允许CGI在不是像上面[3]的默认目录下,更改规则如下。
[root@linuxprobe~]# chcon -R -t httpd_sys_script_exec_t /var/linuxprobe/html/cgi-enabled
[root@linuxprobe~]# semanage fcontext -a -t httpd_sys_script_exec_t /var/www/html/cgi-enabled

[5] 创建一个CGI测试页面,并使用Web浏览器从客户端PC访问它。如果显示以下页面,说明配置正确。
[root@linuxprobe~]# vi /var/www/html/cgi-enabled/index.cgi
#!/usr/bin/perlprint"Content-type: text/html\n\n";
print"\n\n";
print"

\n";
print"CGI Test Page";
print"\n
\n";
print"\n\n";
[root@linuxprobe~]# chmod 705 /var/www/html/cgi-enabled/index.cgi


支持PHP

  • 配置httpd以使用PHP脚本

[1] 安装PHP.
[root@linuxprobe~]# yum -y install php php-mbstring php-pear
[root@linuxprobe~]# vi /etc/php.in
i# line 878: 取消注释,设置时区date.timezone ="Asia/Shanghai"
[root@linuxprobe~]# systemctl restart httpd

[2] 创建一个PHP测试页面,并使用Web浏览器从客户端PC访问它。如果显示以下页面,它是确定。
[root@linuxprobe~]# vi /var/www/html/index.php


[3] 创建phpinfo测试页,确认是都开启php支持
[root@linuxprobe ~]# echo "
阅读(810) | 评论(0) | 转发(0) |
0

上一篇:centos7 安装配置nginx

下一篇:apache 配置

给主人留下些什么吧!~~