Home » Software » How to set up Web Server on Windows, Linux, and Mac Using Apache

How to set up Web Server on Windows, Linux, and Mac Using Apache

How to set up Web Server on Windows, Linux, and Mac Using Apache

Apache

Getting Apache

Apache is an open source web server that you can download and install for free. This tutorial will give you the preliminary info you need — considering the operating system you’re using — to decide how to begin selection and setting up of your web server software program and even make your own web host. Take note, also, that an all-in-one installation kit like XAMPP might work for your needs. We provide information on that option as well in this tutorial. Choosing a version of Apache is important. Apache is currently available in three versions: Apache 2.0, Apache 2.2, and Apache 2.4. All versions are supported and improved. The PHP software operates with all three versions, but some other software related to PHP might have problems with Apache 2.4.

On Windows, Apache 2.4 is currently not available. Like most software, Apache grows as new versions come out. Some 3rd party components might not work properly on all three versions. Because PHP is a module, you should check the web page for the current status of PHP with Apache versions at

www.php.net/manual/en/install.windows.apache2.php

Try to install the most current release of the Apache version you choose so that your Apache server includes all the latest security and bug repairs.

Downloading from the Apache website

Apache for all platforms is available on the official Apache website. You can download source code to compile on your operating system. Compiling and installing source code is not hard on Linux and Mac, but it needs expert knowledge and software program on Windows.

Binary files — compiled, ready-to-run data files that just need to be copied to the correct location — are obtainable for Windows. To get Apache from the Apache website, go to http://httpd.apache.org. Browse to the section for the Apache version you want to download click the appropriate link for the version you want to download. A download page with links to download the current versions displays.

Apache for Windows

The Windows binary file is available with an installer, which will install, configure, and start Apache. On the Apache website download page, find the section for the Apache version you want. Click the link for the Win32 Binary (MSI Installer) to get the installer file. Although Win32 source code is also available to download in a Zip file, compiling and installing Apache from source code is difficult and should be attempted only by advanced users. It requires advanced knowledge and special software.

Apache for Linux

Most recent versions of Linux include Apache. If you need to install Apache or upgrade to a more recent version, most Linux distributions provide software either on their website that you can download or through their package management software that will install on your specific Linux system. In addition, most Linux systems provide a utility specifically for downloading and installing software. For instance, Fedora provides the yum utility that downloads and installs software from the Fedora website. See the documentation for your Linux distribution for details on how to download and install software on your Linux system. In certain cases, you might need to install Apache manually. The software provided by the website might not be the most recent or might not be configured to your needs. To install manually, you need to download the source code from the Apache website at http://httpd.apache.org. You can easily compile and install Apache from the source code. This process isn’t as technical and daunting as it sounds.

Apache for Mac

Apache comes currently installed on most recent versions of Mac OS X. If you test Apache by typing localhost in your browser address window and it does not show a web page, it is most likely installed but not started. You need to start it first. If you need to install Apache because it isn’t installed or an old version is installed, download the source files from the Apache website to compile and install on your Mac.

All-in-one installation kits for web server

XAMPP interface

XAMPP interface

You can obtain some kits that contain and install PHP, MySQL, and Apache in one procedure. These kits can greatly simplify the installation process. However, the software provided might not include the features and extensions that you need. XAMPP is a popular all-in-one installation kit that contains Apache, PHP, and MySQL. XAMPP has stable versions available for Windows and for several versions of Linux. XAMPP is available at www.apachefriends.org/en/xampp.html. WAMPServer is a popular installation kit for Windows that provides recent versions of Apache, PHP, and MySQL. It also installs phpMyAdmin, a utility for managing your MySQL databases. WAMPServer is available at www.wampserver.com/en. MAMP is an installation kit for Mac that installs Apache, PHP, and MySQL for Mac OS X. This free package installs a local web server environment on your Mac. You can find MAMP at www.mamp.info. You can test to publish HTML, PHP, and CSS files using these kits.

Validating a downloaded file

After downloading The Apache, You need to verify its file integrity. The Apache website provides methods to verify the software after you download it, as a security precaution to ensure that the file hasn’t been modified by hackers. You can use the MD5 method or the PGP method for verifying the file. Basically, the same process is used to validate the file for PHP, MySQL, and Apache. You can find instructions for verifying the downloaded file below. On the Apache website, click the MD5 website link to see the MD5 signature discussed in the instructions.

Installing Apache

The following subsections describe installing Apache on Windows, Mac, and Linux.

Installing Apache on Windows

You can install Apache on almost any version of Windows. You can not install Apache with the following directions if Internet Information Services (IIS) is already operating on port 80. If IIS is running, you will find the IIS console at Start ➪ Control Panel ➪ Administrative Tools ➪ Internet Services Manager. If you don’t find this menu item, IIS isn’t installed. If IIS is already running, you must turn it off before installing Apache or install Apache on a different port.

To install Apache after you are sure that IIS isn’t running, follow these steps:

  1. Double-click the file you downloaded.
    The file is named apache_, followed by the version number and win32-x86-no_ssl.msi. For instance, httpd-2.2.22-win32- x86-no_ssl.msi. Note: You might need to right-click the file and choose Run as Administrator. The Apache Installation Wizard begins, and a welcome screen appears.
  2. Click Next.
    The license agreement is displayed.
  3. Select I Accept the Terms in the License Agreement and then click Next.
    If you don’t accept the terms, you can’t install the software. A screen of information about Apache is displayed.
  4. Click Next.
    A screen is displayed asking for information.
  5. Submit the Requested Information and the click Next.
    • Domain Name: Type your domain name, such as etechnologytips.com. If you’re installing Apache for testing and plan to access it only from the machine where it’s installed, you can enter localhost.
    • Server Name: Type the name of the server where you’re installing Apache, such as www.etechnologytips.com or s1.etechnologytips.com. If you are installing Apache for testing and plan to access it only from the machine where it is installed, you can enter localhost.
    • E-Mail Address: Type the e-mail address where you want to receive e-mail messages about the web server, such as webserver@ etechnologytips.com.
    • Run Mode: Select whether you want Apache to run as a service (starting automatically when the computer boots up) or whether you want to start Apache manually when you want to use it. In most cases, you want to run Apache as a service. The Installation Type screen is displayed.
  6. Select an installation type and then click Next.
    Generally, you should select Complete. Only advanced users who understand Apache well should select Custom. If you select Custom, the screens will be somewhat different than the screens described in the following text. A screen showing where Apache will be installed is displayed.
  7. Select the directory where you want Apache installed and then click Next.
    You see the default installation directory for Apache, usually C:\Program Files\Apache Group. If this is okay, click Next. If you want Apache installed in a different directory, click Change and select a different directory, click OK, and click Next. The screen that appears says the wizard is ready to install Apache.
  8. Click Install.
    If you need to, you can go back and change any of the information you entered before proceeding with the installation. A screen displays the progress. When the installation is complete, a screen appears, saying that the wizard has successfully completed the installation.
  9. Click Finish to exit the Installation Wizard.
    Apache is installed on your computer based on your operating system. If you install it on later versions of Microsoft Windows, it is installed by default as a service that automatically starts when your desktop computer starts. If you install it on an older version of Windows, such as Windows 95/98/Me, then you need to start it manually or set it up so that it starts immediately when your computer boots.

Installing Apache on a Macintosh

Apache is installed on all recent versions of Mac OS X, but it might not be started. To start Apache, choose Apple Menu ➪ System Preferences ➪ Sharing. On the Service panel, find the section for web sharing. Click the check box to turn web sharing on, which starts the Apache web server. If you need to install Apache yourself for some reason, you can install Apache from source code, as described below.

Installing Apache from source code on Mac and Linux

You can install Apache on Linux, Unix, and Mac from source code. You download the source code and compile it. To install Apache from source code, follow these steps:

  1. Change to the directory where you downloaded the file.
    The downloaded file is named httpd-, followed by the version name and tar.gz. This file is called a tarball because it contains many files compressed by a program called tar.
  2. Unpack the tarball by using a command similar to the following:
    For Linux: gunzip -c httpd-2.2.22.tar.gz | tar -xf –
    For Mac: gnutar -xzf httpd-2.2.22.tar.gz
    After unpacking the tarball, you see a directory called httpd_2.2.22. This directory contains several subdirectories and many files. Note that the version number will be different by the time you read this.
  3. Use a cd command to change to the new directory created when you unpacked the tarball (for example, cd httpd_2.2.22).
  4. Type the configure command.
    The configure command consists of ./configure followed by all the necessary options. To use Apache with PHP as a module, use the appropriate configure command as follows:
    For Linux or Unix
    use ./configure –enable-so
    For Mac
    use ./configure –enable-module=most
    You can use other options if you want. One of the most important installation options you might want to use is prefix, which sets a different location where you want Apache to be installed. By default, Apache is installed at /usr/local/apache or usr/local/apache2. You can change the installation location with the following line:
    ./configure –prefix=/software/apache
    You can see a list of all available options by typing the following line:
    ./configure –help
    This script probably take a while to finish running. As it runs, it displays output. When the script is finished, the system prompt is displayed. If configure encounters a problem, it displays a descriptive error message.
  5. Type make to build the Apache server. The make command might take a couple of minutes to run. It displays messages while it is operating, with occasional pauses for a process to finish running.
  6. Type the following command to install Apache:
    For Linux or Unix, type make install
    For Mac, type sudo make install
  7. Launch the Apache web server.
  8. Type the URL for your website (for example, www.example.com or localhost) into a browser to test Apache.

If all goes well, you see a web page telling you that Apache is working.

Starting and Stopping Apache

You might need to start Apache when you install it. Or, you might not. It might already be started. However, each time you change your Apache or PHP configuration settings, you need to restart Apache before the new settings go into effect.

Starting and stopping Apache on Windows

When you install Apache on Windows, it’s usually automatically installed as a service and started. It’s ready to use. However, on Windows 95, 98, and Me, you have to start Apache manually, using the menu. When you install Apache, it creates menu items for stopping and starting it. To find this menu, choose Start ➪ Programs ➪ Apache HTTP Server ➪ Control Apache Server. The menu has the following items:

  • Start: This option starts Apache when it isn’t running. If you click this item when Apache is running, you see an error message saying that Apache has already been started.
  • Stop: Stops Apache when it’s running. If you click this item when Apache isn’t operating, you see an error message saying that Apache isn’t running.
  • Restart: This restarts Apache when it’s running. If you make changes to Apache’s configuration, you need to reboot Apache before the changes become working.

How to Start Apache on Linux, Unix, and Mac

A script named apachectl is available to manage the web server. By default, the script is stored in a subdirectory called bin in the directory where Apache is installed. Some Linux distributions may put it in another directory. The script requires a keyword. The most common keywords are start, stop, and restart. The general syntax is as follows: path/apachectl keyword The apachectl script starts the Apache server, which then runs in the background, listening for HTTP requests.

By default, the compiled Apache server is named httpd and is saved in the same directory as the apachectl script, unless you changed the name or location during installation. The apachectl script serves as an interface to the compiled server, called httpd. You can run the httpd server immediately, but it’s better to use apachectl as an user interface. The apachect1 script manages and checks data that httpd commands require. Use the apachectl script to start Apache with the following command:

  • For Linux: /usr/local/apache/bin/apachectl start
  • For Mac: sudo /usr/local/apache/bin/apachectl start

The apachectl script contains a line that runs httpd. By default, apachectl searches for httpd in the default location — /usr/local/ apache/bin or /usr/local/apache2/bin. If you installed Apache in a nonstandard location, you might need to edit apachectl to use the correct path. Open apachectl and then search for the following line: HTTPD=’/usr/local/apache2/bin/httpd’ Change the path to the location where you installed httpd. For example, the new line might be this: HTTPD=’/usr/mystuff/bin/httpd’ After you start Apache, you can check whether Apache is running by looking at the processes on your computer. Type the following command to display a list of the processes that are running: ps –A If Apache is running, the list of processes includes some httpd processes.

How to Restart Apache on Linux, Unix, and Mac

Whenever you change the configuration file, the new directives take effect the next time Apache starts. If Apache is shut down when you make the modifications, you can start Apache as explained earlier. However, if Apache is running, you can’t use start to restart it. Using start results in an error message saying that Apache is already running. You can use the following command to restart Apache when it’s currently running:

✦ For Linux: /usr/local/apache2/bin/apachectl restart

✦ For Mac: sudo /usr/local/apache2/bin/apachectl restart

Although the restart command usually works, sometimes it doesn’t. If you restart Apache and the new settings don’t seem to be in effect, try stopping Apache and starting it again. Occasionally this solves the issue.

How to Stop Apache on Linux, Unix, and Mac

To stop Apache, use the following command:

/usr/local/apache/bin/apachectl stop
sudo /usr/local/apache/bin/apachectl stop

You can check to see whether Apache is stopped by checking the processes operating on your computer by using the following command:

ps –A

The output from ps should not consist of any httpd processes.

For configuring .htaccess settings you can see Apache Rewrite Rules Guide