القائمة الرئيسية

الصفحات

Free Instagram Followers & Likes

How can I create a virtual host on Ubuntu to host multiple websites using Apache?

 Steps to Create a Virtual Host on Ubuntu:

Set Up Apache and PHP:

Install Apache and PHP on your Ubuntu system if you haven't already done so. You can install them using the following commands:

sudo apt update

sudo apt install apache2 php

Create Virtual Host Configuration Files:

Create separate VirtualHost configuration files for each website you want to host. These files typically reside in the /etc/apache2/sites-available/ directory. For example:

sudo nano /etc/apache2/sites-available/domain.conf

Configure VirtualHosts:

In each VirtualHost configuration file, specify the settings for the website, including ServerName, ServerAlias, DocumentRoot, and any other necessary directives. Here's an example configuration:

<VirtualHost *:80>
  # Admin email, Server Name (domain name) and any aliases 
  ServerAdmin admin@gmail.com
  ServerName  domain.test
  ServerAlias www.domain.test
  # Index file and Document Root (where the public files are located)
  DirectoryIndex index.php
  DocumentRoot /var/www/Your Site/public
  <Directory /var/www/Your Site/public>
      Options Indexes FollowSymLinks MultiViews
      AllowOverride All
      Order allow,deny
      allow from all   
      Require all granted 
  </Directory>
    # Custom log file locations  LogLevel warn
  ErrorLog /var/log/apache2/error-domain.test.log
  CustomLog /var/log/apache2/access-domain.test.log combined
</VirtualHost>

Enable the VirtualHosts:

Enable each VirtualHost by creating a symbolic link to the configuration file in the /etc/apache2/sites-enabled/ directory. Use the a2ensite command:

sudo a2ensite domain.conf

Set Up Hosts File:

Add entries to your hosts file (/etc/hosts) to map the domain names to your local server's IP address. For example:

127.0.0.1 domain.test

Restart Apache:

After configuring the Virtual Hosts, restart Apache to apply the changes:

sudo systemctl restart apache2

Test the Websites:

Open your web browser and navigate to the domain names you configured (e.g., domain.test) to verify that the websites are accessible.

By following these steps, you can set up and configure virtual hosts on Ubuntu to host multiple websites using Apache.

أنت الان في اول موضوع

تعليقات

التنقل السريع