Windows Part 3
Installing Apache
1.) Once we have our desired domain names, we’ll have to browse back to the Downloads
directory. You can navigate to it either by clicking on Downloads
in the left sidebar of the File Explorer
or you can open up your favorite web browser and clicking on the Downloads
history dropdown list and then right-clicking on a downloaded file and clicking on Open Containing Folder
to open up the Downloads
directory. Next, navigate into the Apache
directory. It should be called httpd-2.4.25-win32-VC14
. If not, you might be using the x64 bit one. So browse into httpd-2.4.25-win64-VC14
. Once inside the Apache
directory, you’ll see that there’s a directory called Apache24
. Name that to just Apache
as it’s going to be our Apache
directory and it’ll be much easier to remember Apache
and not Apache24
.
2.) Cut and paste the Apache
directory that you just renamed to the progs
directory within our C:/
drive. The location is C:/dev/progs
. You can copy&paste instead if you’d like.
3.) This step should be done in the Installing PHP
section, but to save time, we’ll just do this all-in-one go. So browse back to the Downloads
directory by clicking on Downloads
at the left sidebar. This time, we’re going to rename the PHP
directory from the Downloads
directory instead of browsing into the PHP
directory. So rename php-7.1.0-Win32-VC14-x86
to just PHP
. If that isn’t yours, it could be php-7.1.0-Win32-VC14-x64
.
4.) Again, cut and paste the PHP
directory you just renamed to the progs
directory within our C:/
drive. The location is still C:/dev/progs
.
5.) You should now have both the Apache
directory and the PHP
directory within the progs
directory as shown below.
6.) Now open up your favorite Text Editor
again if it isn’t opened already. Click on File
and then click on Open File...
and browse to your Apache
directory within the progs
directory which should be within the dev
directory inside the root of your C:/
drive. Once inside the Apache
directory, browse to the conf
directory and open up the httpd.conf
file. You can also browse to the Apache
directory and then the conf
directory within your File Explorer
and drag&drop the httpd.conf
file into your Text Editor
. This will simply open the httpd.conf
file without needing to browse so much if you were already in the progs
directory from Step #5.).
7.) If you are using Sublime Text
like I am, you can hit CTRL+H
to open up the Replace All
command. We’re going to replace all lines that have c:/Apache24
since this isn’t the correct location that our Apache
is stored in. The correct location is C:/dev/progs/Apache
. You can also replace it with C:\dev\progs\Apache
like I have there, but it doesn’t matter. For other Text Editors
, you might want to figure out which controls are for opening up the Replace All
command or you could navigate to it using the menu bar at the top of your Text Editor
. If you cannot find the Replace All
command, you might want to contact the author of that Text Editor
or a forum that is active and ask for help finding the commands for that Text Editor
. Or you can simply change Text Editors
if you’d like.
8.) Browse down to where the lines read #LoadModule rewrite_module modules/mod_rewrite.so
and uncomment it. You might want to uncomment this module if you want to use Apache
’s Rewrite
commands in your projects.
9.) On line 180 where there’s a double line break, type in LoadModule php7_module "C:\dev\progs\PHP\php7apache2_4.dll"
. In the picture below, I made a mistake which will come to bite me in the butt later on in the tutorial. And I fixed it after I debugged the error which pointed to this exact line. Mistakes will be made. Don’t copy the one in the picture since it’s not the correct one. Use the one above.
10.) After that, create a new line after the PHP 7
module and type in AddHandler application/x-httpd-php .php
. This is the PHP
handler. We need this in order for Apache
to execute PHP
as PHP
and not output it as HTML
text. If you don’t do this, PHP
will not be processed as PHP
and you will not get PHP
to properly execute.
11.) Browse down to line 231 where it says
<Directory />
AllowOverride none
Require all denied
</Directory>
And replace AllowOverride none
to AllowOverride All
. On that same code, replace Require all denied
to Require all granted
. We’re basically allowing access to our Directory
directories. Basically, if you don’t replace these lines, when you browse to sample.localhost.com
, you’ll get thrown a 404 Error
page. So to avoid this, you’ll want to replace these lines to allow you to access your directories.
12.) Now, browse down a little bit to where you can see DocumentRoot "C:\dev\progs\Apache/htdocs"
. Replace this with our default directory. This default directory will be pointed to our main domain which is localhost.com
. So the default directory is C:\dev\www\default
. We will also do this with the <Directory "...">
line underneath DocumentRoot
as well.
13.) Scroll down some more and where it reads AllowOverride None
, we want to replace that with AllowOverride All
. Simply because it may also cause our default directory to output Error 404
when we should have everything set up.
14.) Again, scroll down some more and where it reads DirectoryIndex index.html
, you’ll want to put in DirectoryIndex index.php index.html
. This simply tells Apache
to look for the index file index.php
before it looks for index.html
. Basically, if you are running a PHP
project, you might want to do this because if you have both index.html
and index.php
inside the same folder, index.html
will get used and parsed instead of index.php
. So it’s best if you put index.php
before index.html
.
15.) Now, scroll down to line 506. It should read #Include conf/extra/httpd-vhosts.conf
. Uncomment is because this is our virtual host that we have to modify in order for us to run our subdomains and main domains.
16.) Scroll to the way bottom of the file and create a new line break and add in PHPIniDir "C:\dev\progs\PHP"
. Basically, with this line we just add in the PHP
ini directory. We basically need to have this line some where in the httpd.conf
file because without this line, Apache
will not load our extensions which isn’t what we want. I’ve tested the httpd.conf
file without this line and it throws a Class not found
error for mysqli_*
if you want to use mysqli_*
. I assume it also throws some more errors to other different functions of PHP
. So having a httpd.conf
file without this line will most likely not work at all.
17.) We are finally finished with the httpd.conf
file. You can either close it or leave it up if you’d like. If you followed the steps and didn’t make the same mistake as I have in Step #9, you don’t have to keep httpd.conf
opened. If you did exactly what the picture shows, you might want to keep httpd.conf
opened until you can fix or debug any errors that happens.
18.) This time, open up the httpd-vhosts.conf
file. To open it, you can either use the File Explorer
or browse to it using your favorite Text Editor
. I believe using the File Explorer
and dragging & dropping the file to the Text Editor
would be a much simpler idea because if you are still working in the same directory, it’s a lot easier to use the current location in the File Explorer
instead of re-browsing back and forth from the C:/ Drive
using the Text Editor
’s File - Open
menu options. So browse to C:\dev\progs\Apache\conf\extra
or C:\ Drive
> dev
> progs
> Apache
> conf
> extra
and open up the httpd-vhosts.conf
file.
19.) Once you have the httpd-vhosts.conf
file open, it should by default have the following data in the file (shown in the picture below). All we’re going to do is use the first set starting from <Directory>
to the end of the first </Directory>
. We’re going to be putting our own into that set and then we’re going to be using that same code and replace it respectively for all of our subdomains and main domain.
20.) Replace ServerAdmin webmaster@dummy-host.example.com
with your own local email. Don’t worry if the email doesn’t exist, we’re not sending legitimate email messages to that email. This is simply a placeholder for when we get 500 Errors
. We’re also NOT creating a local email server so don’t ASSUME that is what we are doing. That is NOT what we are doing. We’re replacing the current ServerAdmin
email to whatever junk email we want. Simply put, since we are the only developers currently on our local machine, the ServerAdmin
email serves NO purpose to us. If we make a mistake configuring our Apache
files, that’s all on us. The ServerAdmin
email’s purpose on a live server is to allow users who don’t own nor have access to the Apache
configurations to contact that administrator email so that they can go and fix the Apache
files. Since we are the only developers on this local machine and have full access to the Apache
files, there is NO point in putting an actual working email in this section.
21.) Replace DocumentRoot "c:/Apache24/docs/dummy-host.example.com"
with your main domain directory. The new replacement should be DocumentRoot "C:\dev\www\default"
.
22.) Replace ServerName dummy-host.example.com
with ServerName localhost.com
. You don’t necessarily have to put in www.
in front of localhost.com
, but if you want to, go for it. I dislike having www.
in front of my domain names as it’s a generic placeholder and serves really no purpose other than having been taught to type that into the address bar when the World Wide Web first came out of its roots. There’s really no specialty in having www.
or not having www.
in front of the domain name. I guess it’s just a matter of preference. I don’t believe it really affects search engine optimization either so there’s really no point in my eyes to put www.
in front of the domain name. But if you do want to however, you’ll have to add that into the hosts
file and also add that into the httpd-vhosts.conf
file and also httpd-ssl.conf
file if you are using SSL
which in this tutorial, we’re not going to do. Basically, if you want to have both www.
and non-www
, you’ll have to add both entries into the hosts
file and have 2 entries of the same domain name and location in both httpd-vhosts.conf
and in httpd-ssl.conf
. I’d say just stick to using the non-www
as it’s much easier to work with and you don’t have to add in so many entries. But if you want to add www.
go for it. The same can also be said about ServerAlias
. This really is just an alias for the domain name. So you can apply this step to the line ServerAlias
.
23.) The ErrorLog
and CustomLog
don’t really have to be accessed all the time as these files relate specifically only to Apache
. These files will show every error that happens when using an Apache
file. If you configured a .htaccess
file incorrectly, you can view these two error logs to debug where the problem persists. These two logs don’t really relate much to PHP
and you’ll rarely use these two files unless you are messing with Apache
. Other than that, all errors in PHP
will be stored in our logs
directory we created a while back. So you can simply leave the directory location and rename the dummy-host.example.com
part to your respective domain.