Mac System
MacOS High Sierra
Version 10.13.4
Mac system comes with Apache, config file in/etc/apache2/httpd.conf
Although I installed the php72
Order with Brew Install PHP72
Input Php-v
Show PHP 7.2.9 (CLI) (Built:aug 2018 02:08:27) (NTS)
But in the local project code, PHPINFO ()
The php5.6.29 version is always displayed.
At first, I followed the online tutorial to modify
sudo vim/etc/apache2/httpd.conf
Note: #LoadModule php5_module libexec/apache2/libphp5.so
Increase:
LoadModule php7_module /usr/local/opt/php/lib/httpd/modules/libphp7.so<FilesMatch \.php$> SetHandler application/x-httpd-php</FilesMatch>
Will error.
Then I use the Brew install HTTPD command
Reinstall HTTPD 2.4.3
After that, there is a new Apache configuration file
/usr/local/etc/httpd/httpd.conf
New homemade Apache, port is 8080
Modify Httpd.conf
ServerName localhost:8080
The browser opens and appears.
localhost:8080
But the original local project is written phpinfo still show, php5.6.29
Restart: sudo apachectl restart always error.
The original Apache cannot be stopped.
Adopt kill-9 ... Command stop port, also invalid. Toss for a few days.
Later found the method, with the command.
sudo launchctl unload-w/system/library/launchdaemons/org.apache.httpd.plist 2>/dev/null
Stopped the original Apache.
And then come back.
- Re-install httpd
brew reinstall httpd
Re-install PHP72
brew install php72 --with-httpd
brew upgrade php72 --with-httpd
But is there a difference here,--with--apache, or--with-httpd? has yet to be studied.
Upgrade PHP.
macdeMacBook-Pro:Documents mac$ brew upgrade php72 --with--apache==> Upgrading 1 outdated package, with result:php 7.2.8 -> 7.2.9_2... (一大段略)==> phpTo enable PHP in Apache add the following to httpd.conf and restart Apache: LoadModule php7_module /usr/local/opt/php/lib/httpd/modules/libphp7.so <FilesMatch \.php$> SetHandler application/x-httpd-php </FilesMatch>Finally, check DirectoryIndex includes index.php DirectoryIndex index.php index.htmlThe php.ini and php-fpm.ini file can be found in: /usr/local/etc/php/7.2/To have launchd start php now and restart at login: brew services start phpOr, if you don‘t want/need a background service you can just run:
Now it's finally clear.
The new configuration file will be modified two places and then restarted:
ServerName localhost:8080
LoadModule Rewrite_module lib/httpd/modules/mod_rewrite.so
macdemacbook-pro:~ mac$ sudo apachectl start
HTTPD (PID 18083) already running
2. Then change the port number and the default root directory.
In order to be able to switch PHP
Create a soft link first.
Ln-s/usr/local/php5-5.6.29-20170114-210819/libphp5.so/usr/local/lib/libphp5.so
Ln-s/usr/local/opt/php/lib/httpd/modules/libphp7.so/usr/local/lib/libphp7.so
Open Edit Configuration
OPEN-E/usr/local/etc/httpd/httpd.conf
There are several places to modify:
`
ServerName localhost
DocumentRoot "/users/mac/data"
<directory "/users/mac/data" >
...
AllowOverride All
...
#LoadModule php5_module/usr/local/php5-5.6.29-20170114-210819/libphp5.so
#LoadModule php7_module/usr/local/opt/php/lib/httpd/modules/libphp7.so
#Brew PHP LoadModule for sphp
switcher
#LoadModule php5_module/usr/local/lib/libphp5.so
LoadModule php7_module/usr/local/lib/libphp7.so
<ifmodule dir_module>
DirectoryIndex index.php index.html
</IfModule>
<filesmatch .php$>
SetHandler application/x-httpd-php
</FilesMatch>
`
Sphp is a tool for switching PHP.
Let's switch manually.
To restart after each modification to httpd.conf
sudo apachectl restart
- Next is to establish a virtual site local domain name.
Open the httpd-vhost.conf sentence. Or
Plus: include/usr/local/etc/httpd/extra/httpd-vhosts.conf
Copy the original httpd-vhost.conf to a new location.
Cp/etc/apache2/extra/httpd-vhosts.conf/usr/local/etc/httpd/extra/httpd-vhosts.conf
In this way, the original/etc/apache2/will not be the tube.
The above reference article:
79057647
Thanks here!
If you also encounter this problem has not come out, please leave a message to contact me.
Brew installation and configuration for Apache under Mac