Local Apache Host Manager
A collection of bash scripts to manage Apache virtual hosts and SSL certificates for local development environments in Ubuntu.
Author Shakil Ahmed Website: shakilahmeed.com
Overview
This toolkit includes three main scripts:
createhost.sh
- Creates new virtual hosts with SSL certificatesremovehost.sh
- Removes existing virtual hosts and their configurationssitelist.sh
- Lists all configured virtual hosts with their status
Prerequisites
- Ubuntu/Debian-based system
- Apache2 installed
- Root/sudo privileges
Installation
-
Clone the repository:
git clone https://github.com/shakilahmed0369/local-apache-host-manager.git
-
Make the scripts executable:
cd local-apache-host-manager chmod +x createhost.sh removehost.sh sitelist.sh
Usage
sudo ./createhost.sh
You will be prompted to enter:
- Domain name (e.g., myproject.local)
- Project folder name (must exist in /var/www/html)
The script will:
- Add the domain to /etc/hosts
- Create Apache virtual host configuration
- Generate and configure SSL certificates
- Enable the site in Apache
sudo ./removehost.sh
You will be prompted to enter:
- Domain name to remove
The script will:
- Remove the domain from /etc/hosts
- Remove SSL certificates
- Remove Apache configuration
- Disable the site
- Clean up all related files
sudo ./sitelist.sh
This will display a table showing:
- Domain names
- SSL status (✓ or ✗)
- Project paths
- Enabled status (green = enabled, red = disabled)
Directory Structure
Your projects should follow this structure:
/var/www/html/
├── project1/
│ └── public/
└── project2/
└── public/
SSL Certificates
- The scripts generate self-signed SSL certificates for local development
- Browsers will show a security warning (this is normal for local development)
- Certificates are valid for 365 days
Common Issues
-
SSL Warning in Browser
- This is normal for self-signed certificates
- Click "Advanced" → "Proceed to site" (Chrome)
- Click "Advanced" → "Accept Risk" (Firefox)
-
Project Directory Not Found
- Ensure your project exists in
/var/www/html
- Ensure the
public
directory exists in your project folder
- Ensure your project exists in
-
Permission Issues
- All scripts must be run with sudo privileges
- Check Apache log files for detailed errors
File Locations
- Apache configs:
/etc/apache2/sites-available/
- SSL certificates:
/etc/ssl/[domain]/
- Host entries:
/etc/hosts
- Project files:
/var/www/html/[project]/public
Contributing
Feel free to open issues or submit pull requests for improvements.
License
MIT License - feel free to use and modify for your needs.