When I do PHP, I use XAMPP to set up a development environment on Windows, then upload to Linux servers, works very well.
I'm now passing on a PHP project to a person who has a Mac so he needs a local PHP dev environment. I noticed XAMPP has a version for Mac which I will recommend.
But knowing that Mac is always a bit different, has anyone used any other easy PHP environment setup tool for the Mac, or I could even imagine that Mac solves this issue more elegantly by e.g. having a web server ready to go upon first boot etc.
What is the best way to set up a PHP development environment on a Mac?
Starting with macOS Monterey, PHP is no longer included in a default installation of the system. If you want to use PHP on macOS Monterey, you must first install PHP. The following instructions show the Terminal commands to install PHP.
I personally use Macports to setup the PHP Development environment. My guess is this is not the best solution right now since it requires a bit more configuration then a complete solution like Xampp but it gives you a bit more flexibility.
Macports
Once you have installed this (don't forget to install the XCode unix tools first) you can easily install packages. For instance:
sudo port install apache2
sudo port install php5 +apache2
sudo port install mysql5
You can also easily add modules:
sudo port install php5-curl
I have setup Apache in the following way (Found this on stackoverflow) so I don't have to keep changing my apache conf file everytime I start a project.
NameVirtualHost *:80
<VirtualHost *:80>
ServerName *.dev
VirtualDocumentRoot "/Users/les/Documents/workspace/%-2+/site/html"
</VirtualHost>
When starting a new project I add this to my /etc/hosts file and restart apache:
127.0.0.1 merchant.dev
Which will effectively run scripts in /Users/les/Documents/workspace/merchant/site/html
Lastly, I use some handy aliasses in my .bash_profile
alias ap='sudo /opt/local/apache2/bin/apachectl'
alias apconfig='mate /opt/local/apache2/conf/httpd.conf'
alias hostconfig='mate /etc/hosts'
alias dsclean='find . -name ".DS_Store" -depth -exec rm {} \;'
mate is a shortcut created by textmate (really useful general purpose texteditor for mac) dsclean is just something to keep our svn repositories clean of mac litter.
If you want a easy solution I would go with MAMP. It is a simple webserver installer so most of the time you don't really have to configure anything: MAMP
If you need a userguide for installing MAMP you can find it here: Userguide
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With