mac 安裝apache + php + redis

mac 版本: 10.15.1

apache

  • apache 是 mac 自帶,故不需要安裝👻
  • apache 啓動命令: sudo apachectl start

啓動後,在瀏覽器輸入 localhost ,若出現

It works!

則爲啓動成功。

  • 修改自定義工作目錄
  • apache默認的工作目錄在 /Library/WebServer/Documents
  • 若想要修改工作目錄,打開配置文件 /etc/apache2/httpd.conf

找到 DocumentRoot 這一欄
將原配置:

DocumentRoot "/Library/WebServer/Documents"
<Directory "/Library/WebServer/Documents">
    ...
</Directory>

修改爲:

DocumentRoot "自定義工作目錄"
<Directory "自定義工作目錄">
    Require all granted
    Options Indexes FollowSymLinks MultiViews
    MultiviewsMatch Any
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

其中修改的配置項 :

AllowOverride  
若配置爲None ,則.htaccess 文件配置都不會生效;
配置爲All,則會生效.htaccess配置;
若配置爲ALL,需要找到 httpd.conf 中的 mod_rewrite.so 行,去掉前面的# 【否則會出現500報錯】
  • 找到 #LoadModule php7_module libexec/apache2/libphp7.so 去掉前面的#

  • 完成上述修改後,重新啓動apache: sudo apachectl restart

安裝redis 擴展

若你需要連接redis 服務,則需要安裝redis 擴展

  • brew install autoconf

  • 下載 https://github.com/phpredis/phpredis/releases

  • 下載後解壓文件,解壓後進入文件

  • 執行phpize

  • 執行./configure

  • 執行make

  • 執行sudo make install

執行phpize時報錯:

grep: /usr/include/php/main/php.h: No such file or directory
grep: /usr/include/php/Zend/zend_modules.h: No such file or directory
grep: /usr/include/php/Zend/zend_extensions.h: No such file or directory

若是10.15版本

 csrutil status #查看SIP狀態
 #若爲 enable , 則需要 重啓MAC,一直按住 Command + R 進入Recovery 模式,在屏幕上方找到實用工具-> 打開終端,輸入:csrutil disable ; 重啓MAC;
 #此時status 爲 disable,
 xcode-select --install #若已安裝則跳過
 sudo mount -uw / #【根目錄掛載爲可讀寫】
 sudo ln -s "$(xcrun --show-sdk-path)/usr/include" /usr/include #建立軟鏈接 

安裝成功後:

  • 在 php.ini 中添加 extension=redis.so
  • 查找php.ini文件位置
php -i |grep php.ini

若只有php.ini.default 文件,則需要

sudo cp php.ini.default php.ini

查看擴展是否安裝成功

php -m | grep redis

修改後執行 sudo apachectl restart

  • 在工作目錄中新增測試文件:
sudo vi test.php 

文件中添加:

<?php phpinfo(); ?>

瀏覽器中打開 http://localhost/test
即可查詢到redis相關模塊

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章