Computersnyou

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

Posted on  6/5/2012
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 
<div class="separator" style="clear: both; text-align: center;">
  <a href="http://4.bp.blogspot.com/-dTveRVZ1s4k/T82g7Sn4WuI/AAAAAAAADw0/6zYFONJtz-w/s1600/Screen+Shot+2012-06-05+at+11.30.47+AM.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: Georgia, 'Times New Roman', serif;"><img border="0" height="339" src="http://4.bp.blogspot.com/-dTveRVZ1s4k/T82g7Sn4WuI/AAAAAAAADw0/6zYFONJtz-w/s400/Screen+Shot+2012-06-05+at+11.30.47+AM.png" width="400" /></span></a>
</div>

<div>
  <span style="font-family: Georgia, 'Times New Roman', serif;"><br /></span>
</div>

<ul style="text-align: left;">
  <li>
    <span style="font-family: Georgia, 'Times New Roman', serif;">open you personal website folder&nbsp;</span>
  </li>
  <li>
    <span style="font-family: Georgia, 'Times New Roman', serif;"><?php phpinfo() ??> &nbsp;shave this code as info.php&nbsp;</span>
  </li>
  
  <li>
    <span style="font-family: Georgia, 'Times New Roman', serif;">open http://localhost/~(your username)/info.php&nbsp;</span>
  </li>
</ul>




3 : mysql with php



  • download and install mysql 
download mysql

<div style="text-align: left;">
</div>

<ul style="text-align: left;">
  <li>
    <span style="font-family: Georgia, 'Times New Roman', serif;">add mysql in your $PATH&nbsp;</span>
  </li>
  <li>
    <i><span style="font-family: Georgia, 'Times New Roman', serif;">export PATH=&#8221;/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH&#8221;&nbsp;</span></i>
  </li>
  <li>
    <span style="font-family: Georgia, 'Times New Roman', serif;">add above line in <i>~/.bashrc</i> or <i>/etc/bash_profile&nbsp;</i></span>
  </li>
  <li>
    <span style="font-family: Georgia, 'Times New Roman', serif;">source your<i> ~/.bashrc</i> or <i>/etc/bash_profile </i>file<i>&nbsp;</i></span>
  </li>
  <li>
    <i><span style="font-family: Georgia, 'Times New Roman', serif;">&nbsp;$ mysql_secure_installation</span></i>
  </li>
  <li>
    <span style="font-family: Georgia, 'Times New Roman', serif;">after installing mysql open <i>/etc/php.ini</i></span>
  </li>
  <li>
    <span style="font-family: Georgia, 'Times New Roman', serif;">uncomnnet&nbsp;; extension=msql.dll and&nbsp;;extension=php_mysqli.dll</span>
  </li>
  <li>
    <span style="font-family: Georgia, 'Times New Roman', serif;">save and restart apache&nbsp;</span>
  </li>
  <li>
    <span style="font-family: Georgia, 'Times New Roman', serif;">sudo apachectl restart&nbsp;</span>
  </li>
</ul>

<div style="text-align: left;">
  <u><span style="font-family: Georgia, 'Times New Roman', serif;">if you are getting sock error&nbsp;</span></u>
</div>

<div style="text-align: left;">
  <span style="font-family: Georgia, 'Times New Roman', serif;">change these in php.ini&nbsp;</span>
</div>

<div style="text-align: left;">
  <i><span style="font-family: Georgia, 'Times New Roman', serif;">pdo_mysql.default_socket=/tmp/mysql.sock</span></i>
</div>

<div style="text-align: left;">
  <i><span style="font-family: Georgia, 'Times New Roman', serif;">mysql.default_socket = /tmp/mysql.sock</span></i>
</div>

<div style="text-align: left;">
  <i><span style="font-family: Georgia, 'Times New Roman', serif;">mysqli.default_socket = /tmp/mysql.sock</span></i>
</div>

<div style="text-align: left;">
  <i><span style="font-family: Georgia, 'Times New Roman', serif;"><br /></span></i>
</div>

<div style="text-align: left;">
  <i><span style="font-family: Georgia, 'Times New Roman', serif;"><br /></span></i>
</div>

<div style="text-align: left;">
  <span style="font-family: Georgia, 'Times New Roman', serif;">if above info was useful to you please share and leave you feedback to us&nbsp;</span>
</div>

<div style="text-align: left;">
  <span style="font-family: Georgia, 'Times New Roman', serif;">thanks&nbsp;</span>
</div>

  • Home
  • About