How to configure the web server in OS X Mountain Lion



Mac OS X in its recent versions with default web server as one of the key built-in components. Prior to the Mountain Lion version, users can easily activate the web server through web sharing option located in the sharing preferences pane. However, this component is removed from the OS X Mountain Lion version. Here I will describe how to configure the web server in Mountain Lion and MY SQL, PHP and PhpMyAdmin.

How to configure the web server in OS X Mountain Lion

Configuring the Apache server

Fortunately, the Apache server is pre-installed on Mac OS X, so there is no need to install it again. Follow the procedure below to start the Apache server.

  • Launch Terminal on your Mac and type the following command.
    sudo apachectl start

This will trigger the Apache server to start and to make sure open the browser and type http: // localhost in the address bar. If you witness a message It works then the Apache server is working fine.

To restart use

sudo apachectl restart

To stop use

sudo apachectl stop

Activation of the PHP module

To run a static HTML file, the Apache server is fine, but the PHP module is required to run a complicated setup like WordPress. PHP is also pre-installed on Mac, but not enabled by default.

Type the following command in terminal and this will open the Apache configuration file

sudo nano /etc/apache2/httpd.conf

Delete the list until you find the row

#LoadModule php5_module libexec/apache2/libphp5.so

Now remove # from the above command. Save the changes using Ctrl + O and exit using Ctrl + X and restart Apache. That’s it, the PHP module is activated on your Mac.

Configure the sites folder

Apache server files will be stored in / Library / Web server / Documents on your Mac. If your mac has multiple users, configure the web server to serve files to different users using http: // localhost / ~ username.

  • Launch Finder on your Mac, then go to the home folder, locate sites case. If it is not available, create a new one.
    Folder sites
  • Type the following command in the Mac terminal
    sudo nano /etc/apache2/users/username.conf
  • Replace the username in the above command with the login username.
  • Now paste the code below into the config file.
    <Directory "/Users/username/Sites/">
    Options Indexes MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all
    Directory>

    Now replace the username again with the login username.

  • Enter the following command
    nano /Users/username/Sites/phpinfo.php

and paste this line

 phpinfo(); ?>

Save the file and restart the Apache server.

  • Type now http: // localhost / ~ username / phpinfo.php in the address field of your browser and you will see the PHP information page.

Configure MySQL

By default, MySQL does not come with Mountain Lion, so you have to download and install it manually.

  • Download MySQL installer for Mac and after downloading open the installer and you will find two .pkg files and one .prefPane file. Install all of these three files.
  • After installing them, go to system preferences> My SQL and start My SQL.
    mac-web-server-start-mysql
  • Type the following command in the terminal to configure the MySQL password.
    /usr/local/mysql/bin/mysqladmin -u root password 'yourpasswordhere'

    To replace your password here with your desired password in the command above.

Install PHP MyAdmin

Finally, visit the browser and type http: // localhost / ~ username / phpmyadmin. In this page you can lging and create the database.


Comments are closed.