在MAC上开启PHP和搭建 Mysql

首先打开commandline 工具 php

 sudo vi /etc/apache2/httpd.conf html

找到  mysql

#LoadModule php5_module        libexec/apache2/libphp5.so web

去掉 “#” 将使php5 模块在 Apache 中可用 sql

保存文件 macos

打开“系统偏好设置” ,- 共享 - 勾选Web共享,这样就完成了 apache


接下来是如何搭建Mysql api

1.下载mysql 安装文件 (下载地址http://dev.mysql.com/downloads/mysql/5.1.html#macosx-dmg) 浏览器

打开dmg安装包 先安装mysql-5.1.70-osx10.6-x86_64.pkg,安装好后安装MySQLStartupItem.pkg ,最后安装MySQL.prePane. 工具

2 如今剩下要作的就是开启 Virtual Hosts. 首先再一次打开 httpd.conf 文件.找到 

# Virtual hosts

#Include /private/etc/apache2/extra/httpd-vhosts.conf

去掉 ”#Include "中的“#”, 如今咱们须要修改 httpd-vhosts.conf文件来添加咱们的虚拟主机

3 打开 /etc/apacha2/extra/httpd-vhosts.conf ,咱们准备为咱们的虚拟主机添加一个实体。

<VirtualHost *:80>
        DocumentRoot "/Users/username/Sites/Website"
        ServerName yourwebsitename  
</VirtualHost>

请注意“username" 你帐户的名字 “yourwebsitename" 你能够使用喜欢的名字。

4.最后,咱们须要修改 /etc/hosts 文件 使Servername 在浏览器中能够使用。那么打开这个文件添加如下的内容

127.0.0.1 yourwebsitename

来使咱们的网站名可以被解析成localhost 后者127.0.0.1

5,如今,重启Apache(系统偏好设置-共享,取消网站共享 后再次选中便可)

6.接下来,让咱们来测试下 php 吧。在 /Users/username/Sites/Webiste 目录下建立 index.php 内容以下

<?php
 
class RedeemAPI {
    // Main method to redeem a code
    function redeem() {
        echo "Hello, PHP!";
    }
}
 
// This is the first thing that gets called when this page is loaded
// Creates a new instance of the RedeemAPI class and calls the redeem method
$api = new RedeemAPI;
$api->redeem();
 
?>


在 浏览器中输入网址 :yourwebsitename/index.php  看看是否输出 Hello, PHP!

(参考网址:http://osxfactor.com/2009/08/30/how-to-enable-php-mysql-in-snow-leopard/

相关文章
相关标签/搜索