I mainly do web development on my 15 in Macbook Pro. Mac runs on base Unix foundation so mainly you could install almost all Linux/Unix software on Mac very easily.
Mac OS X comes by default with Apache Web Server and PHP. In this tutorial we will go over steps on how to enable those on Mac.
Let’s get started:
Enable Apache Web Server
Step-1
Open terminal App and run below command:
apachectl start
Step-2
Open browser and check with URL: http://localhost
Enable PHP Module and verify Perl module
Step-1
Open Terminal
App. Mac OS X comes by default with Perl library
. Just type below commands to check Perl and PHP Setup.
bash-3.2# which perl /usr/bin/perl bash-3.2# pwd /etc/apache2 bash-3.2# ls -ltr total 120 -rw-r--r-- 1 root wheel 53258 Sep 9 2014 mime.types -rw-r--r-- 1 root wheel 13077 Sep 9 2014 magic drwxr-xr-x 4 root wheel 136 Sep 9 2014 original drwxr-xr-x 14 root wheel 476 Sep 9 2014 extra drwxr-xr-x 3 root wheel 102 Sep 9 2014 other -rw-r--r-- 1 root wheel 20786 Sep 9 2014 httpd.conf drwxr-xr-x 4 root wheel 136 May 24 16:21 users -rw-r--r-- 1 root wheel 20786 Jun 9 13:55 httpd.conf.bak bash-3.2# vi httpd.conf
Step-2
Open file httpd.conf
file. You may use any Text Editor
also.
Uncomment the following line (remove #): LoadModule php5_module libexec/apache2/libphp5.so
Step-3
Restart Apache Web Server:
apachectl restart
Step-4
- Find
DocumentRoot
fromhttpd.conf
file. In my case it’s/Users/crunchify/Documents/Blogs/MAMP
as I’m using MAMP on my Mac. - You may have diff folder something like
/Library/WebServer/Documents/
. - Create below file
crunchify-php-on-mac.php
under your DocumentRoot folder. - If you don’t see folder
Web Server
then just create it 🙂
<html> <head> <title>PHP Test</title> </head> <body> <?php echo '<p>Hello World - PHP Testcase on Mac OS X by Crunchify.com...</p><br>Have a fun.. Enjoy..'; ?> </body> </html>
Step-5
Now visit this URL: http://localhost/crunchify-php-on-mac.php
and you should see php file loaded successfully on browser.
How to Kill Apache httpd process on Mac?
Just incase if you need to kill apache httpd process on Mac then you could use below commands.
sudo killall httpd sudo launchctl unload /System/Library/LaunchDaemons/org.apache.httpd.plist
Enjoy and Happy coding…