Apache

Mac 自帶Apache和PHP

默認(rèn)路勁

  • Apache服務(wù)器默認(rèn)的web根目錄在: /Library/WebServer/Documents
  • Apache的配置文件在: /etc/apache2

常用命令

  • 開啟Apache: sudo apachectl start
  • 關(guān)閉Apache: sudo apachectl stop
  • 重啟Apache: sudo apachectl restart
  • 查看Apache版本: sudo apachectl -v

在terminal運(yùn)行Apache啟動(dòng)命令

    sudo apachectl start

啟動(dòng)瀏覽器,輸入http://localhost
發(fā)現(xiàn) It works!

Apache 啟動(dòng)成功,這時(shí)候使用的是默認(rèn)服務(wù)器位置

配置實(shí)現(xiàn)個(gè)人服務(wù)器

  1. 創(chuàng)建個(gè)人服務(wù)器目錄
    在自己用戶名下創(chuàng)建一個(gè)sites文件夾

  2. 找到配置文件給原來httpd.conf備份
    進(jìn)入Apache的配置文件:cd /etc/apache2
    備份Apache的配置文件:sudo cp httpd.conf httpd.conf.bak

    如果遇到錯(cuò)誤想恢復(fù)配置文件:sudo cp httpd.conf.bak httpd.conf

  3. 修改配置文件
    進(jìn)入/etc/apache2目錄下:sudo vim httpd.conf

    • 修改服務(wù)器默認(rèn)路徑
      查找DocumentRoot 將圖片中紅框路徑 替換為sites文件路徑
      添加黃顏色框的 Indexes
  • 加載php模塊
    查找php 將#刪除


保存后退出:wq 不保存退出q!

  1. 備份php配置文件
    進(jìn)入/etc目錄下:cd /etc
    備份php配置文件:sudo cp php.ini.default php.ini

  2. 重啟Apache
    sudo apachectl -k restart

1、警告
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using MitakedeMacBook-Pro.local. Set the 'ServerName' directive globally to suppress this message

#ServerName www.example.com:80
改為ServerName localhost:80

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容