Apache Web Server For Mac Os



16 13 likes 31,725 views Last modified Jan 31, 2019 11:25 AM

Here is my definitive guide to getting a local web server running on OS X 10.14 “Mojave”. 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.

The project is jointly managed by a group of volunteers located around the world, using the Internet and the. On my Mac OS X, Web Sharing is disabled in System Preferences - Sharing - Services - 'Personal Web Sharing'. Still, when I type 'localhost' in the browser, I get the 'It works!' Message, meaning that Apache is still running. Mac OS X version 10.4 (Tiger) or later. A Java Runtime Environment 6 or later. Verify the integrity of the file. The PGP signatures can be verified using PGP or GPG. First download the KEYS as well as the asc signature file for the relevant distribution. Then verify the signatures using.


Note: This user tip is specific to macOS 10.14 “Mojave”. 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 177, 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 177 by typing '177G' (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 178, 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 174:

#LoadModule userdir_module libexec/apache2/mod_userdir.so

to

LoadModule userdir_module libexec/apache2/mod_userdir.so


and do the same at line 511:

#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

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:

Download apache mac

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

Mac


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


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:

http://localhost/


It should say:


It works!


Now try your user home directory:

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


It should say:


My site works


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.


Install apache on mac

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

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

Apache For Mac


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'.


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


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:

sudo apachectl graceful

Although Windows 10 leads the market in terms of active users, there are still a lot of Mac owners out there. In fact, Macs still operate a $25 billion venture for Apple.

If you’re a Mac user and a business owner, it’s likely you’ll want to do things with a computer you’re more familiar with. This also includes running a web server to host your site and other online needs, using your Mac.

That said, you’re looking to turn your Mac into a web server, you need to learn a few things. This might be a better option for some instead of relying on cheap web hosting sites. Don’t worry if you don’t know how to use your Mac as a server; we’ve got you covered.

Simply follow the steps below to get ahead of the game:

1. Install and Configure MAMP (Mac, Apache, MySQL, PHP)

This is an open-source program that gives you the ability to host a website using a Mac computer. Download this app to your Mac computer using a stable connection and install it once it’s finished. As soon as it’s done, navigate to the folder called /Applications/MAMP.

The server configuration files, as well as the website you make, will go to this folder. You can now start configuring MAMP by searching for the file called MAMP.app. Double-click on it to get the HTTP server going.

As soon as it appears, you can proceed to click on Preferences. This will show you choices regarding MAMP and MAMP Pro. Unselect these options to ensure that your server keeps running without the need of the application itself.

Open the Ports tab afterward and make sure you choose the default Apache and MySQL ports. This will ensure that your Apache and MySQL servers are at port 80.

2. Sharing with FTP

Go to the System Preferences and select the Sharing tab as soon as you’re done with the initial setup. Click on the option “File Sharing” and select the Options button. Once there, you can click on “Share files and folders using FTP” and press the done button.

The next step is to unselect the option for “Web Sharing” if the system chose it as the default. To control the computer using SSH, select the option “Remote Login”.

3. Port Forwarding

Server

Do you need to access your website from a device other than the original host? If so, you will need to have a router in place. This allows you to forward the right HTTP ports to your current computer.

It’s important to remember that the specific procedures will vary across different routers. The good news is that the basic steps are almost the same. To start this, you need to go to the System Preferences section and go to Network.

As soon as you’re there, take a note of your IP address shown under Status. You can then go to a website called Port Forward. Scroll down and start looking for your router’s model and once found, click on it.

You’ll get taken to the next page where you’ll get the information related to your router’s external IP. Write it down and find Apache in the gigantic list below and select it.

You can now enter your local IP address in the small box that appears on the next page. Follow the instructions to ensure that you finish forwarding the ports on your router.

4. Install a CMS (Content Management System)

Using a CMS helps making, reviewing, editing, and publishing content much easier. There are a lot of free CMS you can use for your website. But the most popular ones out there include:

  • WordPress
  • Joomla
  • Drupal

This guide will cover the steps on how to set up a WordPress CMS. You need to download the WordPress ZIP file from their official website. Unzip the file and transfer the WordPress folder to the /Applications/MAMP/htdocs directory.

Go to the WordPress folder and use a text editor to open the wp-config-sample.php. Replace both the ‘usernamehere’ and ‘yourpasswordhere’ fields with ‘root’. Also, you need to change the ‘putyourdbnamehere’ with your own database’s name.

Install Apache Web Server Mac Os X

You might still need to make a database while doing this step. If so, leave it blank for now and come back later to fill it up. As soon as you make a complete configuration of WordPress, the CMS will guide you on how to make your web pages.

5. Make a New Database

To make the database, you need to start by opening the MAMP.app program. Click on “Open Start Page” since it launches MAMP’s start page in your preferred web browser. As soon as it’s open, you should select the “phpMyAdmin” on the toolbar located on top of the page.

Apache Web Server Mac Os

Under “Create new database”, you can now type the appropriate name for your database. As soon as you’re done, click on the Create button. Go back to the wp-config-sample.php file and replace ’putyourdbnamehere’ with that database name.

You can then save the file as wp-config.php to finish the entire process.

Using Mac OS Server for Web Hosting

The built-in Apache server has limitations that only exists in the standard Mac OS version. The limitations go away as soon as you opt for the Mac OS Server. This offers a lot of great server features like:

  • Mail Servers
  • Web Servers
  • File Sharing
  • Calendar and Contacts server
  • Wiki Servers

There are more features you can avail for your internet server. It’s especially great if you’re wondering, “what does a server do?” when it’s at full capacity. The Mac OS Server is available for purchase at the app store for about $19.99.

Take note, buying the Mac OS Server will proceed to restore all your web sharing services. This adds a lot of value to your Mac for both short and long runs.

Run a Web Server Today

If you’re asking how does a web server fit on Mac, you can use this guide to answer the question. Following these steps will ensure that you get it up and running within a day. But for full-on websites, you need better web hosting services to fit high traffic volumes.

Do you need help with a web server for the Apple Mac? If so, you can contact us today and we’ll assist you to get started. Our lines are open and we hope to hear from you soon.

Login

×