Setting up a Web Server on Leopard (OS X 10.5) or Snow Leopard (10.6) Running PHP, Apache, and MySQL – A Step by Step Guide

November 5th, 2007

Tips and TricksOne of the great advantages of developing web sites on a Mac is the fact that all of the tools you need to run a web server are pre-installed. Getting them to work and play well together requires a little work—especially in Leopard.

If you are simply wanting a web server to host your personal web site, then you might want to consider stand-alone, point and click apps like XAMPP and MAMP. These turnkey solutions set everything up for you and are great solutions if you are just starting or have simple needs.

However, if you want to set up a development environment running multiple test sites using the free tools already installed on your Mac, and you aren’t afraid of the terminal, then read on.

UPDATE: Based on preliminary testing, these instructions remain up to date for Snow Leopard (10.6).

UPDATE: Since posting this tutorial, I have learned that the stock installation of PHP does not include several critical libraries. After several days of experimenting, I finally landed on MAMP as my production solution. I have published a walk-through for setting MAMP up on your machine [link].

NOTE: This guide is specific to getting a server running on Leopard 10.5. Earlier versions of the OS are not covered here.

This guide will walk you through the steps needed to get a development environment set up and running on your copy of Leopard. In this, we will do the following (click on each to jump to the corresponding section):

  1. Enable your root password
  2. Install the Xcode Tools
  3. Edit your Apache configuration file
  4. Set up your first virtual host
  5. Start/Restart Apache
  6. Test Apache
  7. Test PHP
  8. Load MySQL
  9. Install phpMyAdmin
  10. Install PEAR

Overview

A commonly used web server solution consists of 3 major components: Apache web server, a MySQL database, and the PHP scripting engine. This is the "AMP" in LAMP. (The "L" is "Linux"). This set up is widely used in the development community for two reasons: 1) it’s free and open source, 2) it’s very mature. "AMP" components are included in every copy of OS X, but getting them to work requires a few steps.

Step 1: Enable your root password

  1. Open the Directory Utility: In the Finder, navigate to the Utilities folder (tip: click on the desktop, hit Cmd+Shift+U).
  2. Click on the padlock to allow edits.
  3. Go Edit > Enable Root Password
  4. Enter and re-enter your password.

Now, you are set to access protected areas of the system via the terminal.

Step 2: Install the Xcode Tools

While this isn’t strictly necessary, it’s good practice for developers to install the Xcode tools provided for free on your Leopard disc. You’ll need it at some point, so go on and install it.

  1. Insert your Leopard DVD
  2. Navigate to Optional Installs > Xcode Tools > XcodeTools.mpkg
  3. Run the installer.
  4. Go get a cup of coffee.

Step 3: Edit your Apache configuration file

Note: throughout this guide, you will need to edit configuration files. There are several ways to do this. My preferred method is to use an app called BBEdit that allows you to edit protected files more gracefully than, say, TextEdit or the terminal window. However, BBEdit is not free. For the purposes of this tutorial, I’m going to stick with the terminal method that uses the editor called "nano" just because it’s included on every system.

In the terminal, type:

sudo nano /private/etc/apache2/httpd.conf

Note: "sudo" is a command that lets you perform a specific task with root privileges without having to log in as the root. This is the recommended method of mucking about in the terminal as it is safer than being logged in as root.

  1. Scroll down to about line #114. You’ll see the following:
    #LoadModule php5_module      libexec/apache2/libphp5.so

  2. Remove the hash mark as follows:
    LoadModule php5_module       libexec/apache2/libphp5.so

  3. In order to run multiple sites on this server, you will want to use virtual hosts. Scroll down to the bottom of the document (about line #461) and remove the hash from the Virtual Hosts entry as follows:
    Include /private/etc/apache2/extra/httpd-vhosts.conf

  4. Exit and save httpd.conf.

Step 4: Set up your first virtual host

Virtual hosts are Apache’s way of letting you serve up multiple sites on a single server. Name-based virtual hosting is a convenient way to do this.

For this example, we’re going to set up a test site called "site1". With a name-based virtual host, all we’d type in is "http://site1/ ".

In order to make this work, we’ll need to edit the hosts file on your machine. (Note: In Tiger and previous versions of OS X, you accomplished this through the NetInfo dialog. Since the NetInfo dialog was killed in Leopard, we do this the same way you do this for *nix and Windows by editing the hosts file directly).

To edit your hosts file, type in the terminal:

sudo nano /etc/hosts

Below the default entries, you’ll add the following:

# My sites
127.0.0.1 site1

Save your changes.

Now, we’ll need to add a corresponding virtual host. But first, Apache wants us to add our existing default directory as the very first virtual host. This is critical, so do not skip this step.

To edit your virtual hosts file, type in the terminal:

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

Replace the two example virtual hosts with the following:

<VirtualHost *>
  DocumentRoot "/Library/WebServer/Documents"
  ServerName localhost
</VirtualHost>

Next, add your first virtual host similar to the following:

<VirtualHost *>
  ServerName site1
  DocumentRoot /path/to/site1
</VirtualHost>

Who do we have to add our default directory first? According to the Apache Docs on Virtual Hosts, they recommend the following:

If you are adding virtual hosts to an existing web server, you must also create a <VirtualHost> block for the existing host. The ServerName and DocumentRoot included in this virtual host should be the same as the global ServerName and DocumentRoot. List this virtual host first in the configuration file so that it will act as the default host.

Note: Failing to add my default directory as the very first virtual host tripped me up for days. If your virtual hosts are defaulting to an unexpected directory, this is likely to be the culprit.

Step 5: Start/Restart Apache

  1. If you haven’t done so already, go Apple Menu > System Preferences > Sharing
  2. Ensure that “Web Sharing” is checked

Tip: To restart Apache in the future, you can come to the same control panel, uncheck and recheck the Web Sharing item.

Tip: Alternatively, you can type the following into a terminal:

sudo /usr/sbin/apachectl graceful

Tip: Alternatively, you can create an Automator script as follows:

  1. Open a new, blank, custom workflow
  2. Add a “Run AppleScript” action.
  3. Type the following, replacing values as necessary:
    do shell script "sudo /usr/sbin/apachectl graceful" password "[YOUR ROOT PASSWORD]" with administrator privileges
  4. Save the workflow as an Action.

Step 6: Test Apache

In a browser, load your localhost: http://localhost

If you see the default Apache home page (which contains a red and blue feather image), your Apache server is set up correctly. If you do not, then you might try checking your Apache config syntax:

sudo apachectl -t

Step 7: Test PHP

In your favorite code editor, create a new php file and call it "info.php". In this file, enter the following code:

<?php phpinfo(); ?>

Save the file to the root of your local host directory (e.g. "/Library/WebServer/Documents/info.php") directory. In your browser, navigate to the file (e.g. "http://localhost/info.php").

You should see a purple and white table containing all the PHP variables, modules, and settings. If you don’t see this table, backtrack to Step 3 above to ensure you’ve enabled PHP in your Apache config file correctly.

Step 8: Load MySQL

  1. Download and unzip the MySQL Package for Mac OS X.
  2. Install the main MySQL installer.
  3. Install the Start Up Script.

As of this writing, MySQL has not been updated to support Leopard. You will be downloading the package for Tiger (10.4) and making the following modifications:

  1. Do NOT install the MySQL control panel. As of this writing, it does not work with Leopard.
  2. Start MySQL manually by typing the following into a terminal:
    sudo /usr/local/mysql/support-files/mysql.server start

MySQL should now be running silently in the background.

A new issue with Leopard’s installation of PHP is that it expects MySQL to be somewhere other than where it is installed by the package. To fix this, we need to create a new MySQL configuration file. To do this, create a text file and save it as "/etc/my.cnf". Enter the following text:

[client]
socket = /var/mysql/mysql.sock

[mysqld]
socket = /var/mysql/mysql.sock

In a terminal window, type the following in order to create a folder where the MySQL sock file will live:

sudo mkdir /var/mysql
sudo chown _mysql /var/mysql

Note: If you are using any of the MySQL Tools (e.g. MySQL Administrator, etc.), you’ll need to tell them where to find the sock file. To do this, click the Advanced drop-down on the connection dialog, and enter “/var/mysql/mysql.sock“.

At this point, you should have a fully functioning database. Now, let’s get some data in there.

Step 9: Install phpMyAdmin

phpMyAdmin (PMA) is a popular and free tool to manage your MySQL databases. It is an integral part of most LAMP development environments.

  1. Download and unzip the latest stable release of phpMyAdmin.
  2. Copy the files to a directory of your choice. For this example, we’ll install it in "~/Sites/phpmyadmin/".
  3. Per Step #4 above, add this directory as a virtual host called "pma".
  4. Restart Apache to initialize your new virtual host.
  5. Follow the installation instructions provided in the PMA download to set up the config file.
  6. If you can navigate to PMA (e.g. "http://pma", you’ve good to go.

Step 10: Install PEAR

PEAR is a companion to PHP that is typically installed by default along with PHP. PEAR is a set of applications, modules and pre-packaged classes that provide a wealth of functionality to your apps with minimal effort. One example covered on this blog is how to implement an elegant caching mechanism with just a few lines of code. Using PEAR is highly recommended.

In a terminal window, type the following:

curl http://pear.php.net/go-pear > go-pear.php
sudo php -q go-pear.php

This will auto-install and pre-configure PEAR for you.

Now, we need to tell PHP to look for the PEAR files. To do this, we’ll need to modify the php.ini config file. First, copy the default config file and rename it php.ini by typing the following in a terminal window:

sudo cp /etc/php.ini.default /etc/php.ini

Now, edit the php.ini file:

sudo nano /etc/php.ini

Scroll down to line #469 or so and edit the include_path variable by removing the comment hash and adding the PEAR path as follows:

include_path = ".:/php/includes:/usr/lib/php:/usr/share/pear"

Restart Apache and ensure everything loads and runs as expected.

Conclusion

By this point, you should have a fully functional development server that you can extend and expand as you take on new projects.

Please feel free to add comments below if you find errors or problems with the guide above.

Good luck.

Sphere: Related Content

  • @braddanick - to get apache to list the directory contents, you'll need to add an .htaccess file to the directory with the following directive:

    Options +Indexes

    If you want this at a global level (not recommended for security reasons), search for...

    Options -Indexes

    ... in your httpd.conf and change it to...

    Options +Indexes

    Cheers,
    Steve
  • braddanick
    Hey there!!!!

    Thanks for all the hard work. I originally used your other post to set up MAMP.

    I have been putting off using the MAMP package as my config was working just fine save for having to start MySQL manually.

    I have now purchased and install MAMP and MAMP Pro! I though it'd be nice to have the Pro app to do the dirty work... seems like it was a huge waste of money.

    I have configured my virtual hosts and they seem to work but for one problem.

    Unless I have an index.php file in the folder, it shows a 403 Forbidden error message.

    Is there something I can do to get the default directory listing back?

    Thanks a lot once again!
  • vin.tone
    I get this too.. but the line numbers are different:
    "/usr/local/mysql/support-files/mysql.server: line 260: /usr/local/mysql/bin/my_print_defaults: Bad CPU type in executable
    /usr/local/mysql/support-files/mysql.server: line 263: /usr/local/mysql/bin/my_print_defaults: Bad CPU type in executable"

    (Awesome site BTW!)
  • daleimerman
    HI Guys
    I'm a major newbie when it comes to this SQL and PHP stuff, but I am trying hard to get it setup on Leopard....

    Everything in the Tutorial is brilliant, but when I get to step 8 and try to start SQL Server, I get the following error:
    """
    /usr/local/mysql/support-files/mysql.server: line 237: /usr/local/mysql/bin/my_print_defaults: Bad CPU type in executable
    /usr/local/mysql/support-files/mysql.server: line 240: /usr/local/mysql/bin/my_print_defaults: Bad CPU type in executable
    Starting MySQL
    /usr/local/mysql/support-files/mysql.server: line 159: kill: (5268) - No such process
    ERROR!
    """

    Can someone please assist me bearing in mind I have little knowledge of this stuff.
  • qaz
    I'm trying to get cgi/perl working on leopard. I've altered httpd.conf in apache2, and given 755 permissions to the files. Also. do the cgi files go in the cgi-executables folder? I also tried putting them in the main site folder, but the cgi files will not execute
  • KyleDurand
    I've gotten past the default page with localhost by putting the files I want to see in its root directory ( the one you had me set for it ), but when i try to put files in the root directory of others, I'm told ( by my browser ) that the page could not be found. I'm assuming that for some reason, I'm being directed strictly through the initial localhost. But I have no idea how I'm supposed to fix that.
  • KyleDurand
    I'm not really experiencing any problems like the others, but I can't figure out how to get past the Apache Default page... I can get past it with the info.php page I made, but I can't get to the phpMyAdmin installation page. When I try to access http://pma I just get the Apache Default page. I'm pretty sure I've got my paths set right, so I don't know what it is I've done wrong.
  • @tkroro
    When you installed MySQL on your mac, did you also install the start-up item? If so, you'll want to delete that. I'll be honest and say that I can't remember exactly where it puts the startup item. If memory serves, it's here:

    /Library/StartupItems/MySQLCOM/MySQLCOM

    Let me know if that works.

    -Steve
  • tkroro
    No Problem. When I try to start the server manually with "sudo /usr/local/mysql/support-files/mysql.server start" I get the error. Thanks, Ro.
  • @tkroro
    Sorry. I was typing on my iPhone this morning and couldn't elaborate.

    Anyhoo, when you say "when I try to start the server" do you mean you're trying to start it manually? When, exactly, are you getting this error?
  • tkroro
    Thanks for the quick reply. Excuse me for my ignorance but I'm a noob and haven't the slightest how to check if I have an autoloader. I did install a version of mySQL with my Visual Studio 2005, but I only run that through Parallels. Thanks again, Ro.
  • @tkroro
    that error usually happens when you try to launch (or quit) mysql when it's already running. You might want to see if you have an autoloader working.
  • tkroro
    Much gratitude- A GREAT TUTORIAL!! PHP and Apache are functioning for me, but I too am having issues with MySQL. I get this error when I try to start the server, "line 159: kill: (1414) - No such process ERROR!" I am running Leopard and am using the Universal version of MySql 5.0.51a. I tried the advice you gave Incoe, but still get the error. Any assistance would be greatly appreciated. Thanks in advance, Ro.
  • @kasimir
    No problem. Sorry I couldn't be of more help.

    @veekter
    Glad you got it working.
  • veekter
    I managed to get it working! I had to change the User/Group to mine to gain access to my User directory.

    So for some reason there's something stopping access to my User directory except for the Sites folder, because the Sites folder works just fine without having to change the User/group of the httpd process.
  • kasimir
    @ Steve
    Thanks a lot for your advice, anyway. Now I know where to look for more...
    Regards,
    Kasimir
  • @ veekter

    Not, really. No.

    Perhaps someone more knowledgeable than I about the ins and outs of Apache could weigh in.

    You might also try posting your question to someplace like the DevShed Apache forum:

    http://forums.devshed.com/apache-development-15/

    -Steve
  • veekter
    Hi Steve, I've tried the page access and it still denies access. I've changed the httpd.conf file to what you have there, it was slightly different.

    I also tried to add


    Options Indexes MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all


    to my /etc/apache2/users/victor.conf and it's still not working. Any more ideas?
  • @veekter

    That's a head-scratcher. 403s are generally thrown due to permissions problems, but you already added index.php.


    What happens when you try to access a page directly? For instance http://mytestsite/somepage.php (assuming somepage.php exists)?


    Way up in the httpd.conf file are the default settings for a generic directory. The lines start "<Directory />". Mine looks like this:


    <Directory />

      Options Indexes MultiViews FollowSymLinks


      AllowOverride All


      Order allow,deny


      Allow from all


    </Directory>


    Is yours changed? This is the section that controls default permissions and would be the source of 403s in most cases.


    Let me know.


    -Steve

  • veekter
    Hi Steve,
    Thanks for the great tutorial. I'm having a problem accessing my virtual hosts when I set the DOCUMENTROOT outside of the WebServer folder - I get the 403 Forbidden error.

    I tried copying the folder into WebServer and change the DocumentRoot accordingly and it works fine. However when I place the folder in a directory in my user Documents folder I get the Forbidden error.

    I've added index.php to the DirectoryIndex, so I'm not sure what to do. I even checked the permissions on the folder and everyone has read/write access.

    Any ideas?
  • @Kasimir

    Sounds like you have your hands full. With regard to make_sock, this error is typically a permissions problem of some kind, but I can't say for sure. I usually run across this error with MySQL, not Apache. You might want to explore the Apache docs or post to the DevShed forums for advice if no one here can help.

    With regard to seeing your mac over the network, sounds like you have bigger issues on your network. Of course, if you're getting a sock error on Apache, Apache isn't actually running, so you won't be able to bring up a web page over the network. If your pings are timing out, it is a larger issue. The Mac support forums might be a good resource for you on that one.

    Sorry I can't be of more help.

    -Steve
  • kasimir
    Hi and thanks for the great documentation!
    I want to run a wiki on my local machine and make sure that it is only accesible locally from my Mac and not over the network. I read a good hint about this on http://www.macosxhints.com/article.php?story=20071127011627796&query=leopard%2Bapache
    My "problem" is that even before doing this I cannot access my Mac over the network and I don't know exactly *why* this is. Apart from wanting to understand my Mac's network configuration, it would also be good from a security point of view to know why my Mac is not accesible over the network.
    I can ping my Mac from another computer on the local netowork but when trying to surf to e.g. 192.168.1.17 (or whatever my Mac's address currently is) I just get a timeout sometime...
    Additionally, I find lots of those error messages in my system.log:
    org.apache.httpd[16656] (13)Permission denied: make_sock: could not bind to address [::]:80

    Would you have any hint for me why this could be?

    Thanks!
    Kasimir
  • qaz
    Now, does anyone know how to enable cgi on apache mac leopard? I have given the program files permissions with chmod 755, but am unsure about which httpd.conf alterations to make.
    As I found when enabling php on apache, Leopard seems differently configured to Tiger, and I've had neither working yet in any case.
    help
  • qaz
    Cheers sstringer, 'twas permissions of course: I opened Terminal, gave the uploads directory 'sudo chmod 777', and the file uploaded ok.
    ..Or at least it appeared to upload: the next problem was that the uploaded file was found to be empty or corrupted. To solve this I changed the "move_uploaded_file()" function to the "copy()" function, and for good measure passed its parameters (the filenames) as string variables,
    ie. replaced
    move_uploaded_file($_FILES["file"]["tmp_name"],"upload/" . $_FILES["file"]["name"]);
    with
    $tmpname=$_FILES["file"]["tmp_name"];
    $fullname=$_FILES["file"]["name"];
    copy($tmpname,"upload/" . $fullname);
    $tmpname="upload/" . $fullname;
    I gather this has something to do with the browser not flushing its buffers as often as we might like, and copy(), a more definite command, gets around this problem.
  • @qaz
    This sounds like a permissions error. You'll want to check the permissions on the destination folder ("upload", and "/Library/WebServer/Documents/WebWeb/" in your example).
  • qaz
    On apache /leopard mac, when I try using the move_uploaded_file function I get this double error msg:

    Warning: move_uploaded_file(upload/cat-1.gif) [function.move-uploaded-file]: failed to open stream: Permission denied in /Library/WebServer/Documents/WebWeb/upload_file.php on line 35

    Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/private/var/tmp/php3R28FM' to 'upload/cat-1.gif' in /Library/WebServer/Documents/WebWeb/upload_file.php on line 35
    Stored in: upload/cat-1.gif

    but when I look, it isn't in upload/cat-1.gif at all.
    Tried playin around with php.ini and httpd.conf, but which httpd.conf etc eh?
    help
  • @jsahiri
    1) Reference step 3.3 above
    2) vhosts only.
  • jsahiri
    Steve,
    1) In which file do I have to uncomment the link to the external vhosts file. I didn't see this mentionned in the steps above. Can you be more specific?

    2) does the deletion of port 80 apply to vhosts file only or to some other files. If the latter, do you know which ones: httpd.config, php.ini?

    Thanks
  • @ jsahiri
    Your vhosts file looks right. Assuming these other sites don't load at all, the only other thing I can think of are that you forgot to uncomment your link to your external vhosts file. One other thing to try is to drop the port 80 designation from your vhosts. Anywhere it says ":80", delete it. It's grasping at straws, but it's all I can think of.
  • jsahiri
    Steve,
    Thanks for your quick reply. http://localhost works. What does not work are the virtual domains (sites1 and pma). Here are the contents of
    1) the hosts file

    #
    # Host Database
    #
    # localhost is used to configure the loopback interface
    # when the system is booting. Do not change this entry.
    ##
    # My sites
    127.0.0.1 localhost
    127.0.0.1 site1
    127.0.0.1 pma
    255.255.255.255 broadcasthost
    ::1 localhost
    fe80::1%lo0 localhost


    and
    httpd-vhosts.conf file

    #
    # Virtual Hosts
    #
    # If you want to maintain multiple domains/hostnames on your
    # machine you can setup VirtualHost containers for them. Most configurations
    # use only name-based virtual hosts so the server doesn't need to worry about
    # IP addresses. This is indicated by the asterisks in the directives below.
    #
    # Please see the documentation at
    #
    # for further details before you try to setup virtual hosts.
    #
    # You may use the command line option '-S' to verify your virtual host
    # configuration.

    #
    # Use name-based virtual hosting.
    #
    NameVirtualHost *:80

    #
    # VirtualHost example:
    # Almost any Apache directive may go into a VirtualHost container.
    # The first VirtualHost section is used for all requests that do not
    # match a ServerName or ServerAlias in any block.
    #


    DocumentRoot "/Library/WebServer/Documents"
    ServerName localhost


    ServerName site1
    DocumentRoot /Sites/site1


    ServerName pma
    DocumentRoot /Users/nameofadminuser/Sites/phpmyadmin
  • @ jsahiri
    re: 2) if safari, or presumably any browser or ping utility, can't see "http://pma", it's likely due to a missing value in your hosts file, but it sounds like you thought of that. Double-check your formatting (Leopard is picky about some values needing to be at the top), and ensure that that's not the problem. If you're unable to load *any* local domain, then the problem is likely due to Apache not running. This could be due to a typo in the config file, for instance. Try starting and stopping apache in the command line to see if it loads correctly. Also use the apache config file syntax checker to ensure your config file is correct.

    re: 3) The location of your Automator file shouldn't matter as long as you are using the full paths in your scripts. Remember that these need to run as a privileged user (root, typically) and, thus, the tilde shortcut (~/Sites/) won't work.
  • jsahiri
    Hi sstringer,
    This is one of the best step by step instruction I have ever seen. One comment and then a couple of questions:

    1) Created the file info.php as indicated in step 7 and it would not work. Then I remembered that there was phpinfo inside the ext body, saved the file as phpinfo.php instead and it worked.

    2) As reported by another guest, I had a problem with virtual host. Have no problem seeing apache when I launch http://localhost. But when I try to use http://sites1 or http://pma, I get "Safari can’t open the page “http://pma/” because it could not connect to the server “pma”.

    Wonder what I am doing wrong. I have sites1 and pma under My Sites in the hosts file as indicated in the step 4. But in the virtual hosts, I have the documentroot path pointing to nowhere in fact since I didn't create a file called sites1 to insert in Sites. Same with pma. Could this be the problem. If I had to create a file called sites1 to put in Sites and pma to put in phpmyadmin, what should it contain?

    3) When creating automator script to run "to launch apache and mysql" where should they be saved? Anywhere? I am new to Mac and have not played around with automator yet.
  • lebafar
    Oh well, I think I solved my broblem now. It was a cache thing. Thank you very much for your attention and for this great job you did Steve!
  • @lebafar
    Yes, 3.3.

    If you're outside your network, there are some extra steps you'll need to take that are outside the scope of this tutorial. Generally, though, you'll need to add an alias to each virtual host. Same syntax as "ServerName" but use "ServerAlias" instead. If you're on an intranet, you can type the ip of your machine directly. If you need to access the server from outside your home network, assuming you have a static IP (or an account on DynDNS), you'll set up a port forward on your router to the server in question and then type the alias after your IP or URL (e.g. http://lebarfar.com/pma/). Note that this has the significant drawback of altering your URL structure which affects site-relative linking. The other way to do this is to get a url for each test server, point it at your router, set up port-forwarding as before, and set up a virtual host for unique url.
  • lebafar
    How do I access this vhosts? I thing here I might be having a issue. Like, from my own computer I would type http://site1 and it would open “/Users/lebafar/Sites”. But how about if I am from outside my network?
  • lebafar
    yes, I did. You mean the step 3.3, right?
  • @lebafar
    It's hard to say, exactly, what might be wrong. Assuming your first entry immediately follows the "NameVirtualHost *" line, it should work.

    You did uncomment the vhosts link, right? That's the only other thing I can think of.
  • lebafar
    Hey, I don't want to sound repetitive but I think I am having the same problem of those guys above me were. Well, for every of the three different ServerNames I type on my browser I only access the contents of the localhost DocumentRoot path.
    My httpd-vhost.conf file is set like that :

    DocumentRoot "/Library/WebServer/Documents"
    ServerName localhost



    ServerName site1
    DocumentRoot "/Users/lebafar/Sites"



    ServerName pma
    DocumentRoot "/Users/lebafar/Sites/phpmyadmin"


    Am I doing something wrong?

    Thank you for the site and you help !
    Lebafar
  • @jedmtnman
    Quotes are necessary if you have a space somewhere in the path name, but it's always a good practice. But that's not the problem here...

    Your problem is that you're using tilde (~) in your paths. Since Apache is actually a different, privileged user on your system, it's tilde shortcut is different than yours, so ~/Sites/phpmyadmin isn't what you think it is.

    Use your full path and see if that works. e.g. /Users/[YOU]/Sites/phpmyadmin

    Tip: Drag your target folder into a leopard terminal or textedit window, and the full path will be typed out for you.
  • jedmtnman
    Great tutorial so far, let me just check that I have a couple things correct...

    In my virtualhosts file, i have it set up like this:


    DocumentRoot "/Library/WebServer/Documents"
    ServerName localhost



    ServerName site1
    DocumentRoot /Sites/site1




    ServerName "pma"
    DocumentRoot ~/Sites/phpmyadmin


    I just wanted to check that the path does not need to be in quotes, like the default host and that site1 doesn't need the ~/

    Reson I ask is that I cant seem to navigate to the phpmyadmin site if saved in my Sites folder(access forbidden), but if i store it in the Library/WebServer/Documents directory and I navigate with a browser to http://localhost/phpmyadmin I at least get an error that my config file is messed up.

    Also, if i go to the web sharing CP and click on the link to my ip/~user, it says access forbidden. This worked before my Leopard upgrade. Any ideas?

    You have done a fantastic job on this tutorial and a lot of testing/research. It is very much appreciated.

    thanks,
    Jed
  • @Dick Haight

    "Unable to connect" typically means Apache isn't running at all. Too many reasons to count as to why this might be, but typically it's a typo or misconfiguration in your Apache config (httpd.conf) file. Try typing the following into a terminal:

    sudo apachectl configtest

    "Forbidden" is typically caused when you have a non-standard (from Apache's point of view) default page and have indices turned off. See comment #2 above for the fix to that.
  • Dick Haight
    I have had several Macs running as servers with PHP (osx 10.3, 10.4, G4s, G5s, Intels). I had recently converted to PHP 5.2+ with minor glitchs. So I wasn't expecting much trouble going to 10.5. Since then I have had several days of frustration. I followed stringfoo's steps 1 - 7 without success. Where before I was getting a "Forbidden" message when trying to access a localhost page now I get an "Unable to connect" message.

    Any thoughts?
  • Okay, you'll need to create an alias to the main sock file. In a terminal type:

    sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock

    (Assumes your MAMP installation is in the default location).
  • incoe
    thanks for helping, the apache is working fine now, but the problem with mysql keep persisting i tried installing it again but no use it keep giving same message when i try starting it
    Starting MySQL
    .................................................................................................../usr/local/mysql/support-files/mysql.server: line 159: kill: (189) - No such process
    ERROR!

    also when i try the sudo mysql_secure_installation to set a root password it keeps giving another error

    Enter current password for root (enter for none):
    ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)


    tried all blogs and forums, tries all solutions there but i cant figure out whats wrong, am new to these stuff so i can put my hands on the error it self
  • @incoe:
    Sounds like a permissions problem across the board. When you launch either apache or MySQL manually, be sure to do so with the "sudo" directive before the launch command so the process will have sufficient permissions to launch itself.
  • incoe
    thanks alot for setting up steps, it helped alot, however i tried running mysql manually as you wrote and it gave me this message:

    Starting MySQL
    .................................................................................................../usr/local/mysql/support-files/mysql.server: line 159: kill: (52984) - No such process
    ERROR!

    also i possible to help in this issue too, i typed apchectl -k stop was testing it, and then tried starting it but it keep giving this

    apachectl -k start
    (13)Permission denied: make_sock: could not bind to address [::]:80
    (13)Permission denied: make_sock: could not bind to address 0.0.0.0:80
    no listening sockets available, shutting down
    Unable to open logs

    any suggestions? :-)

    Thanks.
    Karim.
  • rwhart
    I have done all the above, and still have no proof that php5 was installed. I am a little baffled at the way Apple has played with the directory tree( I am mainly a Fedora user). I do not know of any way (obviously I am new to the Mac platform) to check to see if a program is installed - e.g. on Linux I can do a 'rpm -ql | grep [filename]' and see if the package is installed.

    Is such a tool on Leopard?

    Thanks,

    Bob
  • Glad it worked for you. Did I guess the problem correctly, or was it something else?
  • andrea74
    Dear Steve,
    everything is OK now: thank you very very much for your help.
    All the best!
    Andrea
  • @andrea74:


    This one's new for me. I'm a little baffled, in fact.


    The only thing I can think of is that your site1 is not the site you think it is. Let me explain.


    When you set up a virtual host but haven't set a default host, Apache will use the first virtual host it finds and serve it up regardless of the url you enter into your browser.


    If you've set up, say, a test version of site1 in Apache's default folder and then later tried to point your host to a different folder for site1, *but* you didn't define the default virtual host correctly, then any changes you made in site1 wouldn't show up in your browser and would, in fact, cause the error you're seeing.


    To test this, make an obvious text change to info.php. If the change shows up when you enter http://site1/info.php, then I'm wrong. If I'm right, though, the change wouldn't show up.


    To fix this, find the "DocumentRoot" directive somewhere around line 368. Make note of that path. Mine's "/Library/WebServer/Documents"


    Now, in your virtual hosts, define that folder as the very first virtual host:


    #

    # Use name-based virtual hosting.


    #


    NameVirtualHost *


    #


    # Default virtual host


    #


    <VirtualHost *>


      DocumentRoot "/Library/WebServer/Documents"


      ServerName localhost


    </VirtualHost>


    Give it a shot and let me know if it works.


    -Steve

  • andrea74
    Hi, thank you for the manual.
    I have a problem: I added a new irtual host following the instructions at Step4 (for example site1): if I save a file called info.php in the directory, I can open it by browser with http://site1/info.php, but all the others file inside the directory can't opened (for example, I copy info.php and renamed it to info2.php: if I try to open http://site1/info2.php, the browser give me the error message

    Not Found

    The requested URL /info2.php was not found on this server.

    Any idea to solve this problerm?
    Thank you in advance.
    Andrea
  • This problem happens when you've turned off the indexes option in your Directory settings but don't have a default file that Apache can open.

    To fix this, open your httpd.conf file and search for "DirectoryIndex". Let's say your site uses "index.php" for it's default homepage. You'll want to add that to the DirectoryIndex line which already includes names like "index.htm". Add yours, save, and restart Apache. You should now get your site to come up without the "You do not have permission..." error.

    -Steve
  • krisziel
    Hey,
    this is a great wlakthrough, thanks for it. I have encountered an error when trying to access the server though. I get the message that I am forbidden from accessing the page. I am administrator on my computer, and don't know how tog et around this problem
blog comments powered by Disqus