Enabling apache

Mac OS X used to have a sharing function which turned apache (webserver) on so you could make websites on your machine. However, they turned that off, for whatever unknown reason.

To enable apache now, do the following.

First, let's find out your username. Open /Applications/Utilities/Terminal.app

It will come up with a terminal screen

Type:

whoami

The machine will answer with your login name. Note what it is. Let's say it's "bob" for now.

Now type:

sudo vi /etc/apache2/httpd.conf

This will start you off editing the apache webserver configuration file (https://www.youtube.com/watch?v=dFUlAQZB9Ng). Yes, this is a unix machine. The way you edit it is not by mousing, contrary to what we see in Jurassic Park(tm), but by typing in and editing text files.

To search for the necessary lines, type a forward-slash (/)

Type what you want to search for, in this case, php. Press enter after typing php as the search.

You will find a line like this:

#LoadModule php7_module libexec/apache2/libphp7.so


use your cursor keys to get to the # mark. Press the key "x" on the keyboard to delete it. If you make a mistake, press U to undo.

Use forward-slash again to search again, search this time for DocumentRoot, with that capitalisation.

DocumentRoot "/Library/WebServer/Documents"

<Directory "/Library/WebServer/Documents">

    #

    # Possible values for the Options directive are "None", "All",

    # or any combination of:

    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews

    #

    # Note that "MultiViews" must be named *explicitly* --- "Options All"

    # doesn't give it to you.

    #

    # The Options directive is both complicated and important.  Please see

    # http://httpd.apache.org/docs/2.4/mod/core.html#options

    # for more information.

    #

    Options FollowSymLinks Multiviews

    MultiviewsMatch Any


    #

    # AllowOverride controls what directives may be placed in .htaccess files.

    # It can be "All", "None", or any combination of the keywords:

    #   AllowOverride FileInfo AuthConfig Limit

    #

    AllowOverride All


    #

    # Controls who can get stuff from this server.

    #

    Require all granted

</Directory>


Use the cursor keys to perform the following deletions:

Delete

/Library/WebServer/Documents

and once you have deleted it, press the "i" key (lowercase i) and type this, instead:

/Users/bob/Public

assuming your username is bob. Obviously, if your username is something else, you are going to provide that instead of 'bob'.

The reason we do this is that you do not want to type your login password EVERY TIME you want to save a new file into /Library on your computer. Big nuisance. Instead, this will cause apache (the webserver program), to use your Public folder inside your personal home folder.

Once you have typed the new path of your website folder, press the ESC key to go back to moving mode. 

Cursor down to AllowOverride and change the word "none" to "All" as shown, with a capital A.

Press the ESC key again.
Type

:wq

which means "write and quit".

You are now ready to tell Apache to start.

sudo launchctl load -w  /System/Library/LaunchDaemons/org.apache.httpd.plist


Apache should now be running, unless an error occured.

To make sure it starts at bootup time,

sudo defaults write /System/Library/LaunchDaemons/org.apache.httpd Disabled -bool false


Once this is done, you want to install MySQL. That's the topic of another blog.

Now type this into your terminal

cd

chmod 711 .

chmod 755 Public


This tells the Mac to allow apache to read your personal home folder and the Public folder inside it.

You are now ready to create webpages.

Open any text editor, preferably TextWrangler.

Create a text file with something inside it, like, the phrase "Hello World"

Save the file with a file name of "index.html" and save into your Public folder.

If you now open a web browser and go to:

http://127.0.0.1

It should show you a blank white page with "Hello World" on it.

Well done, you are now a webserver administrator.

Popular posts from this blog

Chunk validation failed

The most useful defaults-write options

Erasing firmware password