Switching php version for M1/Intel MACs
$ sphp phpversion, e.g.:
sphp 7.4
xcode-select --install
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
sudo apachectl stop
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist 2>/dev/null
and install HomeBrew Apache version
brew install httpd
test installation: open http://localhost:8080 in browser.
To restart Apache:
breq services restart apache
Other control options (start/stop):
brew services stop httpd
brew services start httpd
You need to install php-fpm version to replace too slow standard php 7.3 installation which called by Apple "deprecated" At first, add repository
brew tap shivammathur/php
and install all php versions:
brew install shivammathur/php/[email protected]
brew install shivammathur/php/[email protected]
brew install shivammathur/php/[email protected]
brew install shivammathur/php/[email protected]
brew install shivammathur/php/[email protected]
brew install shivammathur/php/[email protected]
brew install shivammathur/php/[email protected]
brew install shivammathur/php/[email protected]
brew install shivammathur/php/[email protected]
You need to know that 5.6-7.2 versions are deprecated and may cause some errors, but they are need to launch old sites.
ini files are located at:
/usr/local/etc/php/5.6/php.ini
/usr/local/etc/php/7.0/php.ini
/usr/local/etc/php/7.1/php.ini
/usr/local/etc/php/7.2/php.ini
/usr/local/etc/php/7.3/php.ini
/usr/local/etc/php/7.4/php.ini
/usr/local/etc/php/8.0/php.ini
/usr/local/etc/php/8.1/php.ini
/usr/local/etc/php/8.2/php.ini
/opt/Homebrew/etc/php/5.6/php.ini
/opt/Homebrew/etc/php/7.0/php.ini
/opt/Homebrew/etc/php/7.1/php.ini
/opt/Homebrew/etc/php/7.2/php.ini
/opt/Homebrew/etc/php/7.3/php.ini
/opt/Homebrew/etc/php/7.4/php.ini
/opt/Homebrew/etc/php/8.0/php.ini
/opt/Homebrew/etc/php/8.1/php.ini
/opt/Homebrew/etc/php/8.2/php.ini
You need add modules to httpd.conf after LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so
(php7.4 as a standard)
#LoadModule php5_module /usr/local/opt/[email protected]/lib/httpd/modules/libphp5.so
#LoadModule php7_module /usr/local/opt/[email protected]/lib/httpd/modules/libphp7.so
#LoadModule php7_module /usr/local/opt/[email protected]/lib/httpd/modules/libphp7.so
#LoadModule php7_module /usr/local/opt/[email protected]/lib/httpd/modules/libphp7.so
#LoadModule php7_module /usr/local/opt/[email protected]/lib/httpd/modules/libphp7.so
LoadModule php7_module /usr/local/opt/[email protected]/lib/httpd/modules/libphp7.so
#LoadModule php_module /usr/local/opt/[email protected]/lib/httpd/modules/libphp.so
#LoadModule php5_module /opt/homebrew/opt/[email protected]/lib/httpd/modules/libphp5.so
#LoadModule php7_module /opt/homebrew/opt/[email protected]/lib/httpd/modules/libphp7.so
#LoadModule php7_module /opt/homebrew/opt/[email protected]/lib/httpd/modules/libphp7.so
#LoadModule php7_module /opt/homebrew/opt/[email protected]/lib/httpd/modules/libphp7.so
#LoadModule php7_module /opt/homebrew/opt/[email protected]/lib/httpd/modules/libphp7.so
LoadModule php7_module /opt/homebrew/opt/[email protected]/lib/httpd/modules/libphp7.so
#LoadModule php_module /opt/homebrew/opt/php/lib/httpd/modules/libphp.so
Search for the block
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
and replace it with
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
curl -L https://raw.githubusercontent.com/vadimbk/sphp/main/sphp > /opt/homebrew/bin/sphp
chmod +x /opt/homebrew/bin/sphp
curl -L https://raw.githubusercontent.com/vadimbk/sphp/main/sphp > /usr/local/bin/sphp
chmod +x /usr/local/bin/sphp
Add info.php to Apache root directory
printf "<?php\nphpinfo();\n?>" > /opt/homebrew/var/www/info.php
printf "<?php\nphpinfo();\n?>" > /usr/loca/var/www/info.php
And run the test - open in browser
http://localhost:8080/info.php
You should see an phpinfo() page
Changing a version and re-test:
sphp 5.6
Refresh phpinfo window (Cmd-R)