Get Apache, MySQL, PHP With mcrypt and phpMyAdmin working on OSX 10.9 Mavericks

One of the best thing about OSX 10.9 Mavericks for web developer is Apache and PHP already installed. You do not have to start the Apache – its automatically starts when mac starts.

Apache
Even though you want to start manually

sudo apachectl start

to stop it

sudo apachectl stop

to restart it

sudo apachectl restart

To find the Apache version

httpd -v

Now you can access the it by http://localhost.

The document root is /Library/WebServer/Documents/. But I would suggest you use User Level Root. First create folder “Sites” in your home folder. Now go to /etc/apache2/users/

cd /etc/apache2/users/

Suppose you username is “zakir”. You can found your name

whoami

Now create a conf file in /etc/apache2/users/

sudo nano zakir.conf

add the following to zakir.conf

<Directory "/Users/zakir/Sites/">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
</Directory>

Change permission of the zakir.conf

sudo chmod 644 zakir.conf

Now restart the apache

sudo apachectl restart

Now you access it via http://localhost/~zakir/. Now you need change httpd.conf file to allow .htaccess file.

sudo nano /etc/apache2/httpd.conf

Find the line . Change value of AllowOverride To All.

Permission of the Sites folder

sudo chmod go-rwx Sites
sudo chmod go+x Sites
sudo chgrp -R _www Sites
sudo chmod -R go-rwx Sites
sudo chmod -R g+rx Site

If you have mutiple website ie mutiple folders then do the following after creating each folder

sudo chown -R username ~/Sites/folder
sudo chmod go-rwx ~/Sites/folder
sudo chmod go+x ~/Sites/folder
sudo chgrp -R _www ~/Sites/folder
sudo chmod -R go-rwx ~/Sites/folder
sudo chmod -R g+rx ~/Sites/folder

In this way only you can edit the files and others can not edit files. Apache can also run files. To check permission of a file use following line

stat -f %Mp%Lp file

PHP
Open httpd.conf file

sudo nano /etc/apache2/httpd.conf

Uncomment “LoadModule php5_module libexec/apache2/libphp5.so” line.
Now restart the apache

sudo apachectl restart

Install mcrypt for PHP
First install xcode and xcode for command line see http://blog.jambura.com/2013/02/19/setup-homebrew-perlbrew-ruby-rvm-perl-cpanm-nginx-in-mountain-lion/ for details.

Create mcrypt folder in your home folder.

cd ~
mkdir mcrypt
cd mcrypt

Download libmcrypt from http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz/download and download php source http://museum.php.net/php5/php-5.4.17.tar.gz. Copy the files to mcrypt folder.
Untar the files

tar -zxvf libmcrypt-2.5.8.tar.gz
tar -zxvf php-5.4.17.tar.gz

Configuring libmcrypt

cd libmcrypt-2.5.8
./configure
make
sudo make install

Compile mcrypt php Extension

cd ../php-5.4.17/ext/mcrypt/
make
sudo make install

You will see this msg

Installing shared extensions:     /usr/lib/php/extensions/no-debug-non-zts-20100525/

Copy php.ini from /etc

sudo cp /etc/php.ini.default /etc/php.ini
sudo chmod u+w  /etc/php.ini

Open /etc/php.ini and add the line below at the end

extension=mcrypt.so

Now restart the apache

sudo apachectl restart

MySQL
First download dmg file from http://dev.mysql.com/downloads/mysql/. Install Install all 3…

mysql5.6.xxx.pkg
MySQLstartupitem.pkg
MySQLPrefPane

Now got System Preference and then got mysql then start mysql
null

now set mysql password for mysql – I liked to set password blank

/usr/local/mysql/bin/mysqladmin -u root password ''

Fix the 2002 socket error

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

Download phpMyAdmin, the zip package and move the folder with its contents into the ~/Sites/phpmyadmin folder.

Make the config folder and Change the permissions

mkdir ~/Sites/phpmyadmin/config
chmod o+w ~/Sites/phpmyadmin/config

Go to http://localhost/~zakir/phpmyadmin/setup/. Click new server, Switch to the Authentication tab and set the local mysql root user and the password. Make sure you click on save, then a config.inc.php is now in the /config directory of phpmyadmin directory, move this file to the root level of /phpmyadmin and then remove the now empty /config directory.

About Zakir Hyder

This entry was written by .

17. January 2014 by Zakir Hyder
Categories: Apple, Server Management, Web Development | Tags: , , , , , , , , , , , , | Comments

Comments

  1. […] One of the best thing about OSX 10.9 Mavericks for web developer is Apache and PHP already installed. You do not have to start the Apache – its automatically starts when mac starts. Apache Even though you want to start…  […]