How to Build Local Server 1 -Install and Setup Apache-
GOAL
To setup Apache and build local web server with it. In this article, you can only display default page. If you would like to create new directory as a local serer, check “How to Build Local Server 2” after Apache setup.
Environment
Windows 10
Apache 2.4.43
What is Apache?
Apache is open source application for implementation of an HTTP (Web) server. You can build local web server and global web server regardless of whether it is commercial use or not.
Why is the local web server necessary?
Local web server is used as a virtual environment for development and test before publishing to the live server. You can make local file a test server that only local users can access.
Installation and setup of Apache
Installation
1. Open Download page “Apache HTTP Server project website“.
2. Click Files for Microsoft Windows if you use windows.
* Click “Binaries” if you don’t use windows.
* I don’t know why but I couldn’t click “Source: httpd-2.4.43.tar.bz2”.
3. Select one sit from the list. In my case, I clicked “Apache Lounge”.
4. Install Apache 2.4.43 Win64 or Apache 2.4.43 Win32
Setup
1. Unzip httpd-2.4.43-win64-VS16.zip and open it. You can see the directory named “Apache**”.
2. Put the directory “Apache24” into the directory you want. I put it on document directory.
3. Open Apache24>conf>httpd.conf with your favorite text editor.
Change definition of SRVROOT into the path to “Apache24”
#default #Define SRVROOT "c:/Apache24" Define SRVROOT "C:\Users\USER_NAME\Documents\Apache24\conf" ServerRoot "${SRVROOT}"
Change ServerName
# If your host doesn't have a registered DNS name, enter its IP address here. # #ServerName www.example.com:80 ServerName localhost:80
Start Apache
Use command as below or just double-click httpd.exe.
Open command prompt and change directory into the Apache24¥bin
> cd C:\Users\USER_NAME\Documents\Apache24\bin > httpd AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using ******. Set the 'ServerName' directive globally to suppress this message
If you got an warning about fire wall, allow the access in private network.
Access localhost
How to run httpd in the background?
You should register httpd as a windows service. Open command prompt as administrator and install httpd.
> cd C:\Users\USER_NAME\Documents\Apache24\bin > httpd -k install Installing the 'Apache2.4' service The 'Apache2.4' service is successfully installed. Testing httpd.conf....
Then you can start httpd by command as below.
httpd -k start
You can stop/shutdown by commands as below. It works only when command prompt is run by an user as administrator.
> httpd -k stop
> httpd -k shutdown
Change contents
Put index.html and resources into Apache24\htdocs. I put index.html below.
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>My page</title> <meta name="description" content="The HTML5 Herald"> <!--[if lt IE 9]> <script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.js"></script> <![endif]--> </head> <body> <h1>My Page</h1> <p>this is test page!</p> </body> </html>
Next Step
Change root directory from Apache24\htdocs into your local directory. Check How to Build Local Server 2 -Change Root Directory- for details.