OSX
How to activate a personal web projects folder for Apache on Mac
September 2, 2014
0

Hi all,

My faithful Sony Vaio equipped with Ubuntu 14.04 after some honourable years, stopped working properly; since I’m a developer and I need a computer to work, I decided to move into the Mac world.

One of the first things I had to learn, was how to start and stop apache properly and how to enable a folder to collect my web projects. So let’s start!

My MacBookPro is equipped with OSX  version 10.9.4 and Apache preinstalled, but since Apple dropped the GUI option to turn on web sharing, I had to it manually so:


Open the terminal and type:

sudo apachectl start
Password:

To start Apache.

Sudo apachectl stop
Password:

To stop it.

Type in the password and….. “et voilà”: Apache starts/stops.

To check if it has been started, open your browser and type “localhost” in the address bar, if Apache is working it will display an “It Works!” message in the browser.

Next step you need a project folder so open FileManager and create a directory called “Sites” in  /Users/yourusername.

After this you have to tell Apache to use it: open the terminal again and type:

cd /etc/apache2/users
nano yourusername.conf

and add the following lines

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

Restart Apache and you should be able to view simple HTML/Javascript files.

Since this is not enough funny, let’s enable PHP:

Open the terminal and type:

sudo nano /etc/apache2/httpd.conf

scroll down and uncomment the following line:

#LoadModule php5_module libexec/apache2/libphp5.so
LoadModule php5_module libexec/apache2/libphp5.so

restart Apache again  and here comes the fun:

open your favourite text editor ( I personally like SublimeText  or Atom) and type:

<?php phpinfo()?>

then save it as phpinfo.php in the Sites folder.

Open your browser and type

http://localhost/~yourusername/phpinfo.php

(to type the ~ character simply use Alt+5)

and you should see all the info the installed PHP version.

Now you’re ready to have fun!

Enjoy!!

Leave a Reply

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close