最近在帮学妹做一个毕业设计,这个系统同时需要前端和后端.前端也就罢了,后端的php代码却只能借助于服务器运行.也就是说,用Firefox根本不能直接打开php页面.没办法,必须得安装一个http服务器.
一.httpd
百度百科
httpd是Apache超文本传输协议(HTTP)服务器的主程序.被设计为一个独立运行的后台进程,它会建立一个处理请求的子进程或线程的池.
没看懂?看看维基百科的解释.
维基百科
HTTP Daemon is a software program that runs in the background of a web server and waits for the incoming server requests. The daemon answers the request automatically and serves the hypertext and multimedia documents over the internet using HTTP.
(httpd是一个在后台等待http请求的http服务器.收到http请求后,它会自动响应请求,并且使用http协议向请求者发回超文本或多媒体文档.)httpd stands for Hypertext Transfer Protocol Daemon (i.e. web server).
狗尾续貂地说几句,httpd就是个在后台运行的进程.它能接收到其他主机发送到本地的http请求,然后把请求的超文本或者多媒体包装在http协议里面发送回去.
下面的shell命令里,前面有$
的表示需要root权限.
- 安装httpd:
$ yum install httpd
- 启动httpd:
$ service httpd start
好了,两条命令就把httpd安装好并且启动起来了.
不信?打开浏览器,在地址栏输入:
127.0.0.1
看到了没.
二.在httpd上部署网页
看这儿:
这样的话…
- 进入目录/var/www/html
cd /var/www/html
- 在当前目录下新建一个目录,名字随便:
$ mkdir -p hello
- 老是超级用户权限,真烦人.把目录权限改了算了:
$ chown xxx:yyy .
xxx是你的用户名,yyy是你的组名.这两者通常是一样的.
- 把你的网页复制到新建的目录下面
cp some_path/index.php hello
我复制的是一个php页面.然而,html页面也是可以的.
- 打开浏览器,在地址栏输入
127.0.0.1/hello/index.php
看看效果:
完成:)