Apache (Retired)

From 24PinTech Wiki
Jump to navigation Jump to search

Introduction and Summary

Apache is one of the most common, versatile, and supported web servers of all time due to its easy installation and high functionality. This article is meant to guide you through the process of installing and configuring a fresh new install of Apache and the libraries it works well with (PHP and MySQL) on a Windows environment. This specific type of install is called a WAMP stack (Windows, Apache, MySQL, and PHP.)

Selecting the Proper Environment

Another great thing about Apache is that it runs well on most (if not all) operating systems and provides the same functionality. Before you get started, you want to select which OS you are going to run the web server on. You as the server administrator (or poor soul assigned this agonizing task) should note the features you need and what OS they work best on. If you need a utility that runs better on a Linux server distro than on Windows Server, you might want to select a Linux distro that works well for you (vice versa Windows server.)

If you only need an Apache server running, the general consensus is that it will run the same regardless of OS on most modern hardware, but some disagree. (serverfault discussion about LAMP vs WAMP stacks)

Dependencies and Prerequisites

— DO NOT CONTINUE UNTIL YOU HAVE COMPLETED EVERYTHING IN THIS SECTION —

Before you begin, you're obviously going to need to download Apache. You can find this here, or at the bottom of this section. Once you have it downloaded, unzip the folder called Apache24 and paste it into the C:\ drive (or whatever drive your primary partition is on.) Repeat the same process with PHP, except create a folder on the C:\ drive called PHP and extract the .zip file's contents into there.

For MySQL, download the

All of the download links can be found here:

Apache Installation

Open a new command prompt window as administrator and navigate to the bin folder in the Apache directory you unzipped by running

cd C:/Apache24/bin

and then run the command:

httpd -k install

You should now see "The 'Apache2.4' service is successfully installed." on the 2nd line of the output. After this, start Apache by running the command in the same directory:

httpd -k start

Note: For future reference, in order to manage the Apache service, you can either run the httpd -k command with the options start, restart, or stop. Alternatively, you can manage the service by opening services.msc, finding the Apache2.4 service, and then right clicking on it to manage it there.

Go to your browser and visit http://localhost/ and you should see a page load. You've successfully installed Apache! 👏

httpd.conf

httpd.conf is the main configuration file Apache uses and references it whenever any HTTP request is sent to the website, which is why it's so important you have everything configured properly. First and foremost, if you want your website to be accessible via LAN you're going to need to access this file and tell it to listen on the server's IP. To start, open a new command prompt window and run ipconfig and find where it says "IPv4 Address . . . ." in the output (it'll say "IPv6 Address" if you're a communist) and copy the IP.

Ipconfig.jpg

Open your favorite text editor as an administrator (it matters that you run as administrator) and then open the file C:/Apache24/bin/httpd.conf, and then add the following code at the bottom of the file (location doesn't matter, bottom is just the easiest):

Listen [IP]:80

Just replace [IP] with the IP you copied and save the file, and then restart Apache (httpd -k restart or services.msc in case you forgot.)

VCURNTIME140.dll


In the event that you get the following error, follow the steps below:

"The program can't start because VCRUNTIME140.dll is missing from your computer. Try reinstalling the program to fix this issue."

Go here and scroll below the "DLL-files.com Client Demo" button where it says "VCRUNTIME140.DLL, 7 AVAILABLE VERSIONS" and download both the 64-bit and 32-bit file if you have a 64-bit OS, and only the 32-bit file if you have a 32-bit OS.

This will get a little confusing, but this is where to put the file(s):

64-bit OS

64-bit FileC:/Windows/System32

32-bit FileC:/Windows/SysWOW64

32-bit OS

32-bit FileC:/Windows/System32

PHP Installation

After following the instructions for installing PHP as instructed in the Dependencies and Prerequisites section, open a text editor as administrator and open the file C:/Apache24/bin/httpd.conf. Next, at the bottom, add the following lines:

LoadModule php7_module "C:/PHP/php7apache2_4"
AddHandler application/x-httpd-php .php
PHPIniDir C:/PHP

Save the configuration file and restart Apache. Next, find the following code in httpd.conf:

<IfModule dir_module>
     DirectoryIndex index.html
</IfModule>

Once you've found it, replace it with:

<IfModule dir_module>
     DirectoryIndex index.php index.html
</IfModule>

Save your file and restart Apache (httpd -k restart or services.msc in case you forgot.) Once you've restarted that, navigate to C:/Apache24/htdocs, create a new file called index.php, and edit it to have only the following code (reminder to edit it with a text editor that has been ran as administrator):

<?php
     phpinfo();
?>

Save the file, and then navigate back to http://localhost/. A page that contains information about your PHP install should display. You've successfully installed (and enabled) PHP! 👏

Installing MySQL

Installing MySQL is easy when you use the provided installer, which can be found here. Make sure you get an installer that ends with the .msi file extension.

Mysql-installer-msi.png

After you click the download button, it'll tell you that you have to register for a new account, but there's a button below it that lets you skip that entirely and go straight to your download.

Skip-registration-mysql.png

Once you download it, run the installer, and go through it. The default settings it has should be sufficient, but if you're unsure if you need something research it. When you get to the part of the installation that tells you to enter credentials for MySQL, be sure to document the credentials that you enter so you don't lose them.

phpMyAdmin

As the Wikipedia page puts it:

phpMyAdmin is a free and open source administration tool for MySQL and MariaDB. As a portable web application written primarily in PHP, it has become one of the most popular MySQL administration tools, especially for web hosting services.

Installng it is pretty straightforward. Download it from the link provided, and unzip the contents into a folder called "phpMyAdmin" (or whatever you'd like) to the main document path in Apache (by default it's C:\Apache24\htdocs\) and proceed.

Configuring PHP

PHP will not work properly if it is not configured, which is why it's crucial that you do. To start, navigate to C:/PHP and rename php.ini-production to php.ini. Open that file in a text editor and search for the line that says ;extension=php_mbstring.dll, and then remove the semicolon before it. Repeat the same process on the line that reads ;extension=php_mysqli.dll.

Verifying Functionality

Testing functionality is as easy as opening a web browser, typing in the IP address of your Apache server, and pressing enter. If it loads, it works! If it doesn't, try researching and debugging some things to see where you went wrong. A little bit of research goes a long way.

Try visiting /phpmyadmin and checking things out. The login credentials are the same as what you used to install MySQL, but if they don't work verify that you're properly typing them and then reinstall MySQL.

If everything is working properly, you have correctly configured and installed your WAMP stack!

Current Configuration

Aside from the default httpd.conf configurations and other uncommented changes, this is everything that I have manually added to the configuration file for Apache. If you make any changes, remember to restart the Apache service either by running httpd -k restart or restarting the service in services.msc. Until we get HTTPS, this configuration should remain the same.

ServerRoot "c:/Apache24"
Listen 10.21.25.11:80

DocumentRoot "c:/Apache24/htdocs"
<Directory "c:/Apache24/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

LoadFile "C:/PHP/php7ts.dll"
LoadModule php7_module "C:/PHP/php7apache2_4.dll"
AddHandler application/x-httpd-php .php
PHPIniDir C:/PHP

RewriteCond %{HTTP_HOST} ^www\.24pin\.tech$
RewriteRule ^(.*)$ http://24pin.tech/$1 [R=301,L]

<VirtualHost *:80>
	ServerName 24pin.tech
	DocumentRoot "C:\Apache24\htdocs"
</VirtualHost>

<VirtualHost *:80>
	ServerName wiki.24pin.tech
	DocumentRoot "C:\Apache24\htdocs\wiki"
</VirtualHost>

<VirtualHost *:80>
	ServerName forum.24pin.tech
	DocumentRoot "C:\Apache24\htdocs\forum"
</VirtualHost>

# RedirectMatch "/wiki/" "http://wiki.24pin.tech/$1"
RedirectMatch "/forum/" "http://forum.24pin.tech/$1"

<Directory "C:/Apache24/htdocs/wiki">
    Allow from 127.0.0.1
    Satisfy Any
</Directory>