Install PHP with MacPorts on Mac Big Sur

Install MacPorts based on your mac version.
pls see https://www.macports.org/install.php

if you have already MacPorts, pls update/upgrade it:

Install PHP7.4
read: https://ports.macports.org/port/php74/

run: sudo port install php74
install some php7.4 extension: sudo port install php74-apache2handler php74-cgi php74-gd php74-curl php74-intl php74-iconv php74-gettext php74-mbstring php74-imap php74-mcrypt php74-xmlrpc php74-mysql php74-openssl php74-sockets php74-zip php74-tidy php74-opcache php74-xsl php74-sqlite php74-xdebug

Select php74 as the active PHP version:
sudo port select php php74

check:
php -v
PHP 7.4.33 (cli) (built: Oct 13 2024 09:21:46) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.33, Copyright (c), by Zend Technologies
with Xdebug v3.1.6, Copyright (c) 2002-2022, by Derick Rethans

Install Apache2
check apache2: (the default apache2 from mac)
[codesyntax lang=”bash”]

[/codesyntax]

read: https://trac.macports.org/wiki/howto/Apache2

verify the config file:
[codesyntax lang=”bash”]

[/codesyntax]

Activate apache2 :
sudo port load apache2

to remove the warning:
AH00558: httpd: Could not reliably determine the server’s fully qualified domain name, using Satrias-MacBook-Pro.local. Set the ‘ServerName’ directive globally to suppress this message
edit /opt/local/etc/apache2/httpd.conf –> should use admin to edit it
Open geany as admin via command line: sudo “/Applications/Geany.app/Contents/MacOS/geany”
then add this line:
ServerName localhost:80
then unload and load again apache2:
sudo port unload apache2
sudo port load apache2
then
[codesyntax lang=”bash”]

[/codesyntax]

Test it on the browser: http://localhost/ –> it should work

Link PHP7.4 with apache2
read: https://trac.macports.org/wiki/howto/MAMP
Go to this dir:
cd /opt/local/lib/apache2/modules
then run:
[codesyntax lang=”bash”]

[/codesyntax]

then modify /opt/local/etc/apache2/httpd.conf, so it’ll be:
DirectoryIndex index.php index.html

 

Leave a Reply

Your email address will not be published. Required fields are marked *