Mac Development System With MacPorts
This page descibes how to set up a Mac to be a local development host server
Note and warning for all macOS upgrades
This usually will break your current macports!
Follow the instructions on macports.org carefully 😁
I posted a note on stackoverflow.com about my experience.
Updated April 2025 jonnyb - now running PHP8.3 and 7.4 for Tiki 22 On Mac OS 14.7 Sonoma
Mostly following this page
Basics
- Download MacPort
- turn off web sharing in system prefs > Sharing
- Note: On Lion, it won't appear in the list at all. Alain Désilets found he had to disable it with a launchctl command (forget the exact command)
- install Xcode
- install the XCode command line tools as follows
- Start XCode, then Preferences > Downloads > Command Line Tools > install.
- Start a new Terminal window (to make sure the environment changes made by XCode are in effect), and execute the following commands:
Install Apache 2
Copy to clipboard
xcodebuild -license sudo port selfupdate sudo port upgrade outdated #### apache sudo port install apache2 sudo port load apache2 sudo apachectl start
PHP and Apache
PHP 8.x
Install PHP 8.x (8.3 for example)
Copy to clipboard
sudo port install php83-{apache2handler,calendar,curl,gd,gettext,iconv,intl,mbstring,mcrypt,mysql,opcache,openssl,posix,sockets,sodium,sqlite,xdebug,zip} sudo port select php php83 sudo cp /opt/local/etc/php82/php.ini-development /opt/local/etc/php83/php.ini # or php.ini-production sudo /opt/local/bin/apxs -a -e -n "php" mod_php83.so /opt/local/sbin/apachectl -t # check apache config sudo apachectl restart # check php php -v php74 -v # still there as a fallback? # You may need to add this line to /opt/local/apache2/conf/httpd.conf Include conf/extra/mod_php83.conf # and comment out the php7x and php5x LoadModule and Include lines # also needed to edit in php.ini pdo_mysql.default_socket=/opt/local/var/run/mysql57/mysqld.sock # and (for debug 3) [xdebug] xdebug.mode=debug xdebug.start_with_request=yes
PHP 7.x
[+]PHP 5.x
[+]MySql
Install MySql 5
Copy to clipboard
sudo port install mysql5-server sudo port load mysql5-server sudo apachectl restart sudo -u _mysql mysql_install_db5 mysql N.B. On ML I got: mysql: command not found I had to add /opt/local/lib/mysql5/bin to my path (using "export PATH=/opt/local/bin:/opt/local/sbin:/opt/local/lib/mysql5/bin:$PATH" in ~/.profile) mysqlstart See additions to .profile, you need to run "alias mysqlstart='sudo /opt/local/share/mysql5/mysql/mysql.server start'" for this to work. sudo /opt/local/lib/mysql5/bin/mysql_secure_installation mysqladmin -u root -p variables # look for config location sudo cp /opt/local/share/mysql5/mysql/my-medium.cnf /opt/local/my.cnf
- then edit /opt/local/my.cnf and add (in the relevant sections)
my.cnf
Copy to clipboard
[client] default-character-set=utf8 [mysqld] default-character-set=utf8 default-collation=utf8_general_ci character-set-server=utf8 collation-server=utf8_general_ci init-connect='SET NAMES utf8'
Start MySql and test again
Copy to clipboard
mysqlstart mysql -u root -p mysqladmin -u root -p variables sudo /opt/local/share/mysql5/mysql/mysql.server restart mysqladmin -u root -p variables sudo apachectl restart sudo port install php56-mysql sudo apachectl restart
Extras goodies
Copy to clipboard
sudo port install phpMyAdmin +php56 * Note: This will install phpmyadmin in /opt/local/www, which is different from the default DocumentRoot of apache (/opt/local/apache2/htdocs). So you will have to add the following to your httpd.conf file (or put it in a file that you include at the end of httpd.conf) <Directory "/opt/local/www/phpmyadmin/"> Options Indexes MultiViews AllowOverride None Order allow,deny Allow from all </Directory> Alias /phpmyadmin/ "/opt/local/www/phpmyadmin/" sudo apachectl restart sudo port install subversion sudo port install freetype # needed by captcha # sudo port install Pallet # GUI for macports (don't bother, not very reliable sadly) # to get memcache (needs memcached running) to work do this memcached -d # and test with telnet 127.0.0.1 11211 # to get memcached to run at startup do sudo port load memcached # macports finally has Elasticsearch, and it will install openjdk11 for you as well sudo port install elasticsearch # and to start it at boot sudo port load elasticsearch # and kibana? sudo port install kibana sudo port load kibana # then try this to check it works curl -XGET "http://localhost:9200/_cluster/health?pretty"
Copy to clipboard
#### additions to .profile export PATH=/opt/local/bin:/opt/local/sbin:/opt/local/lib/mysql5/bin:/opt/local/apache2/bin:$PATH alias apache2ctl=apachectl # not needed with path above alias php=php56 # not needed with path above alias mysqlstart='sudo /opt/local/share/mysql5/mysql/mysql.server start'