Wednesday, October 19, 2016

ASP.net: Let's make some web applications!


ASP.net - an open source web framework for building modern web applications! ASP.net is very easy to install, find out more information in the short tutorial below!!

Step 1. The Installation

To install ASP.NET navigate to Control Panel > Programs and Features > Turn Windows features on or off. Once you have done this a window similar to Figure 6.1 will be displayed. Expand "Internet Information Services" > "World Wide Web Services" > "Application Development Features" and check ASP.NET 4.5. Click OK to enable feature.
Figure 6.1 Installing IIS

Step 2. Testing if it was successful

To check if installation was successful click on the start menu and type IIS, hit enter and once Information Services opens up you will now see an ASP.NET section in the main view of the manager (Figure 6.2)!

Figure 6.2 Testing installation

IIS: Internet Information Services

IIS: a flexible, secure and manageable web server, it comes with Windows and must be enabled rather than installed.

Part 1. Enable IIS

In the start menu type Control Panel to open the panel, go to Programs>Programs and Features, the window is displayed in Figure 5.1, on the left hand side of the window click "Turn Windows features on or off"
Figure 5.1 Programs and Features section of Control Panel
After clicking on "Turn Windows features on or off" a window similar to Figure 5.2 should appear.
Figure 5.2 Windows Features pane as selected from the control panel
Scroll to Internet Information Services(IIS) and click the box, you will notice it is filled with a square rather than a check mark, this means not all files in the folder will be installed. When expanded we see FTP Server will not be installed, for the purpose of this tutorial that is fine. Ensure Web Management Tools and World Wide Web Services are marked off as in Figure 5.3 and then press "OK"

Figure 5.3 Check off IIS to enable feature
If it was successfully enabled it should now appear in your Programs & Features list as is seen in Figure 5.4.
Figure 5.4 IIS successfully enabled

Part 2. Create two websites using IIS

Step 1. Open the IIS Manager

Open the start menu type "iis" and press enter. This will open the Internet Information Services Manager, your screen should look similar to Figure 5.5. You'll notice a list of connections on the left hand side, expand Sites, you will likely only see Default Web Site, we will be creating helloWorld and Second IIS Website in this tutorial.
Figure 5.5  Opening IIS Manager

Step 2. Add a website

Right-click on "Sites" and click "Add a website". You should see a screen similar to Figure 5.6

The site name will be displayed in the IIS manager and so you can name it what you would like, you'll notice for binding I have assigned it to all ip addresses on port 80. Now we must select the physical path. When IIS was installed a folder named "inetpub" was put on the root of the C: drive. Navigate to C:\inetpub\wwwroot\ and create a folder called helloWorld. Returning to the IIS Manager Add Website window paste this path into the "Physical path" field or navigate to it with the button beside the field. Add the host name "helloworld.com". Click "OK" when you are finished.

Note: Because we have checked off "Start Website Immediately" we do not need to worry about starting the servers later.
Figure 5.6 Complete the following information to add a website

Repeat this step once more except creating a folder called secondIIS rather than helloWorld in  C:\inetpub\wwwroot\ and change the port to port 8080 rather than port 80 so we can have both running at the same time. The new host name will be secondiiswebsite.com.

Step 3. Change permissions in C:\inetpub\wwwroot

Navigate to C:\inetpub\wwwroot and right click within the window, go to Properties and then click the Security tab and hit the "Edit" button.In Group or user names select Users and check the Allow box under Full Control, apply changes and Ok your way back to the folder.

Step 4. Create distinct index pages

Create a distinct index page in each of the created folders (helloWorld and secondIIS). We should now be able to access each page by opening up a web browser and typing the the host names.




PhpMyAdmin

PhpMyAdmin: a free open source tool written in PHP to handle the administration of MySQL using a web browser. Want to know how to install it? Follow the simple steps below!

Note: Before you install phpMyAdmin open the php.ini file (See PHP Installation Tutorial if this file is not present in C:\PHP) and ensure you have uncommented and thereby activated these two extensions:
  1. extension=php_mysqli.dll
  2. extension=php_pdo_mysql.dll

Step 1: Download PhpMyAdmin

For the sake of consistency across the company we will be downloading phpMyAdmin 4.6.4 and we would like a zip file, assuming the company is primarily English we will download the English only version. In Figure 4.1 below, this is the last option in the list. Click on the file name to begin the download, a window will appear thanking you for downloading and asking if you'd like to donate, simply hit close if you do not wish to make a donation.
Figure 4.1 List of downloadable phpMyAdmin files

Step 2: Extract contents

Upon completion of the download extract the files into the folder where you would like to use phpMyAdmin. I will be using my ashleyhasler.com virtual host configured in the previous tutorial on Apache.

In C:\Apache24\htdocs\ extract Apache into the root of the virtual host you would like to use it with. You can put it in the root of htdocs however, for the sake of this tutorial place it in the firstName+lastName folder you have previously made. In my example I placed it in C:\Apache24\htdocs\ashleyHasler

Step 3: Test if it works!

Start your Apache server by opening ApacheMonitor and once the icon displays a green light visit: firstName+lastName.com/phpMyAdmin, in my case this would be ashleyhasler.com/phpMyAdmin.

If your screen is similar to the one in Figure 4.2 then the installation was successful!
Figure 4.2 phpMyAdmin was successfully installed.

Step 4. Login

To login you will use the user root explained in the MySQL Community Server Installation blog and the password that you set in that blog. If you are successful your screen should look similar to Figure 4.3

Figure 4.3 You have successfully logged in!


MySQL Community Server: Free! Open Source! Downloadable!


MySQL Community Server: a free downloadable version of the world's most popular open source database supported by an active community of open source developers.

Step one: Download

Open your favorite web browser and navigate to: https://dev.mysql.com/downloads/mysql/.
Select your platform and click download on the first option (Windows(x86, 32 bit), MySQL Installer MSI). See Figure 3.1.
Figure 3.1 Browser displayed when you go to the link above
After clicking download scroll down until you see MySQL Installer 5.7.16, see Figure 3.2 for an example. You want to click download on the larger of the two file options, in this case it is the second option, click download. When your download is complete click on it to open up the MySQL Installer.

Figure 3.2 Downloading MySQL Installer

Step 2: Install MySQL Community Server

First agree to the License Agreement and click "Next" to proceed. When choosing a setup type select server only (Figure 3.3). Fill out all other required information that the installer asks for. You do not need to create a user, you will use the root user. All of the default options will suffice.

Note: When typing a password pick something you will remember. It is very important you do not forget this password as it is very difficult to reset.
Figure 3.3 Choose to install the server only

Step 3: Finish Installation

Once you see a message saying installation is complete, as seen in Figure 3.4 below, you may click finish to exit the installer.
Figure 3.4 Installation complete!

PHP: Hypertext Preprocessor

Time to discuss the recursive acronym, PHP!

So you'd like to know how to install PHP 7.0? Follow this short tutorial and you'll be on your way in no time!


Step 1. Download PHP 7.0.12

Head over to: http://www.php.net/downloads.php and under "Current Stable PHP 7.0.12" click on "Windows Downloads"

Under PHP 7.0 we will scroll to "VC14 x64 Thread Safe" and click "Zip" as seen in figure 2.1 below. The download will begin automatically.

We need the VC14 x64 version because that is the version of Apache that we installed in the previous tutorial. Thread safe refers to multi-thread capable builds whereas non thread safe refers to single thread only builds, this is why we picked the thread safe version.

Figure 2.1: PHP 7.0 download for VC14 x64

Step 2. Extract the download

Create a folder called "PHP in the root of the C: drive and extract the php download to that folder (Figure 2.2).
Figure 2.2: Created PHP folder in the root of the C: drive

Step 3. Create php.ini

Once extracted open up the PHP folder and scroll down to php.ini, you'll see two options(Figure 2.3): php.ini-development & php.ini-production make a copy of php.ini-development and rename it php.ini then open it up in your text editor.
Figure 2.3: Extracted contents of PHP download

Step 4. Configure php.ini 

Make the following changes to php.ini:
  • Change extension_dir to "C:/PHP/ext" ()
Figure 2.4
  • Enable the following extensions: (To enable an extension remove the semi-colon)
Figure 2.5

Step 5. Add C:PHP to the environment path variable

Go to Control Panel and click System. Click Advanced and then Environment Variables. Scroll to the System variables list and click Path then Edit. Add ";C:php" to the end of the variable value line. Ensure you include the semi-colon!! You can now click "Ok" until you are back at the initial screen, restart the computer if prompted.
Figure 2.6 Adding PHP to the environment path variable

Step 6: Configure PHP as an Apache module

Go to C:\Apache24\conf\httpd.conf and in the DirectoryIndex add index.php (Figure 2.7). At the top of the file add the content seen in figure 2.8 from there we can test if it is working by opening a command prompt, navigating to Apache24/bin and running the command "httpd -t", if there are no errors then you have configured PHP as an Apache module successfully.


Figure 2.7 Add index.php to the DirectoryIndex
Figure 2.8 Add PHP 7 as an Apache module

Step 7. Let's test it out!

In C:\Apache24\htdocs create a file called index.php and add the following code(Figure 2.9): <?php phpinfo(); ?>
Figure 2.9 Create an index.php file
Go to: C:\Apache24\conf\extra and change the directory index of a virtual host to index.php (Figure 2.10)


Figure 2.10 Change the directory index to index.php
Save all file changes, restart the Apache server and attempt to hit that virtual host, if successful you should see something similar to the output in Figure 2.11.


Figure 2.11 Output successfully loading index.php



Tuesday, October 18, 2016

Apache Tutorial: natives of the Southwest deserts?!

This is why we shouldn't look to Wikipedia for all of our daily questions. Don't let the first wiki link fool you, we aren't referring to the Apache tribe but instead the Apache HTTP server, aka the world's most used web server software! Want to know how to install Apache and configure a virtual host? Check out the tutorial below!


Step 1: Let's go download Apache! 

Before we download Apache we will need to get the latest C++ distributable, this can be acquired by going here. Upon  installation completion, please continue with tutorial.

First things first we go to: https://www.apachelounge.com/download/ and select which version we would like to download. For the purpose of this tutorial we will be using the Apache 2.4 VC14 Win64 binary. VC indicates the version of the compiler, VC 14 is the latest version and that is why we selected this version, 64 indicates it is for a 64 bit platform. To begin to download the .zip, click on the version you would like to download and it will begin automatically (See Figure 1.1).


Figure 1.1 Downloading Apache from Apache Lounge

Step 2. Extract Apache!

Once the download has finished you will extract the files, I extracted them and then placed them in the root of the C: drive for consistency across our organization (Figure 1.2) however it is worth noting Apache can be installed anywhere on your system so long as you change the configuration paths accordingly.
Figure 1.2 Extracting Apache to the root of the C: drive

Step 3. Configure!

Once you have Apache installed, you then need to configure it. To do this you need to open the httpd.conf file. Because we installed Apache in the root of the C: drive to find our httpd.conf file we will use the following path: C:\Apache24\conf, this may vary depending on the location of your installation. Open this file using your desired text editor and make the following modifications.
  1. Modify Listen to listen to all requests on port 80 by changing it to "Listen *:80" (Figure 1.3).
  2. Specify the server domain name (Figure 1.4)
  3. Allow .htaccess overrides, this controls what directives may be placed in .htaccess files (Figure 1.5).

Figure 1.3 Modifying Listen to listen to all requests on port 80
Figure 1.4 Specifying server domain name
Figure 1.5 Allowing .htaccess overrides

Step 4. Test our Apache installation & configuration 

We can test our installation in the command prompt. To open a prompt click the Start menu, type cmd and press enter. Ensure you are in the bin directory of your Apache installation, to do this you can use the cd command. Because I installed Apache in the root of the C: drive my path is: C:\Apache24\bin. Once in the bin directory run the command "httpd -t" until there are no configuration errors, you should receive the message "Syntax OK" (Figure 1.6).

Step 5. Install Apache as a windows service

Apache must now be installed as a windows service. You can do this from the command line in the exact location you were at for the previous command. This time you will run " httpd -k install" (Figure 1.6).

Figure 1.6 Testing Apache configuration and installing as a windows service

Step 6. Is Apache working?

To test if Apache is working, open up the Apache bin folder in Windows Explorer. From there double click on Apache Monitor, if it was successful you should see a green light on the symbol in the toolbar (Figure 1.8).
Figure 1.7 Locating the Apache Monitor Application
Figure 1.8 Successful starting of Apache Monitor

Step 7 Testing localhost

Navigate to C:\Apache24\htdocs and create a file called index.html, within this new file insert some HTML to verify localhost is working.

Hit localhost in your chosen web browser, if successful you should see the contents of the index.html you just created (Figure 1.10).

Figure 1.10 Successfully hitting localhost in a web browser

Let's take it one step further: Configuring two virtual hosts!!

Since we now have Apache working why don't we configure a couple of virtual hosts to go with it!?

Step 1: Add two new index files in separate folders

Navigate to C:\Apache24\htdocs and create two separate folders, name one folder hecklersguild and the other your first and last name(See Figure 1.11 for an example). Within each folder create two separate index.html files and make them distinct in some way, an example is shown in Figure 1.11.
Figure 1.11 Creating 2 separate folders in htdocs

Figure 1.11 Sample html code contained in index.html

Step 2: Add two new virtual hosts

Navigate to C:\Apache24\conf\extra and open httpd-vhosts.conf in a text editor. Copy the example virtual host twice, we will make alterations to each copy. Change each document root to the distinct folders you created in step one. Add a server alias to each new virtual host. Add a server name to each, this is what you will type in the web browser to access the virtual hosts. Ensure the directory indexes are set to index.html because that is what we named the files in step 1. Finally adjust ErrorLog and CustomLog to where you would like them saved. See figure 1.12 for all of the changes you should make.
Figure 1.12 Additions to httpd-vhosts.conf 

Step 3: Add entries to the host file

Navigate to C:\Windows\System32\drivers\etc. Open up the hosts file in a text editor. Add two entries below the comments as demonstrated in Figure 1.13
Figure 1.13 Adding entries to the host file

Step 4: Include virtual hosts configuration file

Navigate to C:\Apache24\conf and open httpd.conf in a text editor, search for Virtual hosts by pressing ctrl+f and typing it in the search, once this is located (as seen in line 495 of Figure 1.14) uncomment the line by removing the pound symbol. This will include virtual hosts in your configuration.
Figure 1.14 Uncommenting the line necessary to include virtual hosts configuration

Step 5: Does it work?!?

Open up your favorite browser and type hecklersguild.com, if your custom index.html appears you did it (see Figure 1.15)!! Type firstName+lastName.com as you configured it above and that too should be your index.html set in that folder(see Figure 1.16).
Figure 1.15 Checking the first virtual host

Figure 1.16 Checking the second virtual host