Home > MacOS, Web > Setup Apache Server on MAC

Setup Apache Server on MAC

To Set Up a Server on my mac.

  • Goto Preference: Sharing, Check the Sharing View
  • Now the apache is running, to do a test: put:  localhost in your browser, you will see “it works!”
  • When you check the box for Sharing View, you will be notified that there are two different websites are now available on your computer
    • 2. Computer Website: http://your-computer-name/
    •       The Site Folder in  <Library/WebServer/>
    •       There are 3 subfolders under this folder: a) CGI-Executable; b) Documents; c) Share
    •        You should put your executables in this folder, such as the below python code:

#!/usr/bin/python
print “Content-type: text/html”
print
print “<html><head>”
print “”
print “</head><body>”
print “Test Page”
print “</body></html>”

Name it as ‘test.py’, and in the terminal change it to

                   $ sudo chmod 755 test.py

Now you can run it by : http://localhost/cgi-bin/test.py

Here’s a useful link: http://www.editrocket.com/articles/python_apache_mac.html

Also here’s how to share a folder: http://www.macworld.com/article/1140370/pythonserver.html

In Terminal, first cd to the folder you’d like to make available via the Web server. For example, cd ~/Pictures to switch to your user’s Pictures folder. Next, you activate Python’s built-in Web server with this command: python -m SimpleHTTPServer (and yes, capitalization counts). Press Return, and you’ll see a message stating Serving HTTP on 0.0.0.0 port 8000 .... The important bit there is the port number (8000). (You can use a different port number by simply including it at the end of the command, like so: python -m SimpleHTTPServer 8080.) To access the server from the machine you’re running the Python server on, switch to a Web browser, and enter http://localhost:8000 (replace 8000 with the port you used, if you didn’t use the defaut) in the URL bar. When you press Return, you’ll see a listing of all files in the directory. Depending on what types of files are there, and which browser you’re using, you can then click on files to view them in the browser. In my testing, Firefox works better than Safari, as Safari wants to download file types it doesn’t know how to handle while Firefox will often let you open them with a helper application. To access the server from another machine on your network, you need to know the server computer’s name. You can find this in the Sharing System Preferences panel, in the aptly-named Computer Name section of the panel. Just below the computer’s actual name, you’ll see a line that begins Computers on your local network can access…, followed by the name they’ll need to use to do so. Typically, this is simply the Computer Name followed by .local—so if the machine’s name is OctoMac, for instance, you can then access the server by entering http://OctoMac.local:8000 in your browser’s URL bar.

Advertisements
  1. No comments yet.
  1. April 25, 2012 at 5:43 AM

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: