Computersnyou

How to setup Apache PHP and MySQL in MacOS X 10.10 Yosemite [ Updated ]

Posted on  7/11/2014

Upgraded to Yosemite , great . now lets see how to setup Apache webserver with PHP and MySQL . unlike 10.7 Lion or 10.6 there is no prefrence pane option to turn on Apache . but don’t worry MacOSX Yosemite comes with Apache and you can turn on it using Terminal . Okay lets see how to setup Apache PHP and MySQL setup in Mac OS X Yosemite .

apachectl -v && php -v
apache and php with yosemite
apache and php with yosemite

setup apache

open terminal and type

sudo apachectl start 

now open your favourite browser and browse to http://localhost
you will see default apache page

default apache page in MacOX yosemite
default apache page in MacOX yosemite

Lets setup user-dir for per user

I am going to use nano in this guide feel free to use any of your favourite editor .

  • Enable mod_authz_core, mod_authz_host, mod_userdir and mod_userdir.so modules
sudo nano /etc/apache2/httpd.conf

Uncomment These Three Modules For Now ( Remove “#” sign from the starting of line if “#” is present )

LoadModule authn_core_module libexec/apache2/mod_authn_core.so
LoadModule authz_host_module libexec/apache2/mod_authz_host.so 
LoadModule userdir_module libexec/apache2/mod_userdir.so 

You can dump list of all Loaded Modules using sudo apachectl -M command .

Enable User Dir IN MacOSX
Enable User Dir IN MacOSX
user-dir module
user-dir module

Then Navigate to bottom of the file , and uncomment following line

Include /private/etc/apache2/extra/httpd-userdir.conf
user_dir apache
user_dir apache

then open /etc/apache2/extra/httpd-userdir.conf

sudo nano /etc/apache2/extra/httpd-userdir.conf  

and uncomment following line

Include /private/etc/apache2/users/*.conf
enabling user dir from extra conf
enabling user dir from extra conf

Okay Now Setup your user.conf

sudo nano /etc/apache2/users/YOURUSERNAME.conf
<Directory /Users/*/Sites>
 DirectoryIndex index.html index.php index index.html default.html default.htm
 AllowOverride FileInfo AuthConfig Limit Indexes
 Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
 <Limit GET POST OPTIONS>
 Require all granted
 </Limit>
 <LimitExcept GET POST OPTIONS>
 Require all denied
 </LimitExcept>
</Directory>

Now Create Sites Folder in your Home Director

mkdir Sites

Now test apache config using

Screen Shot 2014-07-11 at 10.06.05 pm
Screen Shot 2014-07-11 at 10.06.05 pm

Now Create a File inside Sites Directory Name it index.html
Enter Some Plain HTML and save that

Now Let’s Test Apache Configuration

apachectl -t 

then restart apache

sudo apachectl restart

then open browser and browse to http://localhost/~yourusername , Note that “~” tilde in url

your will see something like this

Apache user dir mac osx page
Apache user dir mac osx page

Setup PHP

sudo nano /etc/apache2/httpd.conf 

and uncomment

LoadModule php5_module libexec/apache2/libphp5.so
enabling php in macos yosemite
enabling php in macos yosemite

and test apache config using apachectl -t
then create a file in your Sites Directory

nano ~/Sites/index.php

then enter simple phpinfo() in index.php

<?php 
phpinfo();
?>

and browse to http://localhost/~username/index.php
you will see phpinfo page

Screen Shot 2014-07-11 at 10.30.16 pm
Screen Shot 2014-07-11 at 10.30.16 pm

setup MySQL

Download MySQL (Download DMG ) : http://dev.mysql.com/downloads/mysql/

Screen Shot 2014-07-11 at 10.38.08 pm
Screen Shot 2014-07-11 at 10.38.08 pm

Install that Like another Package of MacOSX there is nothing tricky , install prefPane ( included in DMG )

adding mysql in $PATH

touch ~/.bash_login && echo export PATH=$PATH:/usr/local/mysql/bin | tee ~/.bash_login

above command will create .bash_login file in your home directory and it will add MySQL in PATH

restart your terminal and start mysql from PrefrencePane

MySQL Prefrencepane yosemite
MySQL Prefrencepane yosemite

okay now open terminal and type

mysql_secure_installation

Aloks-Mac-Pro:~ alok$ mysql_secure_installation 



NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] < ------------------ Press ENTER 

Set root password? [Y/n] < ------------- Press Enter 

Screen Shot 2014-07-11 at 10.49.52 pm
Screen Shot 2014-07-11 at 10.49.52 pm
New password:  < ------------------ ENETR NEW ROOT PASSWORD 
Re-enter new password:
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n]  < ------------------- PRESS ENTER 

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n]  < ------ PRESS ENTER 

Screen Shot 2014-07-11 at 10.50.52 pm
Screen Shot 2014-07-11 at 10.50.52 pm
By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n]  < ---------- PRESS ENTER 
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n]  < ------------- PRESS ENTER 
All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!


Cleaning up...

All Done Now MySQL is set up

Screen Shot 2014-07-11 at 10.53.52 pm
Screen Shot 2014-07-11 at 10.53.52 pm

Now You Have Working APACHE PHP AND MYSQL

ScreenCast

happy Coding 🙂


  • Home
  • About