標籤:mac os apache php53 虛擬網址
眾所周知,mac中有內建的apache
以下是關於apache的幾個命令
sudo apachectl start 開啟
sudo apachectl restart 重啟
sudo apachectl stop 停止
sudo apachectl -v 查看本機apache版本
以下是apache的設定檔的路徑
/etc/apache2/httpd.conf
理論上,在終端輸入 sudo apachectl start,輸入密碼。在瀏覽器中輸入localhost,則能顯示“It work!”字樣。
Apache的網站伺服器根目錄在/Library/WebServer/Documents。
可以使用ln -s在案頭建立軟連結~類似於windows中的捷徑
在Mac OS中一班已經有PHP了,只要添加apache對PHP的支援就行了
編輯http.conf設定檔 sudo vim /etc/apache2/http.conf
按 esc 可以進入vim的命令模式,輸入:php5/s 可以尋找到有關php5的內容
找到 #LoadModule php5_module libexec/apache2/libphp5.so,把前面的#去掉
重啟apache
sudo apachectl restart
在根目錄中寫一個phpinfo.php的檔案,裡面寫一個phpinfo()函數,這樣就能看見有關php的版本及相關資料。
看到的版本是Max系統內建的,如果需要安裝別的版本的PHP,可以使用brew命令
首先在終端輸入以下內容,來安裝brew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
繼續輸入
brew update
brew tap homebrew/dupes
brew tap homebrew/php
brew tap josegonzalez/homebrew-php
安裝PHP53
brew install php53
安裝好的php53的設定檔在/usr/local/etc/php/5.3/php.ini
由於Mac內建了php和php-fpm,因此需要添加系統內容變數PATH來替代內建PHP版本:
echo ‘export PATH="$(brew --prefix homebrew/php/php53)/bin:$PATH"‘ >> ~/.bash_profile #for php
echo ‘export PATH="$(brew --prefix homebrew/php/php53)/sbin:$PATH"‘ >> ~/.bash_profile #for php-fpm
echo ‘export PATH="/usr/local/bin:/usr/local/sbin:$PATH"‘ >> ~/.bash_profile #for other brew install soft
source ~/.bash_profile #更新配置
測試看看 php的版本
$ php -v
$ php-fpm -v
這時,如果使用phpinfo()函數顯示,顯示的版本不是php53,是因為apache設定檔中php模組的指向還是原來的那個,現在更改一下路徑
首先還是開啟設定檔sudo vim /etc/apache2/http.conf
esc 然後進入命令列模式,輸入:/php5找到php模組,更改內容成為如下
LoadModule php5_module /usr/local/opt/php53/libexec/apache2/libphp5.so
重啟apache,然後phpinfo顯示的內容就是5.3了
接下來安裝mysql,這個通過mysql官網就可以安裝了 非常方便。
接下來設定虛擬機器主機,使得輸入一個虛擬網址,可以訪問根目錄下的項目。
在終端輸入sudo vim /etc/apache2/httpd.conf 開啟Apche的設定檔
在httpd.conf中找到“#Include /private/etc/apache2/extra/httpd-vhosts.conf”,去掉前面的“#”,儲存並退出。
然後重啟Apache
輸入sudo vi /etc/apache2/extra/httpd-vhosts.conf 開啟了配置虛擬機器主機檔案
檔案中有兩個例子,可以都注釋了
然後添加
<
VirtualHost
*:80>
DocumentRoot "/Library/WebServer/Documents"#根目錄
ServerName localhost
ErrorLog "/private/var/log/apache2/localhost-error_log"
CustomLog "/private/var/log/apache2/localhost-access_log" common
</
VirtualHost
>
<
VirtualHost
*:80>
DocumentRoot "/Library/WebServer/Documents/test"#路徑改成你的專案檔,以test為例
ServerName www.test.com #虛擬網域名稱,以www.test.com為例
ErrorLog "/private/var/log/apache2/sites-error_log"
CustomLog "/private/var/log/apache2/sites-access_log" common
<
Directory
/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order deny,allow
Allow from all
</
Directory
>
</
VirtualHost
>
儲存退出。
然後修改hosts檔案,windows的話在system32下
輸入sudo vi /etc/hosts”,開啟hosts設定檔,加入127.0.0.1 www.test.com
儲存 然後重啟apache
這樣就能在瀏覽器輸入 www.test.com 訪問/Library/WebServer/Documents/test 下的項目了
在mac中配置apache+php5.3+mysql的環境,修改hosts