Table of Content#
- Prerequisites
- Zentyal Server Installation
- Domain Names and DNS Configuration
- Installing Apache Web Server
- Using Zentyal's Package Manager
- Configuring Apache Virtual Hosting
- Creating Virtual Host Directories
- Editing the Apache Configuration File
- Enabling the Virtual Host
- Testing the Setup
- Checking Apache Configuration
- Accessing the Websites
Prerequisites#
Zentyal Server Installation#
Before you can start with web services configuration, you need to have Zentyal Server installed on your server hardware. You can download the installation media from the official Zentyal website (https://www.zentyal.org/download/) and follow the on - screen installation wizard. Make sure your server meets the minimum system requirements (e.g., sufficient disk space, memory, etc.).
Domain Names and DNS Configuration#
You should have at least one domain name (or multiple if you plan to host multiple sites) registered. Also, configure your DNS (Domain Name System) records. For each domain you want to use with your virtual hosts, you need to create an A record that points to the IP address of your Zentyal Server. For example, if your server's IP is 192.168.1.100 and your domain is example.com, create an A record for example.com with the value 192.168.1.100. If you have sub - domains like blog.example.com, create an A record for that as well.
Installing Apache Web Server#
Using Zentyal's Package Manager#
Zentyal Server comes with a package manager that simplifies the installation of software. Log in to your Zentyal Server's web interface (usually at https://your_server_ip:8443). Navigate to the "Software" section. In the search bar, type "apache2". You should see the Apache HTTP Server package listed. Click on the "Install" button next to it. Zentyal will then download and install the necessary packages for Apache.
Configuring Apache Virtual Hosting#
Creating Virtual Host Directories#
- For a Single Site (e.g.,
example.com):- Log in to your Zentyal Server via SSH (using a tool like PuTTY on Windows or the terminal on Linux/macOS).
- Create a directory for your website's files. For example, if your domain is
example.com, you can create a directory like/var/www/example.com. Use the commandsudo mkdir -p /var/www/example.com. - Set the appropriate permissions. You can use
sudo chown -R www-data:www-data /var/www/example.com(wherewww-datais the user and group that Apache runs as). Andsudo chmod -R 755 /var/www/example.comto give read and execute permissions to others.
- For Multiple Sites (e.g.,
example.comandblog.example.com):- Repeat the above steps for each domain. So, create
/var/www/blog.example.comfor theblog.example.comdomain.
- Repeat the above steps for each domain. So, create
Editing the Apache Configuration File#
- For
example.com:- Open the Apache configuration file for the virtual host. Create a new file in the
/etc/apache2/sites-available/directory. Forexample.com, usesudo nano /etc/apache2/sites-available/example.com.conf. - Add the following basic configuration:
- Open the Apache configuration file for the virtual host. Create a new file in the
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>- `ServerAdmin` is the email address for administrative contact. `ServerName` is the main domain name. `ServerAlias` can be used for additional domain names (like `www` sub - domain). `DocumentRoot` points to the directory where your website files are stored. `ErrorLog` and `CustomLog` define the log files.
2. For blog.example.com:
- Create a new file /etc/apache2/sites-available/blog.example.com.conf using sudo nano /etc/apache2/sites-available/blog.example.com.conf.
- Add the following:
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName blog.example.com
DocumentRoot /var/www/blog.example.com
ErrorLog ${APACHE_LOG_DIR}/blog_error.log
CustomLog ${APACHE_LOG_DIR}/blog_access.log combined
</VirtualHost>Enabling the Virtual Host#
- For
example.com:- Enable the virtual host using the command
sudo a2ensite example.com.conf.
- Enable the virtual host using the command
- For
blog.example.com:- Similarly, use
sudo a2ensite blog.example.com.conf. - After enabling the virtual hosts, you need to restart Apache for the changes to take effect. Use the command
sudo service apache2 restart.
- Similarly, use
Testing the Setup#
Checking Apache Configuration#
- Syntax Check:
- Before restarting Apache (if you haven't already), you can check the syntax of your configuration files. Use the command
sudo apache2ctl configtest. If there are no errors, you should see a message likeSyntax OK.
- Before restarting Apache (if you haven't already), you can check the syntax of your configuration files. Use the command
- Log Files:
- Check the error logs (e.g.,
/var/log/apache2/error.logfor the main site and/var/log/apache2/blog_error.logfor the blog site) if you encounter any issues. The logs can give you clues about what's wrong, such as permission errors or misconfigured directives.
- Check the error logs (e.g.,
Accessing the Websites#
- For
example.com:- Open a web browser and type
http://example.com(orhttp://www.example.comif you have set up theServerAlias). You should see the default page (if you haven't added any custom content yet) or your custom website if you've uploaded files to theDocumentRootdirectory.
- Open a web browser and type
- For
blog.example.com:- Type
http://blog.example.comin the browser. Again, you should see the appropriate content based on what's in theDocumentRootdirectory for that virtual host.
- Type
Reference#
- Zentyal Server Documentation: https://doc.zentyal.org/
- Apache HTTP Server Documentation: https://httpd.apache.org/docs/