MAC apache 配置记录

mac自带的apache和php

查看系统预装的apache版本(功能简单,模块少,apxs、apxs2也没有,定制也麻烦):

sudo apachectl -version

Apache目录:

快捷键为:command+shift+G),输入地址:/private/etc/apache2

默认web目录:(认情况下我们是没有读写权限的,需开自行添加当前账号进去启用读写权限)

/Library/WebServer

编译安装的模块目录:

/usr/libexec/apache2

apache 日志位置

/private/var/log/apache2/error_log

                                       access_log

相关命令:

sudo apachectl start

sudo apachectl restart

sudo apachectl stop

sudo apachectl -v

Server version: Apache/2.4.34 (Unix)

Server built:   Feb 22 2019 20:20:11

apachectl  可以查看到apache状态,有错误的时候可以看到错误问题

httpd: Syntax error on line 136 of /private/etc/apache2/httpd.conf: Cannot load libexec/apache2/mod_proxy_fcgi.so into server: dlopen(/usr/libexec/apache2/mod_proxy_fcgi.so, 10): Symbol not found: _proxy_module\n  Referenced from: /usr/libexec/apache2/mod_proxy_fcgi.so\n  Expected in: flat namespace\n in /usr/libexec/apache2/mod_proxy_fcgi.so

参考:

https://blog.csdn.net/qq_37486501/article/details/79999059

https://www.cnblogs.com/xiaovw/p/8854896.html

自行安装apache

brew install apache2

Updating Homebrew...

==> Auto-updated Homebrew!

Updated 1 tap (homebrew/core).

==> Updated Formulae

asio                clamav              globus-toolkit      libgcrypt           libu2f-server       ponyc               tarantool           tcpflow             tiny-fugue          uwsgi

bro                 collectd            joplin              libre               mktorrent           ruby                tcl-tk              tdlib               trafficserver       zbackup

caf                 gammu               juise               libslax             nordugrid-arc       sofia-sip           tcpdump             tinc                ttyd                zim

==> Deleted Formulae

thc-pptp-bruter                                                     tlsdate                                                             tn5250

==> Downloading https://homebrew.bintray.com/bottles/httpd-2.4.41.mojave.bottle.tar.gz

Already downloaded: /Users/root/Library/Caches/Homebrew/downloads/898f045ab4730cb456c8e59ab816d229d44e997c03804875384f9bee5054970e--httpd-2.4.41.mojave.bottle.tar.gz

==> Pouring httpd-2.4.41.mojave.bottle.tar.gz

==> Caveats

DocumentRoot is /usr/local/var/www.

The default ports have been set in /usr/local/etc/httpd/httpd.conf to 8080 and in

/usr/local/etc/httpd/extra/httpd-ssl.conf to 8443 so that httpd can run without sudo.

To have launchd start httpd now and restart at login:

  brew services start httpd

Or, if you don't want/need a background service you can just run:

  apachectl start

==> Summary

?  /usr/local/Cellar/httpd/2.4.41: 1,652 files, 27.2MB

==> `brew cleanup` has not been run in 30 days, running now...

brew info apache2

httpd: stable 2.4.41 (bottled)

Apache HTTP server

https://httpd.apache.org/

/usr/local/Cellar/httpd/2.4.41 (1,652 files, 27.2MB) *

  Poured from bottle on 2019-09-01 at 14:41:37

From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/httpd.rb

==> Dependencies

Required: apr , apr-util , brotli , nghttp2 , openssl , pcre

==> Caveats

DocumentRoot is /usr/local/var/www.

The default ports have been set in /usr/local/etc/httpd/httpd.conf to 8080 and in

/usr/local/etc/httpd/extra/httpd-ssl.conf to 8443 so that httpd can run without sudo.

To have launchd start httpd now and restart at login:

  brew services start httpd

Or, if you don't want/need a background service you can just run:

  apachectl start

==> Analytics

install: 14,189 (30 days), 35,590 (90 days), 176,999 (365 days)

install_on_request: 11,067 (30 days), 28,939 (90 days), 136,891 (365 days)

build_error: 0 (30 days)

which httpd

/usr/local/bin/httpd

brew reinstall httpd

==> Reinstalling httpd 

==> Downloading https://homebrew.bintray.com/bottles/httpd-2.4.41.mojave.bottle.tar.gz

Already downloaded: /Users/root/Library/Caches/Homebrew/downloads/898f045ab4730cb456c8e59ab816d229d44e997c03804875384f9bee5054970e--httpd-2.4.41.mojave.bottle.tar.gz

==> Pouring httpd-2.4.41.mojave.bottle.tar.gz

==> Caveats

DocumentRoot is /usr/local/var/www.

The default ports have been set in /usr/local/etc/httpd/httpd.conf to 8080 and in

/usr/local/etc/httpd/extra/httpd-ssl.conf to 8443 so that httpd can run without sudo.

To have launchd start httpd now and restart at login:

  brew services start httpd

Or, if you don't want/need a background service you can just run:

  apachectl start

==> Summary

?  /usr/local/Cellar/httpd/2.4.41: 1,652 files, 27.2MB

http://127.0.0.1:8080/

/usr/local/lib/httpd/modules/libphp5.6.40.so

sudo brew services start httpd

Warning: Taking root:admin ownership of some httpd paths:

  /usr/local/Cellar/httpd/2.4.41/bin

  /usr/local/Cellar/httpd/2.4.41/bin/httpd

  /usr/local/opt/httpd

  /usr/local/opt/httpd/bin

  /usr/local/var/homebrew/linked/httpd

This will require manual removal of these paths using `sudo rm` on

brew upgrade/reinstall/uninstall.

==> Successfully started `httpd` (label: homebrew.mxcl.httpd)

编辑/usr/local/etc/httpd/httpd.conf 

搜索 #LoadModule php5_module。去掉#

LoadModule php5_module /usr/local/lib/httpd/modules/libphp5.6.40.so

告诉Apache使用PHP 5.6来处理PHP请求。修改这个位置可以修改php版本。

#‎⁨LoadModule php7_module /usr⁩/local/⁨Cellar⁩/php⁩/7.3.9/lib⁩/⁨httpd⁩/⁨modules⁩/libphp7.so

你也必须明确地设置PHP的目录索引,所以搜索这个块:

<IfModule dir_module>

DirectoryIndex index.html

</IfModule>

并用此替换它:

<IfModule dir_module>

DirectoryIndex index.php index.html

</IfModule>

添加:

AddType application/x-httpd-php .php .php7 .php5

#<FilesMatch \.php$>

#SetHandler application/x-httpd-php

#</FilesMatch>

保存文件并停止阿帕奇然后重新启动

找到下面的并去掉#:

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

<Directory />
     AllowOverride none
     Require all granted
     Allow from all
</Directory>
DocumentRoot "/Library/WebServer/Documents"
<Directory "/Library/WebServer/Documents">
    Options Indexes FollowSymLinks Multiviews
    MultiviewsMatch Any
    AllowOverride All
    Require all granted
</Directory>


 

参考:

https://blog.csdn.net/feiwutudou/article/details/79057647

https://www.jianshu.com/p/a617691a7f4f

开启rewrite重写

开启Rewrite模块
LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so

<Directory />

Options FollowSymLinks

AllowOverride None(修改为AllowOverride All)

</Directory>

<Directory "/var/orioner">

Options Indexes FollowSymLinks MultiViews

AllowOverride None(修改为AllowOverride All)

Order allow,deny

allow from all

</Directory>

修改.htaccess文件属性  chmod -R 777 .htaccess

发布了69 篇原创文章 · 获赞 31 · 访问量 8万+

猜你喜欢

转载自blog.csdn.net/yyws2039725/article/details/100159771