在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/

相關文章
相關標籤/搜索