KwikSteps

StepsHow to setup Apache on Bash on Ubuntu on windows

by

Apache server can be installed and run easily on windows after the Windows 10 Anniversary Update which includes Bash on Ubuntu on Windows feature. We will show you step by step how to do it.

Article Image

Requirements

  • Windows 10 64-bit
  • Windows 10 Anniversary Update
  • Bash on Ubuntu on Windows feature

If you are not running the Windows 10 Anniversary Update or Windows 10 Creator Update, please follow one of the following tutorials:

If you are running Windows 10 Anniversary Update but haven’t installed the Bash on Ubuntu on Windows feature, please follow the following tutorial:

Tools and commands used

  • Bash on Ubuntu on Windows shell
  • apt-get shell command
  • service shell command
  • nano editor

You can also check the following tutorials:

Step 1: Run the Bash on Ubuntu on Windows shell

To do this, click on start (or press the Windows key) and type “Bash on Ubuntu on Windows” then click on it to start using the shell.
If you are not running bash as root, please type:

su root

If prompted to enter the password, please do so.

Step 2: Download and install Apache server using apt-get

You need to use the Linux command apt-get in order to install the Apache server or any other package.

apt-get install apache2

Step 3: Start the Apache server using the service command

If prompted to continue, type Y. When the installation is done, you can start the Apache service by typing:

service apache2 start

Step 4: Test the Apache server at http://localhost

To test if the Apache server is running and working correctly, start your browser and point to the following address:

http://localhost/

If everything is working fine, the Apache2 default page will appear with explanation on how to configure the server.

To access the location of the www folder from the Bash, type the following:

cd /var/www/html/

We recommend editing the configuration of the Apache server and change the location of the /var/www folder to another location.

To access the location of the windows drive c or other drivers or folders from the Bash, type the following:

cd /mnt/c/

Step 5: Modify the Apache server configuration

Let’s assume you want to change the Apache www folder to another location, start by creating the new location as follow:

cd /mnt/c/
mkdir www
mkdir www/html
cd www/html 

Now create an html file by typing:

nano index.html

In the editor type the following:

<!DOCTYPE html>
<html>
<head>
<title>Hello server Title</title>
</head>
<body>
<h1>Hello server Header</h1>
</body>
</html>

Press Ctrl+O and hit enter to save the file. Press Ctrl+x to exit the editor.

We need now to change the Apache configuration sites-enabled file to point to the new folder. Type the following:

cd /etc/apache2/sites-enabled
nano 000-default.conf

Change the DocumentRoot section of the VirtualHost as shown below:

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
#       DocumentRoot /var/www/html
        DocumentRoot /mnt/d/www/html

Press Ctrl+O and hit enter to save the file. Press Ctrl+x to exit the editor.
Then change the Apache configuration apache2.conf file to point to the new folder by typing the following:

cd /etc/apache2/
nano apache2.conf

Look and comment the Directory section that has /var/www as its directory and change it as follow:

#<Directory /var/www/>
<Directory /mnt/d/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require all granted
</Directory>

Make sure you restart the Apache server after making the configuration. You can do this by typing:

service apache2 restart

To test if the new configuration is working correctly, start your browser and point to the following address:

http://localhost/
Comments (2)
Load comments
Post your comment
*Name:
Email:
*Comment:
Post Comment
logo203X28
Copyright © 2017
KwikSteps
- All Rights Reserved.
Thank you!
Namecheap.com