Localhost Server For Mac

OS X: You need only one tiny command to start a web server from any directory through OS X's terminal. If you've got a web site lying around and need to test it out, this is possibly the fastest. Thats all is needed to start Apache web server on Mac OS X, now you need to verify it by launching browser and visiting page You should get a page with message “It works!”. Now we can proceed further for setting up PHP and MySql but before that I want to make some tweaks to setup my development environment. Make sure that your port number is correct. The URL should not literally say localhost:port. On some machines it’s localhost:80 and others it’s localhost:8888. You can find your port by opening the MAMP Preferences screen, and looking in the Port tab. The correct port number for you will be within the Apache Port box.

  • Brief description. In Web Development, a localhost is a local server environment in which we can test and use server side scripts on our computer. We can set-up our localhost environment with an Apache server application, MySQL and PHP. If you are a Windows or Linux user, you can download and install XAMPP from Apache Friends. You can also use XAMPP on Mac!
  • I've been developing web apps for several months now on my mac using the built in apache server and everything has been fine. I restarted my mac this morning and now when I try to connect to anything on localhost I get the error: 'Could not connect to localhost'. Here are some things I have already checked: Apache is running.

We’ve already covered the topic of installing a local server on a PC and since I don’t want to be one of those who disses Mac users we’re going to learn how to setup a server on a Mac (we’ll use MAMP for that). MAMP stands for Macintosh, Apache, MySQL, and PHP. As everything on Mac, it’s gonna be really easy and you’re not supposed to have a Ph.D in any discipline to cope with that. Now, why bother at all? Well, you may need a local server on your Mac if you want to test-drive some WordPress plugins or widgets. Alternatively, you may want to tweak some settings on your WordPress but you don’t really feel comfortable doing that on a live site.

In case you’re already running a SaaS business, you may want to make sure that your SaaS onboarding process is not holding you back.

By the way, you can check awesome Drupal code snippets if you want to install a local server for running Drupal on your local machine (computer).

Before we actually get started, let me explain why you need specifically MAMP on your Mac but not something else:

  • it’s user-friendly (easy to install and use)
  • it’s compatible with Mac (duh!)
  • it’s exactly what the doctor ordered (no redundant stuff you don’t actually need)

So, let’s do it.

Screencast: How to Setup MAMP on Your Mac

For starters, check out the video that explains how to get MAMP on your Mac. If you’re not sure about something, don’t hesitate to leave your questions in the comments.

Step-by-Step Instructions on MAMP Installation

  1. To get the ball rolling, you need to go to mamp.info
  2. Once you’re on the site, you need to just click the large logo with an elephant
  3. Now you copy of MAMP should start downloading.
  4. When your download is complete, double-click the MAMP .pkg file to unzip it and start installing
  5. That done, just click the Continue button in the dialog window that appears
  6. The next dialog box (window) will explain you what it’s about to install, just click Continue if you agree
  7. Now you need to read the Software License Agreement, make sure that it’s Ok with you and click Continue if it’s the case
  8. And before you start the actual server installation you can see the info about what exactly will be installed on your Mac and how much space it’ll take up
  9. Once you click the Install button, it’ll prompt you to enter your Mac login and password to make sure that you’re authorized to install software on your Mac (if you’re not, stop using the Mac that does not belong to you! :))
  10. And now the actual installation should finally start
  11. You should be good to go within 5 minutes (as you can see on the screenshot above)
  12. With that done, just close the window and you can go to your Applications to run the MAMP you’ve installed a minute ago. Just click on the big elephant icon in the Applications => MAMP folder
  13. Once you can see your MAMP server dialog window, just click the Start Servers button to get your local server started
  14. When you see both the Apache Server and MySQL Server dots get green, you’re up and running with your MAMP local server. You’ve installed it! Damn, you’re AWESOME
  15. Once your servers got started, you (your browser) will be redirected to http://localhost:8888/MAMP/?language=English where you’ll be able to see basic info about your server that you’ve installed locally
  16. If you want to see more specific and comprehensive info about your server, you can click the phpinfo link
  17. Now you can run your .PHP files, you just need to put them in the htdocs folder.

In Conclusion

And that’s about it. As you could see for yourself, it’s not rocket science at all, but it surely requires a bit of patience. Now you can install any CMS (like WordPress, Joomla, Drupal and the like) or just run php files for educational purposes if you happen to be learning PHP at the moment. In either case, it’s really convenient to have a real life server at your disposal.

Should you have any questions regarding this tutorial, by all means, let me know in the comments.

25 20 likes 19,446 views Last modified Oct 9, 2019 6:12 PM

Here is my definitive guide to getting a local web server running on OS X 10.15 “Catalina”. This is meant to be a development platform so that you can build and test your sites locally, then deploy to an internet server. This User Tip only contains instructions for configuring the Apache server, PHP module, and Perl module. I have another User Tip for installing and configuring MySQL and email servers.


Smplayer for mac versions. Note: This user tip is specific to macOS 10.15 “Catalina”. Pay attention to your OS version. There have been significant changes since earlier versions of macOS.Another note: These instructions apply to the client versions of OS X, not Server. Server does a few specific tricks really well and is a good choice for those. For things like database, web, and mail services, I have found it easier to just setup the client OS version manually.


Requirements:

  1. Basic understanding of Terminal.app and how to run command-line programs.
  2. Basic understanding of web servers.
  3. Basic usage of vi. You can substitute nano if you want.


Optional: Xcode is required for adding PHP modules.


Lines in bold are what you will have to type in. Lines in bold courier should be typed at the Terminal.Replace <your short user name> with your short user name.


Here goes.. Enjoy!


To get started, edit the Apache configuration file as root:

sudo vi /etc/apache2/httpd.conf


Enable PHP by uncommenting line 186, changing:

#LoadModule php7_module libexec/apache2/libphp7.so

to

LoadModule php7_module libexec/apache2/libphp7.so

(If you aren't familiar with vi, go to line 186 by typing '186G' (without the quotes). Then just press 'x' over the '#' character to delete it. Then type ':w!' to save, or just 'ZZ' to save and quit. Don't do that yet though. More changes are still needed.)


If you want to run Perl scripts, you will have to do something similar:


Enable Perl by uncommenting line 187, changing:

#LoadModule perl_module libexec/apache2/mod_perl.so

to

LoadModule perl_module libexec/apache2/mod_perl.so


Enable personal websites by uncommenting the following at line 183:

#LoadModule userdir_module libexec/apache2/mod_userdir.so

to

LoadModule userdir_module libexec/apache2/mod_userdir.so


and do the same at line 520:

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

to

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

Now save and quit.


Open the file you just enabled above with:

sudo vi /etc/apache2/extra/httpd-userdir.conf

Minecraft Server Localhost

and uncomment the following at line 16:

#Include /private/etc/apache2/users/*.conf

to

Include /private/etc/apache2/users/*.conf

Save and exit.


Lion and later versions no longer create personal web sites by default. If you already had a Sites folder in Snow Leopard, it should still be there. To create one manually, enter the following:

mkdir ~/Sites

echo '<html><body><h1>My site works</h1></body></html>' > ~/Sites/index.html.en


While you are in /etc/apache2, double-check to make sure you have a user config file. It should exist at the path: /etc/apache2/users/<your short user name>.conf.


That file may not exist and if you upgrade from an older version, you may still not have it. It does appear to be created when you create a new user. If that file doesn't exist, you will need to create it with:

sudo vi /etc/apache2/users/<your short user name>.conf


Use the following as the content:

<Directory '/Users/<your short user name>/Sites/'>

AddLanguage en .en

AddHandler perl-script .pl

PerlHandler ModPerl::Registry

Options Indexes MultiViews FollowSymLinks ExecCGI

AllowOverride None

Require host localhost

</Directory>


Now you are ready to turn on Apache itself. But first, do a sanity check. Sometimes copying and pasting from an internet forum can insert invisible, invalid characters into config files. Check your configuration by running the following command in the Terminal:

apachectl configtest


Iis Server Localhost

If this command returns 'Syntax OK' then you are ready to go. It may also print a warning saying 'httpd: Could not reliably determine the server's fully qualified domain name'. You could fix this by setting the ServerName directive in /etc/apache2/httpd.conf and adding a matching entry into /etc/hosts. But for a development server, you don't need to do anything. You can just ignore that warning. You can safely ignore other warnings too.


Turn on the Apache httpd service by running the following command in the Terminal:

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


In Safari, navigate to your web site with the following address:

Localhost Server For Mac Catalina


It should say:


It works!


Now try your user home directory:

http://localhost/~<your short user name>


It should say:


My site works

Localhost web server


Now try PHP. Create a PHP info file with:

echo '<?php echo phpinfo(); ?>' > ~/Sites/info.php


And test it by entering the following into Safari's address bar:

http://localhost/~<your short user name>/info.php


You should see your PHP configuration information.


To test Perl, try something similar. Create a Perl test file with:

echo 'print $ENV{MOD_PERL} . qq{n};' > ~/Sites/info.pl


And test it by entering the following into Safari's address bar:

http://localhost/~<your short user name>/info.pl


You should see the string 'mod_perl/2.0.9'.

Parallels Access Localhost On Mac


If you want to setup MySQL, see my User Tip on Installing MySQL.


How To Start Localhost Server

If you want to add modules to PHP, I suggest the following site. I can't explain it any better.


If you want to make further changes to your Apache system or user config files, you will need to restart the Apache server with:

Localhost Server For Mac Windows 10

sudo apachectl graceful