专栏首页极客慕白的成长之路在Mac下配置PHP开发环境:Apache+php+MySql

在Mac下配置PHP开发环境:Apache+php+MySql

一、启动Apache 有两种方法

1、打开网络共享

打开"系统偏好设置"->"共享",在"互联网共享"那一项前面打√。

2、打开终端,输入

<span class="pln">sudo apachectl start</span>

1

<span class="pln">sudo apachectl start</span>

这时需要输入密码,输入电脑密码即可,然后输入

<span class="pln">sudo apachectl </span><span class="pun">-</span><span class="pln">v</span>

1

<span class="pln">sudo apachectl </span><span class="pun">-</span><span class="pln">v</span>

可以查看到Apache的版本信息

<span class="typ">Server</span><span class="pln"> version</span><span class="pun">:</span> <span class="typ">Apache</span><span class="pun">/</span><span class="lit">2.2</span><span class="pun">.</span><span class="lit">24</span> <span class="pun">(</span><span class="typ">Unix</span><span class="pun">)</span> <span class="typ">Server</span><span class="pln"> built</span><span class="pun">:</span> <span class="typ">Jul</span> <span class="lit">7</span> <span class="lit">2013</span> <span class="lit">18</span><span class="pun">:</span><span class="lit">05</span><span class="pun">:</span><span class="lit">17</span>

12

<span class="typ">Server</span><span class="pln"> version</span><span class="pun">:</span> <span class="typ">Apache</span><span class="pun">/</span><span class="lit">2.2</span><span class="pun">.</span><span class="lit">24</span> <span class="pun">(</span><span class="typ">Unix</span><span class="pun">)</span><span class="typ">Server</span><span class="pln"> built</span><span class="pun">:</span>   <span class="typ">Jul</span>  <span class="lit">7</span> <span class="lit">2013</span> <span class="lit">18</span><span class="pun">:</span><span class="lit">05</span><span class="pun">:</span><span class="lit">17</span>

此时在浏览器中输入http://localhost,会出现It works!的页面 二、运行PHP 1、找到Apache的配置文件,在目录/etc/apache2/下,打开Finder,选择"前往"-"前往文件夹",输入"/etc/apache2/",找到其中的"httpd.conf"文件,选择用文稿打开进行编辑,点按Command+F,搜索#LoadModule php5_module libexec/apache2/libphp5.so,如图

把蓝色那一行的#号去掉,然后保存,如果出现文本锁定,无法解锁的情况,解决办法有两种

a)选中该文件,右击后选择"显示简介",点击右下角的小锁的图标,输入电脑密码解锁,然后选择左边的+号键,选择自己当前电脑登陆的用户,将权限设置为读与写,如果还是不行,将其上一级文件夹权限同样再修改一次。

b)将该文件复制到桌面,进行修改,修改后再复制到原来的文件夹替换之前的文件即可。

2、重启Apache,在终端输入

<span class="pln">sudo apachectl restart</span>

1

<span class="pln">sudo apachectl restart</span>

PHP就可以用了。 3、在终端输入

<span class="pln">sudo cp </span><span class="pun">/</span><span class="typ">Library</span><span class="pun">/</span><span class="typ">WebServer</span><span class="pun">/</span><span class="typ">Documents</span><span class="pun">/</span><span class="pln">index</span><span class="pun">.</span><span class="pln">html</span><span class="pun">.</span><span class="pln">en </span><span class="pun">/</span><span class="typ">Library</span><span class="pun">/</span><span class="typ">WebServer</span><span class="pun">/</span><span class="typ">Documents</span><span class="pun">/</span><span class="pln">info</span><span class="pun">.</span><span class="pln">php</span>

1

<span class="pln">sudo cp </span><span class="pun">/</span><span class="typ">Library</span><span class="pun">/</span><span class="typ">WebServer</span><span class="pun">/</span><span class="typ">Documents</span><span class="pun">/</span><span class="pln">index</span><span class="pun">.</span><span class="pln">html</span><span class="pun">.</span><span class="pln">en </span><span class="pun">/</span><span class="typ">Library</span><span class="pun">/</span><span class="typ">WebServer</span><span class="pun">/</span><span class="typ">Documents</span><span class="pun">/</span><span class="pln">info</span><span class="pun">.</span><span class="pln">php</span>

即在Apache的根目录下复制index.html.en文件并重命名为info.php。

4、打开info.php,在It works后面加上<?php phpinfo(); ?>,然后再次重启Apache,在浏览器中输入http://localhost/info.php,会出现一个显示php信息的页面,如图所示。

三、配置MySql 1、在http://dev.mysql.com/downloads/mysql/网站上,选择Mac OS X平台,然后选择图中的下载,下载图中的版本安装成功

双击dmg文件

双击第一个安装,然后双击第三个安装,然后双击第二个,第二个是配置文件,安装之后,可以在系统偏好设置中选择启动或者关闭MySql。

2、修改密码

在终端输入,这里修改密码为123456,也可为其他,自定义即可

<span class="str">/usr/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">mysql</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">mysqladmin </span><span class="pun">-</span><span class="pln">u root password </span><span class="lit">123456</span>

1

<span class="str">/usr/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">mysql</span><span class="pun">/</span><span class="pln">bin</span><span class="pun">/</span><span class="pln">mysqladmin </span><span class="pun">-</span><span class="pln">u root password </span><span class="lit">123456</span>

四、使用phpMyAdmin phpMyAdmin是用PHP开发的管理MySql的程序,非常实用

1、下载phpMyAdmin,在网址http://www.phpmyadmin.net/home_page/downloads.php中选择合适的版本下载,我选择的是phpMyAdmin-4.0.8-All-Languages.tar.bz2 2、将下载好的文件解压后,放进/Library/WebServer/Documents/文件夹中,并命名为phpmyadmin。

3、复制/Library/WebServer/Documents/phpmyadmin中的config.sample.inc.php,并命名为config.inc.php,并放在当前文件夹下。

4、编辑config.inc.php,修改其中的

<span class="pln">$cfg</span><span class="pun">[</span><span class="str">'Servers'</span><span class="pun">]]</span><span class="pln">$i</span><span class="pun">][</span><span class="str">'host'</span><span class="pun">]</span> <span class="pun">=</span> <span class="str">'localhost'</span><span class="pun">;</span>

1

<span class="pln">$cfg</span><span class="pun">[</span><span class="str">'Servers'</span><span class="pun">]]</span><span class="pln">$i</span><span class="pun">][</span><span class="str">'host'</span><span class="pun">]</span> <span class="pun">=</span> <span class="str">'localhost'</span><span class="pun">;</span>

<span class="pln">$cfg</span><span class="pun">[</span><span class="str">'Servers'</span><span class="pun">]]</span><span class="pln">$i</span><span class="pun">][</span><span class="str">'host'</span><span class="pun">]</span> <span class="pun">=</span> <span class="str">'127.0.0.1'</span><span class="pun">;</span>

1

<span class="pln">$cfg</span><span class="pun">[</span><span class="str">'Servers'</span><span class="pun">]]</span><span class="pln">$i</span><span class="pun">][</span><span class="str">'host'</span><span class="pun">]</span> <span class="pun">=</span> <span class="str">'127.0.0.1'</span><span class="pun">;</span>

即可,如果想要无密码登陆,则将其中的下面语句中的false改成true

<span class="pln">$cfg</span><span class="pun">[</span><span class="str">'Servers'</span><span class="pun">][</span><span class="pln">$i</span><span class="pun">][</span><span class="str">'AllowNoPassword'</span><span class="pun">]</span> <span class="pun">=</span> <span class="kwd">false</span>

1

<span class="pln">$cfg</span><span class="pun">[</span><span class="str">'Servers'</span><span class="pun">][</span><span class="pln">$i</span><span class="pun">][</span><span class="str">'AllowNoPassword'</span><span class="pun">]</span> <span class="pun">=</span> <span class="kwd">false</span>

5、在浏览器中输入 http://localhost/phpmyadmin,输入用户名"root",和刚刚自己所更改的密码,如果未更改密码,则按照上一步骤中的无密码操作,然后就可以直接登陆了。 进行php开发还需下载一个php开发工具,mac下的php开发工具也挺多,不过大多数人用的还是PHPstorm和sublime,需要提醒的是,安装好开发工具之后,在建议php工程时,记得要将工程放在和phpmyadmin同一个目录文件下,可新建一个文件夹专门用来存放php工程,否则,是无法运行的

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • Atom主题插件美化教程

    对应的Themes就是可更换的主题。在这一共分为两块,UI Theme和Syntax Theme,一个是UI的,一个是文件语法的,这里可以选择相应的主题。

    慕白
  • 系统讲解CSS应用

    <input type="radio" name="radio1" id="radio1-2" /> <label for="radio1-2">选项二</la...

    慕白
  • Seaborn

    color_map = dict(zip(iris.Name.unique(), ['blue','green','red']))

    慕白
  • CSS3

    天天_哥
  • CSS 使用 Flex 布局来制作一个骰子

    我在上一篇博文 CSS 布局_2 Flex弹性盒中,对 Flex 弹性盒有着详细的介绍,在这里,我们使用 Flex 弹性盒布局,来实现骰子的布局,一个面可以设置...

    Nian糕
  • 前端每日实战:77# 视频演示如何用纯 CSS 创作旗帜飘扬的动画

    https://segmentfault.com/a/1190000015621468

    前端博客 : alili.tech
  • React优化-JSX模板优化-标签化

    JSX是JavaScrip的一种扩展语法,JSX的标签语法既不是字符串也不是HTML; 从本质上讲,JSX只是为React.createElement(comp...

    前端博客 : alili.tech
  • 前端每日实战:115# 视频演示如何用 CSS 和 D3 创作一组 π 数字的彩灯

    https://segmentfault.com/a/1190000016118926

    前端博客 : alili.tech
  • 对libevent+多线程服务器模型的C++封装类

    最近在看memcached的源码,觉得它那种libevent+多线程的服务器模型真的很不错,我将这个模型封装成一个C++类,根据我的简单测试,这个模型的效率真...

    bear_fish
  • 利用 Cloudmailin 服务解析邮件

    Cloudmailin 服务可以将邮件转化成 HTTP POST,这与 Webhook Agent 结合使用的话,可以实现很多有趣的功能,具体的设置步骤如下:

    huginn 中文网

扫码关注云+社区

领取腾讯云代金券