Apache
  Home arrow Apache arrow Using Apache and PHP on Mac OS X
Iron Speed
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Download TestComplete 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
IBM Developerworks
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
APACHE

Using Apache and PHP on Mac OS X
By: Joel Philip
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 86
    2003-03-18

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    Iron Speed
     
    ADVERTISEMENT

    Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    Are you a Mac user? Are you working on the Mac OS X platform and want to use Apache and PHP? Well, Joel has some surprises for you as well as a list of steps one must follow to configure both on your machine.

    If you’re running Mac OS X it has some surprises for you. Seems, PHP and the Apache Web Server have been installed on your machine without your knowledge. Well, its no secret but running them both is somewhat of a mystery and the trick is to flush them out of their hiding spots.

    Generally on a Mac there are Icons that represent programs and documents that you double-click to execute their existence. With PHP and Apache, they run in the background with no sign of an Icon in sight.

    To start Apache Web Server, you must go into the “System Preferences Control panel located on the “Apple Menu”.
     
    Click on the Icon labeled "Sharing". Then locate the tab labeled  "File & Web". You will want to click the button labeled “Start” in the  "Web Sharing " section. This starts up Web sharing which starts the Apache Web Server.
     
    Apache Web Server is now running. Easy, huh? "How can I tell?” you ask. Simple. Start up your web browser of choice. In the web address or URL part of your browser, type: "localhost" (without the double-quotes)
     
    Ex.
    http://localhost
     
    If everything is Okay, your browser will display the following:
     
    "If you can see this, it means that the installation of the Apache Web server software on this system was successful. You may now add content to this directory and replace this page."
     
    It worked! Hooray.
     
    To access the pages of this directory, double-click on your hard drive and locate the "Library" directory. From there locate the "WebServer" directory and then the "Documents" directory where these web pages reside.
     
    Note: If its not running, you either do not have web sharing enabled or   something is wrong with Apache's files. It should work right out of the box.

    Since Mac OS X is a multi-user system, every person has their own account and with that brings it’s own set of web pages. To access your personal web pages you must type the following in the browser address:
     
    Ex.
    http://localhost/~yourname/

    To access your personal web pages, locate your account name directory under   "Users" And locate the directory labeled "Sites".
     
    /Users/yourname/Sites/your web pages are here <---
     
     
    Now that you have Apache running, it would be great to write your own PHP scripts and run them locally on your Mac. This is the most difficult part and if you get past this, everything is downhill with ease.
     
    By default, PHP is disabled along with other features of the Apache Web Server, but we are going to concentrate on enabling PHP.
     
    There is a file called "httpd.conf". The Official name for this file is: "Apache HTTP Server Configuration file". This is our mission. You are going to "uncomment" four lines of the "httpd.conf" file. This requires us to use a text editor to do the job.
     
    Using the Terminal.app, Start the Terminal.app located in the "/Applications/Utilities/" directory, then change the directory to the "httpd" directory using the following command:
     
    cd /etc/httpd
     
    Next step is to use "root" privileges, start up the text editor named "Pico" and edit the "httpd.conf" file.
     
    Use the following command in the Terminal.app:
     
    sudo pico httpd.conf
     
    Type the root password and you are ready to go.
     
    Locate the 4 lines:
     
    #LoadModule php4_module
    #AddModule mod_php4.c
    #AddType application/x-httpd-php .php
    #AddType application/x-httpd-php-source .phps

     
     
    Use your arrow keys to navigate the document and remove only the pound signs "#". The best way to navigate is to use the DOWN arrow key and stay to the left Side of the document. To remove the pound sign, hit the right arrow to the right Of the sign and then hit the DELETE key.

    Warning: Only remove the pound signs!! Keep the lines of code where they are and do not relocate them!! You have been warned!

    The changed lines should look like this:
     
    LoadModule php4_module
    AddModule mod_php4.c
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps

    Save the file by hitting the CTRL + X keys. Pico will ask you if you want to save the document, just hit the Y key to say “YES”. By uncommenting the lines you will load PHP as a module and help the Apache Web Server Serve any PHP file types. You can also create PHP files with another extension simply by adding another Type to the list in the "httpd.conf" file.
     
    What if I wanted all of my PHP files to end with the. bozo extension? Simple, just add this line to the "httpd.conf" file situated next to the AddType  section.
     
    AddType application/x-httpd-php .bozo
     
    After you save the file and restart the Apache Web Server, any PHP file saved with that .bozo extension would display your PHP coding just like a normal PHP file. Now close and save the file. We have to restart the Apache Web Server for everything to take effect. If Apache is running, turn it off by clicking the "Web Sharing On" button that says, "Stop" located in the "Sharing" Section of the System Preferences.

    To restart Apache click on the "Web Sharing On" button. Apache will now be running. We will be writing a small PHP script that will give us information about the PHP installation.
     
    Here is your first piece of PHP code, create an ascii text file and save it as "phpinfo.php", then place it in the Sites directory:

    /Users/yourname/Sites/
     
    Type the following URL in your web browser:

    http://localhost/~yourname/phpinfo.php
     
    It will display a large colorful web page with all of PHP's statistics on your machine. For more information on what the page means visit the PHP web site:
     
    http://www.php.net/manual/en/function.phpinfo.php
     
    So now you can run your own Apache Web Server with PHP enabled from the convenince of your own Mac. Life is good. If you have MySQL installed for Mac OS X, then youre ready to roll with a fully functional web environment to serve dynamic content.

    Written by Joel Philip – Copyright 2003


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More Apache Articles
    More By Joel Philip

     

    IBM® developerWorks developerWorks - FREE Tools!


    Build Forge Express demo: Enabling software delivery excellence for small and midsized businesses

    This demonstration gives you an overview of IBM® Rational® Build Forge Express Edition, a global offering that provides a framework to automate and execute software processes. Rational Build Forge provides a software assembly line that can support all of your tools, technologies, and platforms so you can achieve a repeatable, reliable, and traceable build and release process.
    FREE! Go There Now!


    NEW! Driving Business Success with Rational Process Library

    Join this webcast, to learn how the Rational Process Library can help with compliance issues, drive process improvement, and assist in service-oriented architecture (SOA) or Agile development. We will take a peek into the Rational Process Library with content around software and systems engineering (including RUP), operations and systems management, program and portfolio management, and asset and SOA governance.
    FREE! Go There Now!


    NEW! Best Practices: The Integrated Project and Portfolio Management Platform.

    Hear how IBM Rational Project and Portfolio Management integrated solutions help teams put the right tools and processes in place to maximize the effectiveness and efficiency of project teams and ensure that the business vision is being executed correctly. Learn how to automate and integrate requirements prioritization, top-down project planning, communications and controls, and methodology deployment to keep your scope, costs, and schedules under control. Tackle with an end-to-end approach the management of scope and scope changes, usage of methodology to control and empower project teams, and optimization of resources to align activity costs with the overall project plan.
    FREE! Go There Now!


    NEW! IBM – Taking Web 2.0 to Work

    David Barnes, Lead Evangelist for IBM Emerging Internet Technologies will discuss aspects of Web 2.0 that bring value to corporations, academia, and government. He'll also discuss IBM's vision around Web 2.0, including the importance of remixability and consumability. The discussion will culminate with examples of various IBM Software Group solutions you can use to get ahead of the Web 2.0 adoption curve.
    FREE! Go There Now!


    NEW! Addressing software-as-a-service challenges using Tivoli security and WebSphere solutions

    Building a software-as-a-service solution requires addressing a few key technical challenges. In this webcast, we'll focus on the role of IBM Tivoli Directory Server and WebSphere Portlet Factory in creating a Software as a Service solution. We will demonstrate how to use Tivoli Directory Server to prevent the user population of one tenant from accessing the virtual portal and portlet components of another tenant. We will also use the dynamic profile capability of WebSphere Portlet Factory to create multiple highly customized applications from one code base.
    FREE! Go There Now!


    NEW! Build Web services with transport-level security using Rational Application Developer V7, Part 1: Build Web services and Web services clients

    Build secure Web services with transport-level security using IBM Rational Application Developer V7 and IBM WebSphere Application Server V6.1. Follow this three-part series for step-by-step instructions about how to develop Web services and clients, configure HTTP basic authentication, and configure HTTP over SSL (HTTPS). This first part of the series walks you through building a Web service for a simple calculator application. You generate and test two different types of Web services clients: a Java Platform, Enterprise Edition (Java EE) client and a stand-alone Java client. You also handle user-defined exceptions in Web services.
    FREE! Go There Now!


    NEW! Create dynamic Firefox user interfaces

    When you create browser-based applications that display XML data feeds, you often need to code the data-retrieval mechanism and the user interface. Mozilla Firefox provides an infrastructure that frees you from these tasks, so you can concentrate on your application's functionality. Learn how to use Asynchronous JavaScript + XML (Ajax) to download XML data from a Web server, and discover how you can use Extensible Stylesheet Language Transformations (XSLT) to transform it dynamically into Firefox user-interface elements expressed in XML User Interface Language (XUL). You can apply these techniques to any application that uses XML data sources.
    FREE! Go There Now!


    NEW! Kick-start your Java apps, Part 2

    The combination of Eclipse, DB2 Express-C 9.5, and WebSphere Application Server Community Edition 2.0 -- all free to download, use, and deploy -- is an excellent from-prototype-to-production suite for all of your Java and Java enterprise development needs. What might not be obvious is the relative ease with which you can use these proven tools to create, test, and deploy cutting-edge, lightweight applications as well. This tutorial guides you through the development of a small human-resources application, first using conventional JavaServer Pages (JSP) based technology, and then migrating it to a highly interactive solution using Ajax.
    FREE! Go There Now!


    NEW! Rational Talks to You: Scott Ambler on being agile in a global development environment

    Join this Rational Talks to You teleconference on December 6 at 1:00 pm ET to participate in an agile application development discussion and get your questions answered on using IBM Rational Method Composer in a distributed environment.Get your questions answered!
    FREE! Go There Now!


    NEW! Web development with Eclipse Europa, Part 2: The Java EE for Eclipse

    No matter what combination of technologies you prefer to work with as a Web developer, Eclipse is a single integrated development environment (IDE) that can increase your productivity. In Part 2, we'll see how easy it is to develop PHP applications using a different set of Eclipse plug-ins, collectively known as the PHP Development Toolkit (PDT.)
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    APACHE ARTICLES

    - Programmatically Manipulating Microsoft Exce...
    - Installing PHP under Windows
    - Compressing Web Content with mod_gzip and mo...
    - Compressing Web Output Using mod_deflate and...
    - Setting Up Apache 2.0.45 to Parse PHP Pages
    - Custom Error 404 Documents with PHP
    - Using Apache and PHP on Mac OS X
    - ASP: Active Sessions, Active Logins and Tota...
    - Working With Oracle on Windows: Part 1
    - The Quick-n-Dirty Guide to Setting Up Apache...
    - Installing Apache With SSL: The Complete Gui...
    - 7 Powerful .htaccess Customization Tips
    - Trap And Get Notified: A Practical Solution ...
    - One Way To Use Server Side Includes
    - Using ForceType For Nicer Page URLs






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway