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
順利的話,能看到一個預期的結果。