0

[I have already installed and set up Apache2; this is not a duplicate question, please see below]

I have uploaded a HTML file to the Apache2 localhost web server, using the default :8000 port. I want this file to be accessible via a web browser on another device in another location, by entering a WWW domain into a search engine. In other words, I want to create a fully accessible website while keeping the HTML files for my website on the Apache web server.

I would appreciate any help I can get.

3 Answers3

1

Place the file like this /var/www/html/index.html. Then go to /etc/apache2/sites-available, here create a file index.conf and add the following

<VirtualHost *:80>
        ServerName test.com
        ServerAdmin info@test.com
        ServerAlias www.test.com
        DocumentRoot /var/www/html

        <Directory /var/www/html>
                Require all granted
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

As I did forgot and E. Yagmahan mentioned save your file and run this command:

sudo a2ensite index.conf

This command will enable your configuration file.

After all that run this:

sudo systemctl restart apache2
  • Thanks, I will try this out. By the way, I was advise by a friend who does CS not to use the :80 port, and to use another one instead. Is he right, or is there any reason in not wanting to use the :80 port? – Ruairí Másún Jan 05 '19 at 19:20
  • https://httpd.apache.org/docs/2.4/vhosts/examples.html read this. Port 80 is used for http making it a reserve port. – thirteen4054 Jan 05 '19 at 19:34
  • 1
    @RuairíMásún if you intend http://domain.tld/ to go directrly to the site you need to use port 80. Your friend who does "CS" is not familiar with IT networking, but they're probably trying to shield you from typical HTTP based attack vectors and port scanners, but that's just security through obscurity and is useless in the long run. (FYI: I'm an IT Security professional so I'm speaking from some levels of experience here.) – Thomas Ward Jan 05 '19 at 19:35
  • If you have a custom application that does not run as root or doesn't get served directly by Apache, then yes you would use port 8000. But that's not the case when Apache itself is serving the files. – Thomas Ward Jan 05 '19 at 19:36
  • I can't create a new file in the /etc/apache2/sites-available directory directly. Am I able to do this using Terminal? If so, how do I do it? I've opened the Terminal in that directory. – Ruairí Másún Jan 05 '19 at 19:55
  • Yes it is done using terminal. Go to this directory etc/apache2/sites-available and type sudo nano index.conf. Once you have added contents in the file press Ctrl+O to save it. – thirteen4054 Jan 05 '19 at 20:56
  • @thirteen3054 I am having trouble doing this still. I have followed all of the steps you have made, in this order:

    First, I created the index.conf file in the /etc/apache2/sites-available directory by opening the Terminal there and going "touch index.conf" (I had already put my index.html file in the /var/www/html/ directory).

    Then, I opened the Terminal again in the same place and ran this command: sudo a2ensite index.conf

    – Ruairí Másún Jan 06 '19 at 03:23
  • @thirteen3054 Then, I ran this command in a new Terminal window:

    <VirtualHost *:80> ServerName test.com ServerAdmin info@test.com ServerAlias www.test.com DocumentRoot /var/www/html

        <Directory /var/www/html>
                Require all granted
        </Directory>
    
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    
    

    And finally, I ran this command:

    sudo systemctl restart apache2

    – Ruairí Másún Jan 06 '19 at 03:26
  • @thirteen3054 However, this didn't work. When I enter my localhost address (127.0.0.1) it just opens the file as before (http://127.0.0.1) and I can't give it a web address. Do you have any other suggestions I can make? – Ruairí Másún Jan 06 '19 at 03:28
  • @E. Yagmahan The steps above did not work. Do you have any other solutions? – Ruairí Másún Jan 06 '19 at 03:28
  • @RuairíMásún you are not to run <VirtualHost *80>...</VirtualHost> I did not said that. this snippet needs to be in index.conf file. After that run sudo a2ensite index.conf in same directory. – thirteen4054 Jan 07 '19 at 18:12
  • @thirteen3054 How do I edit the file once it's in the etc/apache2/sites-available directory? I open the file using a text editor, and when I try to save the updates, it says permission denied. I assume there is some way I can do this using the Terminal with a sudo command. – Ruairí Másún Jan 07 '19 at 20:44
  • from terminal go to the sites-available and and type sudo nano index.conf – thirteen4054 Jan 08 '19 at 00:26
  • @thirteen3054 Thanks for your help so far. I have created an index.conf file in the sites-available directory with all of the information you suggested and have run the suggested commands after that. However, when I search in the URL bar for 127.0.0.1 the web page comes up as a normal directory still. How do I make the webpage accessible via a WWW domain? – Ruairí Másún Jan 08 '19 at 19:45
0

In addition to the answers of thirteen3054:

After creating the new file index.conf you should enable it via:

sudo a2ensite index.conf

Doing that enables the specified site within the apache2 configuration. It does this by creating symlinks within /etc/apache2/sites-enabled. (Likewise, "a2dissite" disables a site by removing those symlinks.)

0

Place the file like this /var/www/html/index.html. Then go to /etc/apache2/sites-available, here create a file index.conf and add the following

ServerName test.com ServerAdmin info@test.com ServerAlias www.test.com DocumentRoot /var/www/html

    <Directory /var/www/html>
            Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

save your file and run this command:

sudo a2ensite index.conf This command will enable your configuration file.

After all that run this: /etc/init.d/apache2 restart