Apache server php & mysql
Mac 已內建Apache Server
設定Apache讀取指定的資料夾
1.開啟Apache
terminal:
sudo -s
apachectl start

網頁測試(Apache預設讀取/Library/WebServer/Documents/):
http://localhost/
2.建立特定資料夾

3.於/etc/apache2/users建立username.conf檔
內容:
<Directory "/Users/username/Sites/">
AllowOverride All
Options Indexes MultiViews FollowSymLinks
Require all granted
</Directory>

4.編輯/etc/apache2/httpd.conf
將以下三行前的#刪除:
LoadModule userdir_module libexec/apache2/mod_userdir.so
Include /private/etc/apache2/extra/httpd-userdir.conf
LoadModule php7_module libexec/apache2/libphp7.so

5.編輯 /etc/apache2/extra/httpd-userdir.conf
將這行前的#刪除:
Include /private/etc/apache2/users/*.conf

6.測試可否讀取到指定的資料夾
terminal:
apachectl restart
輸入網址:
http://localhost/~username/

7.於localhost建立phpinfo.php
內容:
<?php
echo phpinfo();
?>

8.測試php運行
apachectl restart
網址輸入:
http://localhost/phpinfo.php

9.下載安裝mySQL後,確認是否可連到MySQL:
terminal:
cd /usr/local/mysql/bin
./mysql -h localhost -u root -p

設定Apache讀取指定的資料夾
1.開啟Apache
terminal:
sudo -s
apachectl start

網頁測試(Apache預設讀取/Library/WebServer/Documents/):
http://localhost/
2.建立特定資料夾

3.於/etc/apache2/users建立username.conf檔
內容:
<Directory "/Users/username/Sites/">
AllowOverride All
Options Indexes MultiViews FollowSymLinks
Require all granted
</Directory>

4.編輯/etc/apache2/httpd.conf
將以下三行前的#刪除:
LoadModule userdir_module libexec/apache2/mod_userdir.so
Include /private/etc/apache2/extra/httpd-userdir.conf
LoadModule php7_module libexec/apache2/libphp7.so

5.編輯 /etc/apache2/extra/httpd-userdir.conf
將這行前的#刪除:
Include /private/etc/apache2/users/*.conf

6.測試可否讀取到指定的資料夾
terminal:
apachectl restart
輸入網址:
http://localhost/~username/

7.於localhost建立phpinfo.php
內容:
<?php
echo phpinfo();
?>

8.測試php運行
apachectl restart
網址輸入:
http://localhost/phpinfo.php

9.下載安裝mySQL後,確認是否可連到MySQL:
terminal:
cd /usr/local/mysql/bin
./mysql -h localhost -u root -p

Comments
Post a Comment