Skip to main content

How to Create an Apache Virtual Host on Linux (Debian/Ubuntu)

HardReset.InfoJanuary 18, 202610 min18 views
17 connections·22 entities in this video→

Apache Virtual Host Setup on Linux

  • πŸ’‘ Apache installation is a prerequisite; check its status with sudo systemctl status apache2.
  • πŸš€ If Apache is stopped or disabled, use sudo systemctl start apache2 or sudo systemctl enable apache2.

Creating the Site Directory and Permissions

  • πŸ“‚ Create a directory for your new site using mkdir -p /var/www/mysite.local/public_html.
  • πŸ”‘ Set ownership and group with sudo chown -R www-data:www-data /var/www/mysite.local/public_html.
  • βš™οΈ Apply permissions using sudo chmod -R 755 /var/www/mysite.local/public_html.

Creating the Index File and Virtual Host Configuration

  • πŸ“ Create a simple index.html file in the public_html directory using nano.
  • πŸ“„ Define the virtual host configuration in /etc/apache2/sites-available/mysite.local.conf.
  • 🏑 Key directives include ServerAdmin, ServerName, ServerAlias, and DocumentRoot pointing to your site's directory.
  • πŸ—„οΈ Configure ErrorLog and CustomLog paths within the virtual host file.

Enabling the Virtual Host and Testing

  • πŸ› οΈ Enable the new virtual host with sudo a2ensite mysite.local.conf.
  • 🚫 Disable the default Apache site using sudo a2dissite 000-default.conf.
  • βœ… Test the Apache configuration syntax with sudo apachectl configtest.
  • πŸ”„ Restart Apache for changes to take effect: sudo systemctl restart apache2.
  • πŸ’» Edit the hosts file (sudo nano /etc/hosts) to map mysite.local to 127.0.0.1.
  • 🌐 Access your local domain (http://mysite.local) in a web browser to confirm it's working.
Knowledge graph22 entities Β· 17 connections

How they connect

An interactive map of every person, idea, and reference from this conversation. Hover to trace connections, click to explore.

Hover Β· drag to explore
22 entities
Chapters4 moments

Key Moments

Transcript36 segments

Full Transcript

Topics14 themes

What’s Discussed

Apache Virtual HostApache2LinuxDebianUbuntuWeb Server ConfigurationLocal DevelopmentSystemctlChownChmodA2ensiteA2dissiteApachectl/etc/hosts
Smart Objects22 Β· 17 links
ProductsΒ· 4
MediasΒ· 3
CompanyΒ· 1
ConceptsΒ· 13
LocationΒ· 1