FOPENP

Apache2: local web site with a domain, on linux

On linux™ you can obtain a local web site with its own domain name, without the need to publish it.

Before all, you need to modify the /etc/hosts file and write, to the right part of 127.0.0.1, the domain name of your choice; for example, mysite.neocities.org:

127.0.0.1       localhost mysite.neocities.org

With this line you can already enter into the local server, like Apache2.

su
apt install apache2

In a Debian GNU/Linux system, your site is seeked in /var/www/html/ and Apache logs are saved in /var/log/apache2/ .
You need to create a folder that will host the site:

su
mkdir /var/www/html/mysite.neocities.org
chown myuser:myuser /var/www/html/mysite.neocities.org

... and you'll need to insert an index.html file into it for make appear the test web site.

After that, you need to create a /etc/apache2/sites-available/mysite.conf file and type inside of it:

<VirtualHost *:80>
        ServerName mysite.neocities.org
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/mysite.neocities.org
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Now you execute (as root):

a2ensite mysite.conf
systemctl restart apache2

The “a2ensite” command indicates to enable your own web site found in mysite.conf configuration.

Now, if you use the linux browser and visit the http://mysite.neocities.org/ hyperlink, the index.html page will be open.

2023
Dec, 18