Friday, March 18, 2011

How to make MySQL and PHP to Communicate in Mac?

I already explained How to make PHP and Apache to Communicate  in Mac.
Now, we will do the same with MySQL and PHP.
The default location of mysql.sock is in the /tmp/mysql.sock directory. We’ll need to change this to /var/mysql/mysql.sock as this is where PHP will look for it.
So first off, create a my.conf (or in this case my.cnf) file in your text editor and save it as my.cnf in the /etc folder with the following code:

[client]
socket = /var/mysql/mysql.sock
 
[mysqld]
socket = /var/mysql/mysql.sock

Next move mysql.sock to it’s new directory by typing the following code in a Terminal window:

$ sudo mkdir /var/mysql
$ sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock

That is pretty much.

Thursday, March 17, 2011

How to enable PHP with Apache in Mac?

1. First you have to find the location of the apache configuration file httpd.conf. It is normally found at /private/etc/apache2/httpd.conf. Find the following or similar line:

#LoadModule php5_module        libexec/apache2/libphp5.so

Uncomment the above line by removing "#", save and quit the file.

2. Restart the apache using your root access or proper privileges
$ apachectl restart

3. Create a test php file called x.php in the public folder of the server, which can be accesses through URL in the browser

$ vi /Library/WebServer/Documents/x.php
and write

4. access the file using your favorite browser.

http://localhost/x.php

It show all the configuration. Congratulations!!!

Tip: You can create soft link directly from your home folder to your web directory like:

$ ln -s /Library/WebServer/Documents htdocs