How to set up a Local Server Environment using MAMP

If you have spent any amount of time just in front-end web development, you may have started to take it for granted that aside from FTP/transferring your files, all you really need to do your work is a web browser. HTML, CSS and JavaScript (the three foundational elements of the front-end) only require a web browser to compile and produce a viewable website. As soon as you start involving scripting languages such as PHP, Python or Perl, however, you are going to have to bring a server into the mix. For many, the first need to work with a server comes from having to install WordPress or maybe another CMS (in which case you’ll need a server installed with PHP and MySQL).

In the process of working on any development project, there are huge advantages to doing all of the development work on a “local” version, and then transfer the finished product to the live site once it is ready for production. In order for that to be possible, there are many different “local server environment” applications that create a server, directly on your local machine, without even need for internet to run it. One of the most popular of these is MAMP.

Install MAMP

MAMP stands for Macintosh, Apache, MySQL, and PHP (also Perl and Python), as these are the technologies set to run in its server environment.

The standard version of MAMP is available totally for free, and although there is a Windows-specific version called WAMP, MAMP itself runs on both Mac OS X and Windows.

To download and install MAMP, simply head over to the official downloads page, download the latest version for your operating system, and run the installation.

After running the installation, and starting the application, you should see the following window:

how to setup a local server environment using MAMP

Click “Start Servers”, and wait for the power icon to turn green. If you’re not logged into the superuser/administrator account, you may be asked for the computer’s admin password to make further changes.

Once the power icon turns green, a new page should open up in your browser. If it does not, click on the “Open WebStart page” button.

If you see a page that looks something like below, then you’ve successfully set up your server environment:

how to setup a local server environment using MAMP

Change your project directory

To work with a specific project (say, one with a WordPress installation), click on the “Preference” button on the main MAMP window. Select the “Web Server” tab, and then click the folder icon next to “Document Root”. A pop-up window will appear, asking you to select the root directory of your project. Hit select and then “OK” in the preferences window.

You may need to hit “Start Servers” again if you changed the project directory while the servers were already started.

Test PHP

To test that PHP is correctly running on the server, you can save the following file as index.php, and then select the containing folder as the document root in MAMP:

<!DOCTYPE html>
<html>
​
    <head>
        <meta charset="utf-8"
        <title>MAMP Demo</title>
    </head>
    
    <body>
        
        <p>This is a page to test MAMP</p>
        
        <p><?php echo date('Y'); ?></p>
    </body>
</html>

Click on “Open WebStart page” or type in localhost:8888 in your web browser (or just localhost on Windows), and you should see the following if PHP is correctly running:

how to setup a local server environment using MAMP

Resources

Post a Comment

Comments are moderated. Your email is kept private. Required fields are marked *

© 2018 Sunlight Media LLC - Web Design Company