How to install Apache and PHP on a Mac

How to install Apache and PHP on a Mac (MAMP Part 1)

219 thoughts on “How to install Apache and PHP on a Mac (MAMP Part 1)

  1. wording details: instead of
    “Find the next line and make sure the comment is removed #”
    replace with:
    “Find the next line and make sure the comment (#) is removed”

  2. Great work.
    First part completed, but i have answers for you!I can use the same guide for xampp ? or you advise me to use MAMP on mac ? thanks a lot 😉

    1. Hi Paola, It’s going to depend on your needs. If you need to work on PHP I generally recommend a MAMP setup.

  3. Hey Jonathan,

    I have followed each and every step but the testing isnt getting through. Also when i even do http://localhost/~pulkitkumar95, it says “Cannot connect to localhost”, i am running mac os el Capitan and apache server version is 2.4.16. I am in urgent need of this to work.plesase help me out asap

    1. Hi Pulkit, also, in step 3 part 2, make sure you setup your configuration file correctly for your version of Apache. Then Restart your server. Best of luck

  4. Hi.
    I have EL CAPITAN
    At the end I get the message: “SAFARI CAN’T CONNECT TO THE SERVER Safari can’t open the page “http://localhost/~MarcelloMacMini/phpinfo.php” because Safari can’t connect to the server “localhost”

    but if I type just “localhost” I get the IT WORKS! page so localhost by itself is working.. only not the php page…

    I’ve followed everything, the permissions are correct, the php file is there

      1. Hi Marcello, a permission error should be easy to resolve by updating the permissions on your Sites directory. See Step 5. Part 5 in the tutorial. It shows you how to update them. Let me know how it goes.

  5. Hello, Jonathan –

    After following all the instructions several times in your – most excellent – tutorial, I’ve consistently received the following error message in Chrome:

    This webpage is not available


    Google Chrome’s connection attempt to localhost was rejected. The website may be down, or your network may not be properly configured.

    Your help in solving this issue will be greatly appreciated!

    1. Hi Kym,

      It’s tough to solve with just that error alone. Do you get this same error when using Safari? Also, what OS do you have installed? This will help to diagnose the issue. Thanks.

  6. HELP??? I have now gone through at least 4 tutorials on getting Apache working on Mac (OSX 10.8.5). Every single one starts with the command sudo apachectl start in terminal. I get a response of command not found. I’ve made the change to enable PHP, and I’ve set up a user config file, but the base command simply doesn’t work. Any ideas?

  7. Thank for the tutorial.
    I keep getting (after completing all the steps) a 404 error. How can I overcome

    1. Hi Pavan, sorry for the late response. 404 error means that the page wasn’t found. Sometimes that means that Apache doesn’t have permission to access the location of the site. Have you tried giving the Apache user permission to your Sites folder? I’ve left instructions after part 5 of the tutorial.

      Run the following in your terminal. Remember to replace username with your username.

      sudo chown -R :_www "/Users/username/Sites"

      sudo chmod -R g+w "/Users/username/Sites"

      sudo apachectl restart

  8. Hello Jonathan,

    Thanks for the instructions. I am running El Capitan beta. I am getting a 404 error: The requested URL /Users/~quint/phpinfo.php was not found on this server.

    Could you provide any troubleshooting tips?

    1. Hi Quint, I’m about to test on El Capitan myself. Downloading it as I type this. What does your Apache error log say?

  9. Thank for the tutorial.
    I keep getting (after completing all the steps) a 403 error. How can I troubleshoot this?

    1. Hi Marco,
      This is error means that the directory is forbidden. You can fix this in your user configuration file. Double check that you are using the right one. You can see the options under Step 3 in the tutorial. Can you let me know what version of Apache you have? Type this into your terminal to find out httpd -v

  10. I am trying to set up a testing server on a Mac running OSX 10.8.3
    I want to set up virtual hosting. When I get to the final step, I don’t see the correct PHPInfo file. I am getting the file, but just the line of code. The PHP code isn’t executing. I have it at the top level of the Sites directory. Inside are other directories. I can go into a site and see the files there, but just as a list. What am I doing wrong? Thanks very much.

    1. Hi Carol,

      This is possible if PHP is not enabled. First thing I would check is that the following line doesn’t have a # comment in front of it. See Step 2 in the tutorial.

      Open the Httpd config file in nano

      sudo nano /etc/apache2/httpd.conf

      Then look for this line

      LoadModule php5_module libexec/apache2/

      If that is correct, then try restarting the Apache server. Once restarted it should work fine.

      sudo apachectl restart

  11. Hi Jonathan, Thanks for this easy tutorial.
    I’m trying to make it work for a WordPress program.
    I do however, have a little problem when:
    Username-MacBook-Pro:~ username$ sudo chmod /Users/username/Sites 0755
    it says:
    chmod: Invalid file mode: /Users/username/Sites

    What happened? I can’t find a understandable answer on the net.
    Please help 🙂


    1. Hi Sydney,

      Sorry about that. The command is:

      sudo chmod 0755 /Users/username/Sites

      The permission 0755 needs to be written before the file path in the command. I’ve updated the tutorial.

  12. Hey,
    I have a question about permissions to delete or edit files using PHP. I would like to unlink files and add files to folders. Using PHP Unlink(path) will not work. Any suggestions?

    1. Hi Matthew,

      Correct, PHP will need permission to delete this file using unlink. You can give php permission by changing the files permission using a php function like chmod($filepath,$permission); When using a command like chmod() make sure to add a 0 in front of the permission number. So for example if you want to set the permission to 777, use 0777 to make sure the number is correctly interpreted as an octal number. Here’s an example chmod($filepath,0777);

      1. Thanks for the quick reply,
        I am still getting permission error:

        [message] => unlink(../user/123123/main.jpeg): Permission denied

        This is my code:

        chmod(“../user/123123/main.jpeg”, 0777);

  13. I went step by step like you said but I am still getting “The requested URL was not found on this server.” Even tried the last two optional steps. Plz help

    1. Hi Aditya,

      I’m going to see if I can replicate the problem you are having. Will get back to you this weekend with what I learn.

    2. Hi Aditya,

      Okay, so I think I may have found the problem. It’s likely that your /Users/username/Sites folder permissions need to be changed. Run the following command in terminal to change your Sites/ permission to 0755. Be sure to change username with yours.

      sudo chmod /Users/username/Sites 0755

      1. Hey Jonathan,
        great tutorial. thanks for that. However, I seem to be stuck at this point. Once I type in sudo chmod /Users/myusername/Sites 0755, I get the following error message:

        chmod: Invalid file mode: /Users/myusername/Sites

        Do you know what is going on here?


        1. Hi Stephan,

          The error is because of the command format.

          Try this:

          sudo chmod 0755 "/Users/myusername/Sites"

  14. Hi, this article is really cool.
    But now I want to try to host my php files in some other directory, instead,

    What do I have to do?

    1. It’s easy. It requires 2 things

      1. Update the virtual host file to point apache to the new location
      2. Make sure that the apache user _www has permissions for your new directory.

      I do this with all my projects. Instead of hosting them in my user directory. I host them the same way I would on my live server /srv/www/

  15. Hi Jonathan,
    Your tutorial is very informative and I’ve tried to follow and read it through a dozen times. I am still stuck on step 1; I never get the browser to say “It Works!”. I’ve been reading pretty much every forum on the matter and nothing seems to make it work for me. (I should also say that I’m pretty new to doing this kind of things). I also tried to install nginx to see if I had more luck with that but it didn’t work either.

    When I run “sudo apachectl” in the terminal I get this:

    AH00112: Warning: DocumentRoot [/usr/docs/] does not exist
    AH00112: Warning: DocumentRoot [/usr/docs/] does not exist
    no listening sockets available, shutting down
    AH00015: Unable to open logs

    and when I run sudo nginx I get:

    nginx: [emerg] bind() to failed (48: Address already in use)
    nginx: [emerg] bind() to failed (48: Address already in use)
    nginx: [emerg] bind() to failed (48: Address already in use)
    nginx: [emerg] bind() to failed (48: Address already in use)
    nginx: [emerg] bind() to failed (48: Address already in use)
    nginx: [emerg] still could not bind()

    From this I draw the conclusion that I’ve maybe messed something really basic up and I don’t know what?
    Do you think you could help me out?

    // Hjalmar

    1. Hi Hjalmar, this looks like a port error and is pretty unusual.

      The errors show that both the Apache and Nginx servers are failing to bind to listening port. This likely means that a process is already using that port.

      Run this command to see what is bound to port 80

      sudo lsof -i :80

  16. Jonathan – great tutorial, thanks (and no thanks to Apple for removing the very simple Web Sharing GUI route!) One suggested edit for the tutorial, which you got in one of the comments, but I think would help is that it’s not apachect1 (number 1) but apachectl (letter l) – they look so alike, I think it’s worth highlighting in the tutorial. Great work, thanks!

  17. I know this article is a little on the old side, but I wanted to request a small correction, for the sake of performance and security. You say to change *all* instances of ‘AllowOverride None’ to ‘AllowOverride All’. This should not be done in (ie, in the root directory of your filesystem) as this allows .htaccess files *outside* of your document root. Instead, AllowOverride should only be enabled in the directory designated as DocumentRoot, or in user directories if you’ve got that enabled.

    1. Hi Rich,

      Good point. On a local server it’s useful to enable .htaccess on all sites. But on a production server you would want to specify the root directory of the site. Such as:

      For those who want to dive deeper into .htaccess it’s also worth pointing out that AllowOverride All doesn’t enable overriding all apache options. Some options such as Multiview need to be set manually.

      AllowOverride Options=All,MultiViews
  18. Well i followed the steps exactly and still get the forbidden error even. 403 You don’t have permission to access /~Tom/phpinfo.php on this server. Anyone have ideas and yes I try the updated sudo commands it didn’t work

    1. Hi Tom,

      It’s probable that your /Sites folder permissions need to be changed to 0755. You can do this by running the following command in Terminal. Remember to replace username with your actual username.

      sudo chmod /Users/username/Sites 0755

  19. Thanks so much for this well written tutorial. Coming from the windows world to the Mac world and having to go through this would have been a lot harder if you hadn’t written this, so much thanks!

    One thing you might want to add is the necessity to hit the enter key after the ^X and “Y” when finishing a file edit. If you leave the terminal screen before doing that (and it’s not as obvious as it should be), your edits are lost. Nice learning lesson, though. lol

  20. Hi Jonathan!

    I’ve got the problem of 404 when I try to access to my phpinfo.php page.

    It can be caused by the apache “AH00558” error? How I can solve it? Thank you in advance!

  21. Hi,
    Since apache 2.4 ( Yosemite have 2.4.9 installed ) the directives :
    Order allow,deny
    Allow from all

    Must be replaced by:
    Require all granted

    Hope it help

        1. Hello I did a little more research and your instructions are missing the following:

          In Step 2 while in the in /etc/apache2/httpd.conf

          Also uncomment out the following two lines:

          #LoadModule userdir_module libexec/apache2/

          #Include /private/etc/apache2/extra/httpd-userdir.conf

          Changing these two lines allowed all of your previous directions to work, good job on everything else, thanks!

  22. Hi Mr. Jonathan

    I’ve just updated new os ypsemite. before that php was working fine and after update apache is wokring fine but php is not working.
    I have applied the step to reconfigure the php but still php is not working.
    below error is coming .

    Not Found

    The requested URL /~username/phpinfo.php was not found on this server.

    any suggestion?

      1. Hi Ashish, so I believe I have found the source of your problem. The permission of your Sites folder needs to be changed to 0755

        Run the following command to ensure Apache has permission to access it. Be sure to replace the string username with yours.

        sudo chmod /Users/username/Sites 0755

    1. Hi Major, I added instructions at the end of the tutorial to show you how to update the permissions of your Sites folder. That should solve your problem.

  23. Thanks for the awesome tutorial. I also got the same error as Holley got. I could fix by adding ” /” after Sites in the step 3 code

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

    And the URL as http://localhost/~geeta/phpinfo.php

    The URL must have ~ before the useraname

  24. Hi Jonathan,
    First Thanks for the explanation above.
    After starting the server also my localhost is refusing connection.
    even then i went ahead and completed all the steps.
    then also the browser is showing connection refused.
    Before i could find ur website i followed the step from another website

      1. And i just creating individual html and php pages for my website…so i thought of putting them in the sites folder created above and running them…

        1. Hi Bhardwaj,

          It seems the error likely has to do with the Apache not having permission to access the Sites folder. It’s taken some time to locate the problem.

          Run the following command in your Terminal. Be sure to replace username with yours.

          sudo chmod /Users/username/Sites 0755

    1. Hi Bhardwaj,

      What error are you getting? In that tutorial he sets up the Apache host settings using the httpd-vhosts.conf file. It is likely you have a mistake in the /etc/apache2/extra/httpd-vhosts.conf file. It’s probably a very simple problem to fix when you know where to look.

  25. Hi after creating the phpinfo.php file and getting a forbidden warning in my browser it turns out that I had skipped much of step 4 which was to change the multiple instances of “allowoverride none” in the httpd.conf file. There are 3 instances that need to be changed not one.

    1. Hi Robert,

      Glad you got it working. Thanks for sharing what you found I think it will help others with the same problem.

  26. Hello,

    I have one quick question. I followed through all the step you gave, but when I typed “http://localhost/~yeaseul/phpinfo.php” in my browser, it doesnt’ work. I can see that there is a file in the path /Users/yeaseul/Sites/phpinfo.php. I am using 10.9.4. Is tihs going to be a problem?

    1. Hi YS,

      Yes you will need this to work. It may be related to the same problem Robert had. In step 4 make sure you replace all the instances of “allowoverride none” in the httpd.conf file

      best of luck

    1. Opening the file phoinfo.php using nano in your Terminal will automatically create it for you if it is not created already

  27. Hey! Loved it all, just hit one bump I can’t get over though!
    When I’m on the step of testing out the php; and enter this in the terminal:
    sudo nano /Users/username/Sites/phpinfo.php
    and then add

    to the file I get this error when trying to save:
    “Error writing /Users/~username/Sites/phpinfo.php: No such file or directory

    It’s a huge pain, I proofread it several times (changed ~username to my actual username btw) and still can’t figure out what is wrong! 🙁

    1. Hi Waleed,

      When trying to open the file in nano using the Terminal remove the ~ from the path

      The path should look like:
      sudo nano /Users/username/Sites/phpinfo.php
      sudo nano /Users/~username/Sites/phpinfo.php

      Let me know if that works for you

      1. Yup! I’ve done that several times over, it keeps on saying
        “Error writing /Users/waleed/Sites/phpinfo.php: No such file or directory”


      2. Yup! I’ve done that several times over, it keeps on saying
        “Error writing /Users/waleed/Sites/phpinfo.php: No such file or directory”

        1. Hi Waleed,

          Try to create the file from within the folder directly.

          Using Terminal

          cd /Users/waleed/Sites/
          sudo nano phpinfo.php

          1. Hej,
            I am having exactly the same problem. Did you solve it?
            (apart from this great instruction! Thanks a lot!)

          2. Sorry, I misunderstand. I am not havin the same problem as Waleed. I am not having poblems on creating this file but when I try to open it in my browser I get the message:
            The requested URL /username/phpinfo.php was not found on this server.
            Even though it exists!

          3. Hi Holley,

            Hopefully I will be able to help you out. Are you using the ~ character at the beginning of the URL?


            Also, Robert had a similar problem. In step 4 make sure you replace all the instances of “allowoverride none” in the httpd.conf file

            If that still doesn’t work, check the phpinfo.php file permissions. Set them to 777 and try agian. Let me know how that goes?

  28. Howdy Jonathan,

    I am getting an error “Firefox can’t establish a connection to the server at localhost.”
    I get the same error on Safari.

    IT Works – shows up

    Gets the above error

    macpro$ whoami

    vi +217 /etc/apache2/httpd.conf
    AllowOverride all

    vi /etc/apache2/httpd.conf
    LoadModule php5_module libexec/apache2/

    macpro$ cat /etc/apache2/users/macpro.conf

    Options FollowSymLinks Indexes MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all


    macpro$ ls -l /Users/macpro/Sites
    total 8
    -rwxr-xr-x 1 root staff 20 Jun 30 18:11 phpinfo.php

    sudo apachectl restart

    I would surely appreciate any help you can give me.

  29. Hey Jon,

    It is saying:

    Not Found

    The requested URL /MitchelBlais was not found on this server.

    I have the Sites folder in MacintoshHD/Users/MitchelBlais/Sites/phpinfo.php
    and it still isn’t working any ideas?


  30. Hi Jonathan! I hope you can help me with this. I managed to get Apache started but when I go to http://localhost I get the Forbidden Error 403.
    I followed all the other instructions without any trouble but I still can’t get the localhost to work, and consequently I can’t get the http://localhost/~username/phpinfo.php doesn’t work either. It gives me the same error.
    My mac is OSX 10.8.5
    Do you know what this is? Please help!

    1. Hi Catalina,

      I believe that the 403 error is caused by a permission problem. I’m not sure why you would be having that problem. Were you able to resolve it?

  31. when I run “sudo apachectl start” it is saying sudo:apachect1 command not found. please advice. Thnaks

    1. Hi Tejaswi,

      The last character in apachectl is a the letter L even though it can easily be mistaken for the number 1

      sudo apachectl start

  32. Hey, thanks for posting this stuff. Wondering if I should follow your directions or use MAMP – just got my first Macbook (yay). Someone wrote me code (php, sql, css) for pages for my new website that I’ll be launching – registration, login/logout, profile, etc – so I want to open them, use them, make any changes so they’ll be functional for me. Thanks.

    1. Well, downloading the project is a good place to start. It is easy to get setup. The problem with using it is that it is very limited with customization. If you need to install a PHP Extension for an application it can be very hard to do with their app. And in the long run it is much better to use a true local environment on your Mac.

      So if you want to get started quickly, start with the MAMP app, then install your own Apache and PHP setup on your machine as you become more advanced

  33. Thank you — had typo trouble but was able to find it and fix it thanks to your clear and easy-to-navigate instructions. Thank you.

    The optimist fell ten stories.
    At each window bar
    He shouted to his friends:
    “All right so far.”

  34. After spending a few hours trouble shooting my php I came across your blog. Step #4 fixed the problem and put a smile on my face. Thanks a mil.

  35. Thank you for providing this information. Now that I have Apache and PHP working, I have one question:

    Will these changes automatically start Apache and PHP on reboot or do you have to execute “sudo apachectl start” when you want to start it? If the latter, is there some way to execute the “apachectl start” at boot?

    Thanks again.

    1. No problem Chuck,

      To make Apache automatically start when your restart your mac run the following command in Terminal

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

      And this to turn it off again run this

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

  36. Hi Jonathan,

    I am very new to this Apache and PHP on a Mac thing. However, I was able to follow your guide with no issue until I got to step five and got the following error: “Error writing /Users/bnax/Sites/phpinfo.php: No such file or directory”. I am using OS X Version 10.9. Any insight would be highly appreciated.

    1. Hi JB,

      Another visitor had the same problem, I’m unsure why this is not working for you.

      Perhaps go to that folder directly and create the file manually using a coding text editor. I use Coda 2.

  37. Hi Jonathan,

    I’m from Malaysia. I’m new on Mac. Just migrated from Windows to Mac.
    I’ve followed all the steps and I had this problem. When just using http://localhost it’s fine but when I try to open the phpinfo.php file it says “Connect Connect To The Server”. I also have restarted the machine the my apache via Terminal.

    1. HI Azman,

      First off, welcome to Mac.

      This problem would point to Apache not running and needing to be started. But because it works on http://localhost that would not be the problem.

      Have you tried restarting Apache?

  38. hi jonathan.

    i followed all the steps you posted. however, when i use localhost/~username/phpinfo.php i got an error ‘you don’t have permission to access /~username/phpinfo.php on this server.

    what should i do?

      1. Sorry, the angle brackets weren’t shown in my previous post. Here’s what I meant to say:

        The username you enter in the username.conf is case-sensitive.

        For example, if your site is located under “Users/Robert/Sites”, then the first line in robert.conf should be:

        <Directory “/Users/Robert/Sites”>

          1. Thanks for your comment Robert! I’m sure it will be very helpful to someone with the same problem

    1. Yes, it’s really easy to setup using virtual host files and your local /etc/host file. I can make a tutorial on it if you would like.

      1. Thank you for this great tutorial. Can you please make one for virtual host file? Or direct me to where I can find it if you already made one.


    1. Hi Phil,

      Yes you can make better URLs by setting up virtual hosts. It’s very easy to do.

      Then you can set a URL like


      I don’t have a tutorial for it yet, but will create one and post it for you.

  39. Is there a way to change “localhost” or “localhost/~username” to something else? Like “local” or “dev”. I’ve tried googling it but don’t think I’m searching with the right terminology.

    1. Yes, it is actually very easy. You just need to enable virtual hosts and then setup a pointer in your /etc/hosts file. I will create a tutorial to show you how to do this.

  40. Hi Jonathan
    I have been having the same problem for a while now, and I follow all comments and tutorials and it always ends up not working, and me having to start again. Yours has come the closest so far, but still I am unable to progress past this point.

    This is my machine name and my short name assigned by the system: Petars-MacBook:~ petar j$ . My short name on the user directory is: petar j

    Whenever I try and (re)configure the apache user, I have tried using all of the following short names tyoing them in as follows: “petar j” , “petar%20j , petar j$ and “petar_j” all with no success! As a result of this I am unable to configure anything any further.

    Is there a fixed rule when there is a “space” assigned in the short name when I type this into the terminal, and then when I am adjusting the code?

    I have also copied the apache2 error_log for your info:

    “[Thu Oct 24 15:30:48 2013] [notice] caught SIGTERM, shutting down
    [Thu Oct 24 15:30:48 2013] [warn] Init: Session Cache is not configured [hint: SSLSessionCache]
    httpd: Could not reliably determine the server’s fully qualified domain name, using Petars-MacBook.local for ServerName
    [Thu Oct 24 15:30:48 2013] [notice] Digest: generating secret for digest authentication …
    [Thu Oct 24 15:30:48 2013] [notice] Digest: done
    [Thu Oct 24 15:30:48 2013] [notice] Apache/2.2.24 (Unix) DAV/2 PHP/5.3.26 mod_ssl/2.2.24 OpenSSL/0.9.8y configured — resuming normal operations
    [Thu Oct 24 15:34:19 2013] [error] [client fe80::1] File does not exist: /Library/WebServer/Documents/petar j
    [Thu Oct 24 15:34:47 2013] [error] [client fe80::1] File does not exist: /Library/WebServer/Documents/petar_j
    [Thu Oct 24 15:35:22 2013] [error] [client fe80::1] Options FollowSymLinks or SymLinksIfOwnerMatch is off which implies that RewriteRule directive is forbidden: /Users/petar j/Sites/
    [Thu Oct 24 15:42:02 2013] [error] [client fe80::1] Options FollowSymLinks or SymLinksIfOwnerMatch is off which implies that RewriteRule directive is forbidden: /Users/petar j/Sites/”

    Mac OS X 10.8.5 Macbook Pro

    Looking forward to your reply.

    Many thanks

    1. Hi Petar,

      It may be that because you have a space in your name.

      On a mac any path with a space in it will need quotes wrapping them.

      If you were running this command for example

      sudo chmod 644 /etc/apache2/users/user name.conf

      It would need to look like this to work

      sudo chmod 644 “/etc/apache2/users/user name.conf”

      Hopefully that helps

  41. Hey Jonathan,
    I´ve gone through the steps in your tutorial but I get the “Firefox can’t establish a connection to the server at localhost.” when trying to open the phpinfo.php
    Everything looks ok in all the steps but this last one just doesn´t work. Phillip Friese talked about a missing folder or something, but I don´t know how to check this in terminal (new to terminal…)

    What can I do to figure this out? Help is greatly appreciated.

  42. You help a lot, thanks very much. With a little attention and search yours hints make me into the Apache and PHP for MAC.

  43. Got to step 5 with no issues. When I attempt to open the phpinfo.php file in Safari I get the error “Safari cannot connect to the server localhost. After step 1 I got the “It Works” in Safari. I did restart teh Apache server after seting up the user.conf file.

  44. Followed every step. I get the illustrious

    403 Forbidden

    You don’t have permission to access /~username/index.html on this server.

    of course, I changed the “username” to my username. I haven’t tried php yet because I don’t need php. I just want to host some files on a server. Are there any extra steps I should be taking for this function?

    I’m using 10.8.3

    1. You may need to update your Site folder to give Apache permission to access it. I’ve added a section at the end of Part 1 to show you how to do that.

  45. Hi Jonathan

    I have now spent a 2 x day’s trying to get this set-up to work and now officially don’t know anymore. I am pretty new to this, so please bear with me if I do not use the correct terminology.
    I am trying to set-up my machine to host a website I propose building. I started by installing the complete MAMP package. Doing it this way, I was unable to get the Apache Server to run. I unintalled the package and found your tutorials on-line and I have subsequently followed your tutorial to the letter. I have checked and double checked each and everyone of your suggested settings, but all I get when I type in http://localhost I currently get ‘Failed to open page” Safari can’t open the page…..”localhost” Yesterday I got a “Error 404 message” when trying the same thing, so I am not sure if this progress or not? My mac short name is “petar j” I have put the short name in ” ” I have a Sites Folder, I have created and see the “phpinfo.php” file. I do also have existing iWeb Folders in my configure Sites Folder, not sure what other information you may require to assist me further?

    What am I doing wrong, or what do I need to change or what other settings do I need to do?

    Many thanks in advance?

    1. Hi Petar,

      It’s difficult to diagnose your problem without seeing your setup. Are you still having this problem?

    1. Hi Bhargav,

      Hopefully I can help. Have you tried restarting Apache and then entering the URL in your browser again?

  46. This all works on my machine but how can I access the page from another computer on the same network?

  47. Just wanted to say thanks for the tutorial, works great! I tried three other tutorials before yours and none of them worked for me….so thank you!

  48. Hello,

    thank you for the guide! But I have a problem: even the very first step does not work. After starting apache with “apachectl start” and typing in both “http://localhost” and “localhost” Safari says it is unable to connect to the server. Am I doing something wrong?

    1. I am sorry for double-posting, but I found some things out. First, I am indeed using an upgraded Mac OS X, I have been using it since Snow Leopard.

      bash -x /usr/sbin/apachectl -k start gave me an interesting output:
      “+ /usr/sbin/httpd/ -k start
      (2)No such file or directory: https: could not open error log file /private/var/log/apache2/error_log”

      And indeed, /usr/sbin/httpd/ is completely missing. How may I fix this major problem? And will there be some other important things missing?

        1. I am using Mac OS X 10.8.4, upgraded from Snow Leopard over Lion. But I fixed the problem by myself! I just created a the missing …/log/apache2 folder and chmod-ed it and now it works without a problem! Your How-To “php” just worked fine, thank you!

  49. Hey there,

    First off thank you for the great tutorial. I am a bit lost though.

    I have walked through all the steps here. When I go to “localhost” I get back the message that “It Works” ok so we’re good there. In the users directory I have the folder named “Sites” in there is the “phpinfo.php”. Ok great so those commands worked as well.

    Yet when I try the final step to test “http://localhost/~TenfoldSystems_MBP/phpinfo.php” I am getting that the page failed to open because it cannot connect to the server. I tried running the restart command and same thing applies. Could there be an issue since my short name is “TenfoldSystems_MBP” ?

    1. Hi James, I don’t think it is the short name. It sounds like you did that correctly. I am going to try to recreate the problem on my server to see if I can duplicate the problem.

      1. Hi James, to confirm. Does the error you are getting say, “You don’t have permission to access /~TenfoldSystems_MBP//phpinfo.php on this server.” ?

        1. Actually. I restarted: sudo apachectl restart and restarted the computer. Then started: sudo apachectl start which was successful and let the server be found to load the php page created in the sites folder.

          Got through the rest of the steps successfully. Have MySQL and phpMyAdmin installed. Now just trying to figure out how to implement the MySQL for my website. (Just getting into web design so that’s why I don’t know.) If you create something local server through the phpMyAdmin then does it provide the code for website use? Or is this only really for local testing? Already have a dedicated server and website up.

          1. Nice. Yes having the MySQL installed on your localhost is best for local testing and development. You will just need to install MySQL on your dedicated server. What OS are you running on it?

          2. Server Settings
            Apache version 2.2.22
            PHP version 5.2.17
            MySQL version 5.5.31-cll
            Architecture x86_64
            Operating system linux

            The cpanel does not have any controls like my old godaddy did Foy MySQL.

            Computer osx 10.8.4
            Using dreamweaver

    1. Hi Tom. This is because the php module is not enabled in the httpd.conf file. Check to make sure the line of code LoadModule php5_module libexec/apache2/ in the file /etc/apache2/httpd.conf is not commented out. You can see instructions in Step 2

      1. Thanks for answering my question, Mr. Whiting. As embarrassing as it is to have to admit, in the short time between my question and your response everything that I had gotten to work following your steps has stopped working all together. I’m pretty sure my brain exploded. Parts of it that were clicking just a few weeks ago when all this was making sense are not there. Someday, though…

  50. Please I was confortable untill step 5.
    I got this message on firefox:
    The connection was reset.The connection to the server was reset while the page was loading.
    I got osx 10.8.2.
    I am still studying php now and for days I cannot get enable.Why?
    However I search google but no solutions.Please help.

  51. Thank you Bro, this is a great tutorial but i got stuck here on this part:

    how to ad this directory on terminal after the password? Could you give me specifics details if possible with IMAGES? thanks

    Options FollowSymLinks Indexes MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all

  52. Hi,

    Thanks for this guide. So I’m having a hard time at Step 3. Apache2 works since I can type in http://localhost and it says “It Works” but I’m having a problem setting up the configuration file.

    My mac’s shortname is odd. It’s “Alex (Main”). This was the default. I’m not a terminal wizard, so I’m not sure how to enter this.

    Could you help me set up my configuration file the right way? My end goal is to be able to load Dokuwiki.

    1. Hi Alex
      Try this. Put the path in quotes when you type it in a file or on the command line. When a path has spaces it needs to be either wrapped in quotes. ie. “path with spaces” or escaping the spaces in the path ie. path\ with\ spaces

      1. Hey Jonathan,

        Thanks for that tip. I wrapped in quotes, and I got a .conf file ‘Alex (Main)’.conf

        I proceeded through all the steps, but when I go to my browser and enter http://localhost/~Alex%20(Main)/phpinfo.php I get a response saying ‘Forbidden

        You don’t have permission to access /~Alex (Main)/phpinfo.php on this server.’

        I’m at a loss. Any words of wisdom?

        1. That sounds like the file permissions need to be set to allow visitors to read.

          Try this. sudo chmod 644 your conf file and also sudo chmod 755 your phpinfo.php file

          1. Check to make sure you restarted your apache server correctly. In your terminal run sudo apachectl restart. Apache won’t recognize the new .conf file until after it is restarted.

  53. Hello thx for sharing the knowledge. I’m using the mac 10.8.3 version and i found that has no websharing function s in this version. And i follow ur step until step5 after finish “http://localhost/~denni/phpinfo.php” i test in Chrome shows 404 Not Found. Its that only work in Safari ?

        1. Hi Mary,
          I’m trying to recreate the problem. I have two quick questions for you.
          1. After setting up the username.conf file did you restart the apache server? sudo apachectl restart
          2. If you did restart the server, is the path in the conf file directory set correctly? /Users/username/Sites” > (it’s case sensitive)

          Let me know, and we can keep figuring out the problem from there.

Leave a Reply to Barun Cancel reply

Your email address will not be published.

Previous post A challenge! I accept
Next post How to find the owner and group of a directory in Ubuntu