centos 7 安装 apache http 服务 httpd 和 php

1 篇文章 0 订阅
1 篇文章 0 订阅

Apache HTTP 服务项目致力于发展和维护 开源的 HTTP 服务,提供 安全 有效 可扩展的 HTTP 服务,保持与 HTTP 标准同步。

Apache HTTP 服务 (httpd)始发于 1995 年, 是 Apache 软件基金会的一个项目。复制于官网的简介如下。

The Apache HTTP Server Project is an effort to develop and maintain an open-source HTTP server for modern operating systems including UNIX and Windows. The goal of this project is to provide a secure, efficient and extensible server that provides HTTP services in sync with the current HTTP standards.

The Apache HTTP Server ("httpd") was launched in 1995 and it has been the most popular web server on the Internet since April 1996. It has celebrated its 20th birthday as a project in February 2015.

The Apache HTTP Server is a project of The Apache Software Foundation.


PHP 超文本预处理器,是流行的 web 开发语言。复制于官网的简介如下。

PHP (Hypertext Preprocessor) is a popular general-purpose scripting language that is especially suited to web development. Fast, flexible and pragmatic, PHP powers everything from your blog to the most popular websites in the world.


安装 httpd 2.4


#yum install httpd httpd-devel mod_ssl


查看版本


#httpd -V


开启 httpd 服务


#apachetcl start


查看开启的 httpd 服务


#ps aux |grep httpd


某版本的 centos 防火墙屏蔽了 httpd 默认的 80 端口,如果是,开启


#iptables -I INPUT -p tcp --dport 80 -j ACCEPT


并保存改变


#service iptables save


用 firefox 查看 httpd 是否运行


#firefox localhost


如果页面出现 ... it means that this site is working properly ... 表示 httpd 运行正常


开启 httpd 服务自启动


#chkconfig httpd on


证实自启动


#systemctl list-unit-files |grep httpd


安装 php 5.4


安装以下 php 组件可能是不错的选择


#yum install php php-devel php-gd php-pecl-memcache php-pspell php-snmp php-xmlrpc php-xml


查看版本


php --version


使用简单的脚本测试 httpd 和 php


httpd 安装后有一个目录  /var/www/html 是 httpd 的默认根目录。把两个脚本 index.html 和 test.php 放置于该目录


index.html 的内容如下


<html>
<head>
<meta charset="utf-8">
<title>apache php test</title>
</head>
<body>
<form action="test.php" method="post">
What is your name: <input type="text" name="fname">
<input type="submit" value="submit">
</form>
</body>
</html>


test.php 的内容如下


welcome <?php echo $_POST["fname"]; ?>!<br>


运行


firefox localhost


填入一个名字并提交,页面跳转


但是可能没有实现需要的效果,这是因为 hpptd 服务没有解析 php 文件,编辑 httpd 的配置文件改善之, 配置文件为


/etc/httpd/conf/httpd.conf


在其中找到  AddType application/x...

在临近位置添加


AddType application/x-httpd-php .php


现在重启 httpd 服务


#apacheclt restart


运行 


firefox localhost


顺利的话,能看到一个预期的结果。





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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值