Installing the PHP environment - spaceshiptrooper [Style]

Windows Part 6


Extra (needed if you want to have Apache up and running without having to manually start it up)


1.) I only placed these steps here because these steps simply doesn’t belong in the Installing PHP section and we cannot add these steps into the Installing Apache section as we have just finished configuring our php.ini file and our PHP installation. The neat thing about Linux is that it starts mostly every service up without needing to manually start up those service. In Windows however, if you want Apache to start up when you turn on your computer, you’ll need to create a short cut and add that into your Startup directory. So the first thing you want to do is again, open up File Explorer and browse to C:/dev/progs/Apache/bin or C:/ Drive > dev > progs > Apache > bin.

2.) Once you are there, right-click on ApacheMonitor and from the context menu, click on Create shortcut. This will create a shortcut to the ApacheMonitor executable file. Basically, when your computer starts up and all of the startup programs are started up, this shortcut will point to the ApacheMonitor and then Windows will start up the ApacheMonitor executable file.



3.) What I’d like to do is rename ApacheMonitor - Shortcut to just ApacheMonitor, but you can leave it as is if you’d like. It’s just a matter of preference.


4.) Once you have that all sorted out, click on the Start button at the bottom left corner of your Windows 10. Once the Start menu expands and you see the small left sidebar again, scroll way down to Windows System. Then click and open Run.

5.) Once Run is opened, where it says Open:, type in the text field shell:startup. This should open the Startup directory.


6.) The Startup directory should be empty and have nothing in there. If it there are things in there, don’t worry about it. Now, what you should do is line both the Apache directory and the Startup directory next to one another. Drag and drop the ApacheMonitor shortcut. If you renamed the ApacheMonitor shortcut to just ApacheMonitor, you can tell the difference between the actual ApacheMonitor and ApacheMonitor shortcut. The shortcut has a little blue icon that’s pointing up and it’s within a little white box. That icon represents shortcuts in Windows. You can interpret this as “A reference to the actual program”. When you drag and drop the shortcut, it should NOT create a new copy. It should have moved the shortcut to the Startup directory leaving no ApacheMonitor shortcut in the Apache directory.



7.) Once the ApacheMonitor shortcut is inside the Shortcut directory, click and open the ApacheMonitor shortcut. This will prompt you a security warning. Simply, it’s just the default Windows warning dialog box. In the left bottom corner of the dialog box, it says Always ask before opening this file. Unless you are sure and are willing to allow the ApacheMonitor to be opened without permission, I suggest not unchecking the checkbox. However, if you don’t uncheck the checkbox, the Apache service will not start up right away if there is an error in your Apache configuration for any reason. This dialog box may popup and ask you again or it may not even. So the Apache service may not even run OR start up without the ApacheMonitor. I suggest unchecking the checkbox to ensure that the Apache service does indeed start up when Windows gets booted. But it’s up to you if you want to open it or not. These files are safe and the Apache Lounge website is linked to by the official PHP team. So I would highly doubt that the official PHP team would link to you to any malicious website that they don’t deem unsafe for their users. Once you are done deciding whether you want to allow this or not, click on Run. The warning dialog box should disappear and the ApacheMonitor icon should appear in your icon tray at the bottom of your task menu.


8.) During this point, we should check to make sure that the Apache service is working and have no errors. You can check by clicking on the ApacheMonitor icon in your icon tray. The first time you hit Run from the above step, ApacheMonitor should actually open up. But if you’ve opened it before, it’ll minimize and go into the icon tray just like the picture below. So right-click on the ApacheMonitor icon if it’s already minimized. And from the context menu, click on Open Apache Monitor.


9.) By default, the Apache service should not be running. So you’ll have to start it up. Click on the Start button at the right sidebar. You’ll be prompt to type in or allow the Apache service to run. So allow it. If all works well, the little red circle at the left of Apache2.4 should turn into a green sun light. If it still remains a red circle or it prompts you a message saying that Apache cannot run or some kind of error message for Apache, you might want to correct that before running Apache. To do this, just open up a Command Prompt with administrator permissions and change the directory to C:/dev/progs/Apache/bin and then type in httpd. httpd will always tell you what’s wrong with your Apache configuration so use it well. It’s your friend.



10.) If you are NOT using Sublime Text, you can skip this step unless your Text Editor provides the same option. For Sublime Text users, I usually like to have my development projects ready to be worked on. I recommend placing your development directory on the left sidebar of Sublime Text. This allows you to navigate and pull up files at ease without having to go to File > Open File > ...... It takes too much time to open your project files so I recommend doing this. To do this, just click on File in the top menu. Then from the menu, click on Open Folder..., browse back to C:/dev and select the www directory and hit the Select Folder button. A new Sublime Text window should appear with your development projects or subdomain directories on the left sidebar. You can minimize both Sublime Text windows and drag and drag the files or tabs from the first Sublime Text window onto the second Sublime Text window. You might want to drop those files by holding onto the tabs and dropping them in the tabs view. Dragging and dropping just the filename might not work. Another way you can also do is just drag and drop the www directory onto the left sidebar. This will do basically the same exact thing except you don’t have to drag and drop the tabs since the www directory will be in the current Sublime Text window.


11.) Once we are all set and have a clean development environment to work with, you can now create test files to make sure that PHP works. To do so, we’ll create a new file. So click on File in the menu bar at the top and from the menu, click on New File. The new file will always be called Untitled by default unless you are using a different Text Editor such as Dreamweaver. Then yours might be Untitled.html. In the new file (Untitled), type in

<?php
phpinfo();

Save the file to C:/dev/www/default and name it as index.php. We’re just basically checking to see if PHP works and if it does work, it’ll display our PHP information.




12.) Open up another new file using the same menu option and then type in

<?php
print('Sample');

This time, save the file to C:/dev/www/sample and name it as index.php. This index.php is meant to make sure that our subdomains work correctly and that PHP also works correctly.



13.) For this step, I’m not really doing much. I am just expanding the directories to demonstrate that there are 2 different index.php files and they are both saved in different directories.

14.) Open up your favorite web browser and create a new tab and type into the address bar localhost.com. It should display a similar page to the first picture below.

15.) Create another new tab and type into the address bar sample.localhost.com. It should display something similar to this page. There should be nothing really except for a text that outputs Sample. If you are getting a 404 Error page on this subdomain, you probably forgot to change the lines that read

<Directory />
    AllowOverride none
    Require all denied
</Directory>

They need to be changed to

<Directory />
    AllowOverride All
    Require all granted
</Directory>

So that you can access directories within your www directory. You’ll also want to restart your Apache service. You can restart the Apache service by clicking on the ApacheMonitor icon in the icon tray and hovering over Apache2.4 and then from the secondary menu, click on Restart. The Apache service should restart and you can then refresh that page you are on.

2 Likes