Installing Virtualmin on Ubuntu and CentOS
Virtualmin is a robust and versatile web hosting control panel designed to streamline the management of domains, websites, email accounts, databases, and more on a Linux server. Its intuitive web interface offers a simplified approach to server configuration and administration.
This guide details the steps required to install Virtualmin on two widely used Linux distributions: Ubuntu and CentOS 7.
Prerequisites
Before commencing the installation of Virtualmin, ensure that your server meets the following prerequisites:
- A clean installation of either Ubuntu (20.04, 22.04 LTS recommended) or CentOS 7.
- A static IP address configured on the server.
- A fully qualified domain name (FQDN) pointing to your server’s IP address. This is crucial for mail server functionality.
- Root or sudo privileges.
- Sufficient system resources (RAM and CPU) depending on the number of websites and applications you plan to host. A minimum of 1GB RAM is recommended.
Step 1 – Install Dependencies
Virtualmin relies on various packages and modules to operate correctly. We’ll begin by installing these dependencies.
On Ubuntu
Execute the following commands as root or a user with sudo access to install the necessary dependencies:
$ sudo apt update
$ sudo apt install -y wget perl libnet-ssleay-perl openssl libauthen-pam-perl libpam-runtime libio-pty-perl apt-show-versions python
Next, enable the Universe repository, which contains community-maintained software:
$ sudo add-apt-repository universe
Install additional packages required for Virtualmin:
$ sudo apt install -y libnet-dns-perl libnet-ldap-perl libnet-dns-sec-perl libnet-ip-perl libplrpc-perl libjson-xs-perl
On CentOS 7
Enable the EPEL (Extra Packages for Enterprise Linux) repository, which provides extra packages not available in the base CentOS repositories:
$ sudo yum install -y epel-release
Install the core dependencies:
$ sudo yum install -y wget perl perl-Net-SSLeay openssl pam pam-devel perl-IO-Tty perl-libwww-perl libtool-ltdl rsync gawk
$ sudo yum install -y perl-Net-DNS perl-Sys-Syslog perl-LWP-Protocol-https perl-Net-IP perl-Encode-Detect
Install further packages:
$ sudo yum install -y perl-JSON-XS perl-Net-DNS perl-LDAP
Step 2 – Download and Install Virtualmin
With the dependencies in place, we can now proceed with the installation of Virtualmin.
Download the installation script:
$ wget https://software.virtualmin.com/gpl/scripts/virtualmin-install.sh
Execute the script to install Virtualmin:
$ sudo sh virtualmin-install.sh
The script will automatically detect your operating system distribution and install the appropriate version of Virtualmin. Carefully follow the prompts during the installation process and provide the requested information, such as your license key (if you have a Virtualmin Professional license), hostname, and other configuration details.
Upon completion, Virtualmin will be successfully installed and ready for use!
The installation script offers a range of useful options:
--bundle LAMP|LEMP Install LAMP (Apache) or LEMP (Nginx) stack
--minimal Install a minimal set of packages
--skip-os-upgrade Skip upgrading system packages
--unattended Run installation unattended without prompts
--reinstall Reinstall Virtualmin
For example, to install a minimal Virtualmin setup with Nginx on Ubuntu, use the following command:
$ sudo sh virtualmin-install.sh --bundle LEMP --minimal
Step 3 – Access Virtualmin Web Interface
Virtualmin provides a web interface accessible on port 10000. To access it:
- Open your web browser.
- Enter your server’s IP address or FQDN followed by port 10000 (e.g.,
https://your_server_ip:10000
orhttps://your_domain.com:10000
). - Log in using the root username and password (or the username and password of the user with sudo privileges).
Step 4 – Initial Configuration
Following the installation of Virtualmin, a few initial configurations are necessary before it can be fully utilized.
Configure Networking
Navigate to Virtualmin > System Info > Networking to configure your server’s networking settings according to your specific requirements.
Key settings to consider:
- Hostname: Ensure that the hostname is correctly set and matches your FQDN.
- Network Interface: Select the correct network interface for your server.
- DNS Servers: Configure the appropriate DNS servers for your network.
Configure SSL Certificate
By default, Virtualmin uses a self-signed SSL certificate. For enhanced security and trustworthiness, it’s highly recommended to install a valid SSL/TLS certificate from a trusted Certificate Authority (CA) like Let’s Encrypt.
To add a custom SSL certificate:
- Go to Virtualmin > Server Configuration > SSL Certificate.
- You can either generate a Let’s Encrypt certificate (if your domain is properly configured) or upload an existing certificate and private key.
- Follow the instructions provided to install the certificate.
Configure Mail Relay Host
To ensure reliable delivery of outgoing emails from your server, relaying through a proper mail server is generally preferable to sending directly.
Under Virtualmin > System Info > Mail, set the Outgoing Mail Relay Host to your mail server, such as Office365, Gmail, or your ISP’s mail server. You will also need to configure the necessary authentication details for the relay host.
Review Configuration
Finally, go to the Virtualmin dashboard and click the Check Configuration button. This will validate that everything is set up correctly and provide helpful tips for resolving any identified issues.
With these initial configurations complete, your Virtualmin installation is ready for use!
Using Virtualmin
Now that Virtualmin is installed and configured, you can begin using it to manage your web hosting environment. Here are some common tasks you can perform:
- Create Virtual Servers: Set up new virtual servers (websites) with dedicated domains, users, and resources.
- Manage DNS Records: Configure DNS records for your domains, including A records, MX records, and CNAME records.
- Create Email Accounts: Create and manage email accounts for your domains.
- Manage Databases: Create and manage MySQL or MariaDB databases for your websites.
- Install Web Applications: Easily install popular web applications like WordPress, Joomla, and Drupal.
- Monitor Server Resources: Monitor your server’s CPU usage, memory usage, and disk space usage.
- Configure Backups: Set up regular backups of your virtual servers and databases.
Refer to the comprehensive Virtualmin documentation for more detailed information on all the available features and how to use them effectively.
Conclusion
This guide has provided a detailed, step-by-step process for installing Virtualmin on Ubuntu and CentOS 7. By carefully following these instructions, you can successfully install and configure Virtualmin, benefiting from its powerful web hosting control panel that greatly simplifies server administration. The initial post-installation configurations are crucial for ensuring optimal performance and security.
With Virtualmin, even those with limited technical experience can effortlessly manage multiple websites, email accounts, databases, and more on a Linux system through its intuitive web interface. It’s an invaluable tool for efficiently delivering hosting services on VPS or dedicated servers.
Alternative Solutions for Web Hosting Management
While Virtualmin provides a comprehensive and user-friendly interface for web hosting management, other solutions cater to different needs and preferences. Here are two alternative approaches:
1. Docker Compose with Pre-built Images
This approach leverages containerization technology to create a self-contained environment for each website or application. Docker Compose simplifies the orchestration of multiple Docker containers, allowing you to define your entire web hosting stack in a single docker-compose.yml
file.
Explanation:
Instead of installing individual services like Apache/Nginx, PHP, and MySQL directly on the host operating system, you would use Docker images that encapsulate these services. Docker Compose then manages the creation, configuration, and networking of these containers. This approach offers several advantages:
- Isolation: Each website or application runs in its own isolated container, preventing conflicts and ensuring security.
- Reproducibility: The
docker-compose.yml
file defines the entire environment, making it easy to replicate across different servers. - Scalability: Docker containers can be easily scaled up or down as needed.
- Simplified Management: Docker Compose provides a single point of control for managing the entire web hosting stack.
Code Example (docker-compose.yml):
version: "3.8"
services:
web:
image: nginx:latest
ports:
- "80:80"
- "443:443"
volumes:
- ./html:/usr/share/nginx/html
- ./nginx.conf:/etc/nginx/conf.d/default.conf
depends_on:
- php
php:
image: php:8.1-fpm
volumes:
- ./html:/var/www/html
db:
image: mysql:8.0
environment:
MYSQL_ROOT_PASSWORD: your_root_password
MYSQL_DATABASE: your_database_name
volumes:
- db_data:/var/lib/mysql
volumes:
db_data:
Explanation of the docker-compose.yml
file:
- version: Specifies the Docker Compose file version.
- services: Defines the different services that make up the web hosting stack.
- web: The Nginx web server.
- image: Uses the
nginx:latest
Docker image. - ports: Maps ports 80 and 443 on the host to the corresponding ports in the container.
- volumes: Mounts the
html
directory on the host to the/usr/share/nginx/html
directory in the container, allowing you to serve your website files. It also mounts a custom Nginx configuration file. - depends_on: Specifies that the
web
service depends on thephp
service.
- image: Uses the
- php: The PHP-FPM processor.
- image: Uses the
php:8.1-fpm
Docker image. - volumes: Mounts the
html
directory on the host to the/var/www/html
directory in the container, allowing PHP to access your website files.
- image: Uses the
- db: The MySQL database server.
- image: Uses the
mysql:8.0
Docker image. - environment: Sets environment variables for the database, including the root password and the database name.
- volumes: Creates a named volume
db_data
to persist the database data.
- image: Uses the
- web: The Nginx web server.
- volumes: Defines the named volumes used by the services.
To start the stack, navigate to the directory containing the docker-compose.yml
file and run:
docker-compose up -d
This will build and start the containers in detached mode.
2. Ansible for Automated Server Provisioning and Configuration
Ansible is an open-source automation tool that allows you to define infrastructure as code. Instead of manually installing and configuring each server, you can use Ansible playbooks to automate the entire process.
Explanation:
Ansible works by connecting to your servers over SSH and executing tasks defined in YAML-based playbooks. These playbooks can include tasks such as installing packages, configuring services, deploying code, and managing users. This approach offers several benefits:
- Idempotency: Ansible ensures that each task is executed only once, even if the playbook is run multiple times.
- Agentless: Ansible does not require any agents to be installed on the target servers.
- Scalability: Ansible can manage hundreds or even thousands of servers simultaneously.
- Version Control: Playbooks can be stored in version control systems like Git, allowing you to track changes and revert to previous configurations.
Code Example (Ansible Playbook – install_apache.yml):
---
- hosts: webservers
become: true
tasks:
- name: Update apt cache
apt:
update_cache: yes
when: ansible_os_family == "Debian"
- name: Install Apache2
apt:
name: apache2
state: present
when: ansible_os_family == "Debian"
- name: Start Apache2 service
service:
name: apache2
state: started
enabled: yes
when: ansible_os_family == "Debian"
- name: Install httpd (Apache) on CentOS
yum:
name: httpd
state: present
when: ansible_os_family == "RedHat"
- name: Start httpd service on CentOS
service:
name: httpd
state: started
enabled: yes
when: ansible_os_family == "RedHat"
Explanation of the Ansible Playbook:
- hosts: Specifies the target hosts for the playbook (in this case, a group named "webservers").
- become: Grants the playbook root privileges.
- tasks: Defines the individual tasks to be executed.
- Update apt cache: Updates the APT package cache on Debian-based systems.
- Install Apache2: Installs the Apache2 web server on Debian-based systems.
- Start Apache2 service: Starts and enables the Apache2 service on Debian-based systems.
- Install httpd (Apache) on CentOS: Installs the httpd package (Apache) on CentOS/RedHat-based systems.
- Start httpd service on CentOS: Starts and enables the httpd service on CentOS/RedHat-based systems.
- when: Conditional statements that determine when a task should be executed, based on the operating system family.
To run this playbook, you would first need to configure Ansible to connect to your servers. Then, you would execute the following command:
ansible-playbook install_apache.yml
This would automatically install and configure Apache on all servers in the "webservers" group. You could extend this playbook to install other services, configure virtual hosts, and deploy your website code. This approach provides a high degree of automation and control over your web hosting infrastructure.