setting up apache and php with mysql in mac [ tutorial ]

mac os x ( assuming that you have mac 10.6.X or later .. tutorial on lion 10.7.4 ) comes with the bundle of apache and php pre-preinstalled .. just you have to trigger apache to serve php and php to process request , there are mamp and xampp is available which come pre configured bundle but if you dont want to use any external software then you can configure your mac to process php



external softwares
mamp : http://www.mamp.info/en/index.html
xampp : http://www.apachefriends.org/en/xampp-macosx.html

okay , lets configure mac for php ( i will be using textmate as a text editor , mate is symlink of textmate  )

1 :  configure apache to server php 


  • open terminal 
  •  $ mate /etc/apache2/httpd.conf
  • find ( ⌘ + f ) and search for php 
  • uncomment that line and save conf file 

2 :  now this time configure php 

  • open terminal 
  • sudo cp /etc/php.ini.default /etc/php.ini
  • that command will copy default ini file as your current php config 
  • turn error reporting on in php 
  • mate /etc/php.ini
  • and search error and change according to your needs 
  • now open system preferences and under sharing menu check web sharing 

  • open you personal website folder 
  •  shave this code as info.php 
  • open http://localhost/~(your username)/info.php 




3 : mysql with php



  • download and install mysql 
download mysql

  • add mysql in your $PATH 
  • export PATH=”/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH” 
  • add above line in ~/.bashrc or /etc/bash_profile 
  • source your ~/.bashrc or /etc/bash_profile file 
  •  $ mysql_secure_installation
  • after installing mysql open /etc/php.ini
  • uncomnnet ; extension=msql.dll and ;extension=php_mysqli.dll
  • save and restart apache 
  • sudo apachectl restart 
if you are getting sock error 
change these in php.ini 
pdo_mysql.default_socket=/tmp/mysql.sock
mysql.default_socket = /tmp/mysql.sock
mysqli.default_socket = /tmp/mysql.sock


if above info was useful to you please share and leave you feedback to us 
thanks