Home  >  Article  >  Backend Development  >  怎的在mac机器上搭建php的基础运行环境

怎的在mac机器上搭建php的基础运行环境

WBOY
WBOYOriginal
2016-06-13 12:16:20805browse

怎样在mac机器上搭建php的基础运行环境

1,首先Mac OS X 内置了Apache 和 PHP

检测包含php的方法:在终端输入

<code class=" hljs lasso">php <span class="hljs-attribute">-v</span></code>

这里写图片描述

检测是否已经有apache:在终端输入sudo apachectl -v

<code class=" hljs bash"><span class="hljs-built_in">sudo</span> apachectl -v</code>

这里写图片描述

2,在浏览器中输入http://localhost会出现一个html的网页

这里写图片描述

3,现在我们要配置让它能够显示php网页

在终端中运行“sudo vi /etc/apache2/httpd.conf”,打开Apache的配置文件。(如果不习惯操作终端和vi的可以设置在Finder中显示所有的系统隐藏文件,记得需要重启Finder,这样就可以找到对应文件,随心所欲编辑了,但需要注意的是某些文件的修改需要开启root帐号,但整体上还是在终端上使用sudo来临时获取root权限比较安全。)
找到“#LoadModule php5_module libexec/apache2/libphp5.so”,把前面的#号去掉,保存(在命令行输入:w)并退出vi(在命令行输入:q)。

4,做如下下配置(这个主要是为后期的网站的配置,暂时可以不用配置)

运行“sudo cp /etc/php.ini.default /etc/php.ini”,这样就可以通过php.ini来配置各种PHP功能了。比如:
;通过下面两项来调整PHP提交文件的最大值,比如phpMyAdmin中导入数据的最大值
upload_max_filesize = 2M
post_max_size = 8M
;比如通过display_errors来控制是否显示PHP程序的报错
display_errors = Off
运行“sudo apachectl restart”,重启Apache,这样PHP就可以用了。
运行“cp /Library/WebServer/Documents/index.html.en /Library/WebServer/Documents/info.php”,即在Apache的根目录下复制index.html.en文件并重命名为info.php
在终端中运行“vi /Library/WebServer/Document/info.php”,这样就可以在vi中编辑info.php文件了。在“It’s works!”后面加上“

5,现在我们来创建一个php文件,但是这个文件一定要放到apache目录下:/Library/WebServer/Document/

创建一个helloworld.php

<code class=" hljs xml"><span class="php"><span class="hljs-preprocessor"><?php</span><span class="hljs-keyword">echo</span> <span class="hljs-string">'Hello World!'</span>;<span class="hljs-preprocessor">?></span></span></code>

然后到浏览器中输入:http://localhost/helloworld.php

这里写图片描述

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn