Apache Local Web Server



Step 5: Testing a Beta Run Of Your Home Web Server. Now that you have successfully port-forwarded your router or modem, it’s time to test your home web server and open a sample local website stored in your computer from any other computer you might have. Go to whatsmyip.org to find out your computer’s external IP address. Apache is a popular open-source, cross-platform web server that is, by the numbers, the most popular web server in existence. It’s actively maintained by the Apache Software Foundation.

How to configure Apache 2 web server on a local Linux computer for local web development. Configure Apache to host multiple local web sites for web development on Linux Mint or Ubuntu.

The previous blog post describes how to set up a LAMP stack on a local Linux computer. This post shows how to set up multiple web sites on a single local LAMP server. Having copies of websites on a local computer allows PHP code and WordPress plugins or themes to be developed and tested on a local computer. After testing the PHP code or plugins, they can be uploaded to the live version of the website.

Apache Settings for Local Web Development

Be sure to install a local LAMP stack before continuing with this tutorial.

Choose the Websites Location

Make a folder that contains your local websites. This should be in your home directory or folder. As an example, you could create a folder called websites in your home directory. The full path to the folder would then be:

Create a Folder for Each Website

Create a new folder for each local website that you want. Create these folders inside the main folder that you created in the previous step. Two folders are created as examples for this tutorial. The first folder is called test and the second site as shown below.

More folders for additional websites can be added at any time.

Write a PHP script called index.php for each of the websites that will uniquely identify them. For example, print the name of each website so that it can be viewed in a browser. Save the scripts to their respective website folders created above.

Example index.php script for the test website:

Make a similar PHP file for the site website, but substitute Site in the file for Test in two places.

Configure Apache 2 Web Server

A configuration file for each local website must be created by copying an existing file in the Linux file system. Open file manager as root to edit the file system files. Alternatively use the command line and a text editor such as nano.

Opening the File Manager as Root

Press Alt + F2 to open the Run Application dialog box. In Linux Mint Mate, type gksudo caja in the dialog box and hit the Enter key. Caja is the file manager in Linux Mint Mate. Substitute the file manager name for your Linux distribution in the run box.

After pressing Enter, you will be prompted for your Linux password. Enter your password and the file manager will start with root privileges.

Caution: With the file manager opened as root it is possible to edit or delete any file in the file system. Use the file manager with great care when it is opened as root and close it immediately after all the file system files have been edited.

Create the Apache 2 Configuration Files

Use the file manager to navigate to:

Make a copy of 000-default.conf for each website that will be configured. Drag this file in file manager and hold down the Ctrl key before dropping it in the same folder to make copies of this file. Rename each new file to the name of the folders being used, i.e. test and site for this example. The image below shows the two new files created by copying 000-default.conf in the file manager. The files are renamed next.

To rename a file in file manager, click the file to select it and then press F2 to edit it. Now type the new name and press the Enter key. The result of renaming the two files is shown below. You should now have two files called test.conf and site.conf which are copies of 000-default.conf.

Editing the Apache Configuration Files

Apache Local Web Server

Each of the configuration files must now be edited. Double-click test.conf to open it for editing (this must be done in the file manager opened as root or else it will not be able to be saved). Add the following lines to the file. First change the server name at the top of the file. Modify the paths in the below text to suit your user name and website name. The sever name and paths are marked in bold in the next code listing.

The complete file looks as follows:

It is important to modify the lines above marked in bold. These lines will be different for each website and must contain the name of the web server and path to each website’s folder.

Save and close these files after editing.

Activate the New Local Websites

Right-click in the file manager that was opened as root and should have the /etc/apache2/sites-available/ folder open. In the menu that pops up click Open in Terminal to open this folder in a terminal window.

Apache Web Server Versions

In the terminal window, type a2ensite followed by the site name(s), e.g.:

The terminal window is shown below after running the command.

The terminal window can now be closed.

Configure Host

In the file manager that was opened as root, navigate two folders back. This will be the /etc/ folder. Open the hosts file for editing (/etc/hosts).

Local

Add the names of the new sites next to the IP address of 127.0.0.1. The edited file is shown below.

Save and close the file.

Setup apache web server ubuntu

Open a terminal window and enter the following to restart the Apache server so that the changes can take effect.

Modify File and Folder Permissions

Apache web server tutorial

The new websites are now configured, but Apache does not have permission to access your local website folders. Before continuing, close the file manager that you opened as root.

Open a normal file manager (not as root) and navigate to your website folders. Select the website folders (test and site for this example) and right click them. In the menu that pops up, click Properties. In the Properties dialog box, click the Permissions tab. Change the permissions for Group and Others to Access Files and Read-only as shown below. Click the Apply Permissions to Enclosed Files button and then the Close button.

In the file manager, move one level back and using the same method, change the permissions for the websites folder to Access files for the Folder access options for Group and Others. Do the same for your home folder.

Apache Web Server Windows 10

Access the Local Websites

The local websites used as examples in this tutorial can now be accessed from a browser. Type http://test in the browser address bar to access the test website and http://site to access the site website. You can now use the new websites for local web development of PHP and WordPress sites or other sites or applications that use a LAMP stack.

Further Configuration

You may also want to configure PHP to display error and warning messages during software development on the local LAMP stack. Enabling error and warning messages to be displayed helps with debugging PHP code locally before moving it to a live production server.