Dino Geek, try to help you

How to configure a virtual server on Apache?


Apache has the capability of serving multiple domains from a single server by using a mechanism called “virtual hosts”. If a server has one IP address and two domains are hosted on it, each pointing to the same IP, Apache uses the domain name that the browser requests to serve the correct website.

Here’s a simple step-by-step guide to set up a virtual host:

1. Create a Directory for The Domain Document Root Create a directory that will hold the website’s files. This can be at any location but for demonstration, let’s put it in `/var/www/`.

sudo mkdir /var/www/your\_domain

1. Grant Permissions Allow the `$USER` environment variable to hold your username.

sudo chown -R $USER:$USER /var/www/your\_domain sudo chmod -R 755 /var/www/your\_domain

1. Create a New Virtual Host File Apache comes with a default virtual host file called `000-default.conf` that we can use as a jumping off point.

sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/your\_domain.conf

1. Configure the New Virtual Host File Open the new file in your editor with root privileges:

sudo nano /etc/apache2/sites-available/your\_domain.conf Modify it to look like the following: ServerAdmin webmaster@localhost ServerName your\_domain ServerAlias www.your\_domain DocumentRoot /var/www/your\_domain ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined

1. Enable New Virtual Host File

sudo a2ensite your\_domain.conf This creates a symbolic link from this file to the sites-enabled directory, which is read by Apache.

1. Test Configuration Now it’s time to test our configuration file for syntax errors:

sudo apache2ctl configtest If everything is OK, it will return `Syntax OK`. If not, it will tell you what’s wrong.

1. Restart Apache After all this, restart Apache for the changes to take effect:

sudo systemctl restart apache2

Now, you should be able to access the domain your\_domain and see the content you’ve added to the respective directory.


Simply generate articles to optimize your SEO
Simply generate articles to optimize your SEO





DinoGeek offers simple articles on complex technologies

Would you like to be quoted in this article? It's very simple, contact us at dino@eiki.fr

CSS | NodeJS | DNS | DMARC | MAPI | NNTP | htaccess | PHP | HTTPS | Drupal | WEB3 | LLM | Wordpress | TLD | Domain name | IMAP | TCP | NFT | MariaDB | FTP | Zigbee | NMAP | SNMP | SEO | E-Mail | LXC | HTTP | MangoDB | SFTP | RAG | SSH | HTML | ChatGPT API | OSPF | JavaScript | Docker | OpenVZ | ChatGPT | VPS | ZIMBRA | SPF | UDP | Joomla | IPV6 | BGP | Django | Reactjs | DKIM | VMWare | RSYNC | Python | TFTP | Webdav | FAAS | Apache | IPV4 | LDAP | POP3 | SMTP

| Whispers of love (API) | Déclaration d'Amour |






Legal Notice / General Conditions of Use