How to Configure and Install Apache Http Server

Source: Internet
Author: User
Keywords install apache http server how to install apache http server apache http server
Apache http server installation and configuration
Note: After 2.2, the Apache official website no longer provides windows msi or exe installation version. Now Apache http Server has two branches, 2.2 and 2.4


Alibaba Cloud Simple Application Server:  Anti COVID-19 SME Enablement Program
$300 coupon package for all new SMEs and a $500 coupon for paying customers.


download
  1. Enter Apache official website, http://httpd.apache.org/download.cgi
  2. Select the version, click Files for Microsoft Windows, (windows installation version).
  3. Choose to download the mirror under Downloading Apache for Windows (any one of the first three, Apache Lounge is recommended)
  4. Corresponding to different systems, different VS versions, choose to download.
  5. After the download is complete, unzip the "Apache24" directory to the drive letter to be installed. (The path cannot have Chinese characters or spaces)
Main file structure
Create service: bin\httpd.exe
Management panel: bin\ApacheMonitor.exe
The main configuration file: conf\httpd.conf
Website root directory: \htdocs

installation
Switch to the bin directory in the Apache decompression path
$ cd "Extract path"/bin
To install the Apache service, the -n parameter is to specify the service name, and the exe can be ignored.
$ httpd.exe -k install -n "Apache"
If you want to uninstall the Apache service, you can execute the following command
$httpd.exe -k uninstall -n "Apache"
An error will be reported after the installation command is executed. The reason is that the default configuration file has a problem. You need to adjust the configuration file conf/httpd.conf first to start the service normally.

According to the error prompt, it is found that the default configuration path is C:/Apache24, so we need to modify the default configuration path to our installation path, and then re-execute httpd.exe -t
Test the configuration file and prompt Syntax OK, which means that the service is installed successfully.

If there is a warning about ServerName, you can ignore it temporarily

Next, run the following command to restart the service.
// Note to start the window as an administrator
# Start Apache service
$ httpd.exe -k start -n "Apache"
# Restart Apache service
$ httpd.exe -k restart -n "Apache"
# Stop Apache service
$ httpd.exe -k stop -n "Apache"
Go back to the browser, type in the address bar: http://locallhost/, press Enter to visit, you should be able to see It works!

Port, website root directory configuration

port
++httpd.conf file under Apache\conf directory++
Listen 80 (80 is the port number)

Website root directory

++httpd.conf file under Apache\conf directory++
# Prohibit all root directory access
<Directory />
    AllowOverride none
    Require all denied
</Directory>
The double quotes here are changed to the root directory path of the website to be set (D:/www)
DocumentRoot "D:/www"
<Directory "D:/www">
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>
Default document
++httpd.conf file under Apache\conf directory++

This tag is to set the default access page document
<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>
Directory browsing
++httpd.conf file under Apache\conf directory++

Options Indexes FollowSymLinks in the Directory tab, remove Indexes to prohibit directory browsing
<Directory "D:/www">
    Options FollowSymLinks
</Directory>
Virtual host
++httpd.conf file under Apache\conf directory++
#Virtual hosts
#Include conf/extra/httpd-vhosts.conf
Uncomment the Include conf/extra/httpd-vhosts.conf under the <IfModule proxy_html_module> tag
Open the conf/extra/httpd-vhosts.conf file
*:80 monitor port 80 of any IP bound to the current computer

Since multiple virtual hosts work at the same time, each virtual host needs to be configured with ServerName

ServerName is configured in the httpd.conf file under the Apache\conf directory

At the same time, point 127.0.0.1 to ServerName in the hosts file C:\Windows\System32\drivers\etc\hosts
<VirtualHost *:80>
    # Webmaster Email
    ServerAdmin webmaster@dummy-host2.example.com
    # The root directory of a virtual host
    DocumentRoot "D:/www (directory path)"
    # The domain name of a virtual host
    ServerName baixiu.abc (domain name address)
    # Domain alias of a virtual host
    ServerAlias www.baixiu.abc (domain name alias address)
    # Error log file of a virtual host
    ErrorLog "logs/net war domain name-error.log"
    # Access log file of a virtual host
    CustomLog "logs/website domain-access.log" common
</VirtualHost>
Multiple virtual hosts need to be configured. In order to prevent the Forbidden situation, add the Directory label under DocumentRoot in the VirtualHost label.
<VirtualHost *:80>
    #ServerAdmin webmaster@dummy-host2.example.com
    DocumentRoot "D://www"
        <Directory "D:/www">
            Options Indexes FollowSymLinks
            AllowOverride None
            Require all granted
        </Directory>
    ServerName baixiu.top
    ErrorLog "logs/baixiu.top-error.log"
    CustomLog "logs/baixiu.top-access.log" common
</VirtualHost>
At the same time, point 127.0.0.1 to ServerName in the hosts file C:\Windows\System32\drivers\etc\hosts

==After the setting is complete, restart the Apache service! ! ! ==
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.