mac上brew安装Apache+MySQL+PHP7

MySQL和PHP很好装,装好可以直接用

brew install mysql@5.6
brew install php@7.2

vim ~/.bash_profile可以配置php环境变量

export PATH="/usr/local/opt/php@7.2/bin:$PATH"
export PATH="/usr/local/opt/php@7.2/sbin:$PATH"

安装配置Apache稍许麻烦一些

brew install httpd

然后配置(去掉注释或添加注释)

Include /usr/local/etc/httpd/extra/httpd-vhosts.conf

LoadModule php7_module /usr/local/Cellar/php@7.2/7.2.18/lib/httpd/modules/libphp7.so

AddHandler application/x-httpd-php .php

ServerName localhost:80

Listen 80

#伪静态配置
LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so

在extra/httpd-vhosts.conf配置虚拟主机

<VirtualHost *:80>
    ServerName xxx
    DocumentRoot xxx
    <Directory "xxx">
        DirectoryIndex index.html index.php
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog "/usr/local/var/log/httpd/error_log"
    CustomLog "/usr/local/var/log/httpd/access_log" common

    RewriteEngine On

    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ https://%1$1 [L,R=permanent]

    RewriteCond %{HTTP:X-Forwarded-Proto} =http
    RewriteRule .* https://%{HTTP:Host}%{REQUEST_URI} [L,R=permanent]

    RewriteCond "%{DOCUMENT_ROOT}%{REQUEST_FILENAME}" !-f
    RewriteCond "%{DOCUMENT_ROOT}%{REQUEST_FILENAME}" !-d
    RewriteRule "^" "/index.php" [L]
</VirtualHost>

最后重启Apache

sudo apachectl restart

Apache开机自启

brew services start httpd
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容