{"id":49626741,"url":"https://github.com/shuvo-halder/virtualhost-automation","last_synced_at":"2026-05-05T08:01:35.355Z","repository":{"id":261051376,"uuid":"694805657","full_name":"shuvo-halder/virtualhost-automation","owner":"shuvo-halder","description":"Production-Grade Virtual Host Manager for Apache \u0026 Nginx on Ubuntu/Debian.","archived":false,"fork":false,"pushed_at":"2026-05-05T06:25:31.000Z","size":37,"stargazers_count":1,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-05-05T07:27:12.747Z","etag":null,"topics":["automation","bash-scripting","hosts","linux-automations","linux-server","server","shuvo-halder"],"latest_commit_sha":null,"homepage":"https://acquirespot.xyz","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shuvo-halder.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-09-21T18:21:11.000Z","updated_at":"2026-05-05T06:07:34.000Z","dependencies_parsed_at":"2024-11-04T13:17:52.488Z","dependency_job_id":null,"html_url":"https://github.com/shuvo-halder/virtualhost-automation","commit_stats":null,"previous_names":["shuvo-halder/apache-virtualhost","shuvo-halder/virtualhost-automation"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/shuvo-halder/virtualhost-automation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shuvo-halder%2Fvirtualhost-automation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shuvo-halder%2Fvirtualhost-automation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shuvo-halder%2Fvirtualhost-automation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shuvo-halder%2Fvirtualhost-automation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shuvo-halder","download_url":"https://codeload.github.com/shuvo-halder/virtualhost-automation/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shuvo-halder%2Fvirtualhost-automation/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32640538,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-04T10:08:07.713Z","status":"online","status_checked_at":"2026-05-05T02:00:06.033Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automation","bash-scripting","hosts","linux-automations","linux-server","server","shuvo-halder"],"created_at":"2026-05-05T08:01:34.046Z","updated_at":"2026-05-05T08:01:35.345Z","avatar_url":"https://github.com/shuvo-halder.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"Virtualhost Automation v2.0.0\n===========\n\n\u003e **Production-Grade Virtual Host Manager for Apache \u0026 Nginx on Ubuntu/Debian**\n\nBash scripts to safely create and manage Apache/Nginx virtual hosts on Ubuntu/Debian servers with professional features like logging, dry-run mode, validation, and comprehensive documentation.\n\n---\n\n## ✨ Features\n\n### Core Features\n- ✅ **Create Virtual Hosts** - Automated setup with best practices\n- ✅ **Delete Virtual Hosts** - Safe removal with backup options\n- ✅ **List All Hosts** - View all active virtual hosts\n- ✅ **DNS Management** - Automatic /etc/hosts entries\n- ✅ **Domain Validation** - Strict input validation\n- ✅ **Permission Management** - Proper ownership and permissions\n- ✅ **Test Files** - Auto-generated phpinfo.php and index.html\n\n### Production Features\n- 🔐 **Security Hardened** - Deny hidden files, proper permissions\n- 📝 **Comprehensive Logging** - All operations logged to `/var/log/virtualhost/`\n- 🔍 **Verbose Mode** - Detailed output with `-v` flag\n- 🎯 **Dry-Run Mode** - Preview changes with `-d` flag without executing\n- 💾 **Backups** - Automatic backups of modified system files\n- ⚡ **Performance** - Gzip compression, caching headers, static file optimization\n- 🐛 **Error Handling** - Graceful error messages and recovery\n- 📚 **Help System** - Full `--help` and `--version` commands\n\n### Apache-Specific\n- `mod_rewrite` enabled by default\n- Framework-ready configuration (Laravel, WordPress, Drupal)\n- Gzip compression enabled\n- Deny access to hidden files\n- Error/Access logging per domain\n\n### Nginx-Specific\n- PHP-FPM socket support (TCP \u0026 Unix)\n- Static file caching with 30-day expiry\n- Security hardening (deny hidden files)\n- Fastcgi parameters optimization\n- Per-domain error/access logging\n\n---\n\n## 📋 Requirements\n\n- Ubuntu 18.04+ or Debian 9+\n- Apache 2.4+ or Nginx 1.14+\n- PHP 7.0+ (optional, for phpinfo test)\n- Sudo access (root privileges)\n- Bash 4.0+\n\n### For Apache:\n```bash\nsudo apt-get install apache2 apache2-utils php libapache2-mod-php\nsudo a2enmod rewrite\n```\n\n### For Nginx:\n```bash\nsudo apt-get install nginx php-fpm\n```\n\n---\n\n## 📦 Installation\n\n### Method 1: Quick Install (Recommended)\n```bash\n# Download and install both scripts globally\ncd /usr/local/bin\n\n# Apache\nsudo wget https://raw.githubusercontent.com/shuvo-halder/virtualhost-automation/master/virtualhost.sh\nsudo chmod +x virtualhost.sh\nsudo ln -s virtualhost.sh virtualhost\n\n# Nginx\nsudo wget https://raw.githubusercontent.com/shuvo-halder/virtualhost-automation/master/virtualhost-nginx.sh\nsudo chmod +x virtualhost-nginx.sh\nsudo ln -s virtualhost-nginx.sh virtualhost-nginx\n```\n\n### Method 2: Clone Repository\n```bash\ngit clone https://github.com/shuvo-halder/virtualhost-automation.git\ncd virtualhost-automation\nchmod +x virtualhost.sh virtualhost-nginx.sh\n\n# Optional: Link to PATH\nsudo ln -s $(pwd)/virtualhost.sh /usr/local/bin/virtualhost\nsudo ln -s $(pwd)/virtualhost-nginx.sh /usr/local/bin/virtualhost-nginx\n```\n\n### Method 3: Manual Download\n1. Download `virtualhost.sh` or `virtualhost-nginx.sh`\n2. Make executable: `chmod +x /path/to/script.sh`\n3. Run with: `sudo /path/to/script.sh [options] command domain`\n\n---\n\n## 🚀 Quick Start\n\n### Apache\n```bash\n# Create virtual host\nsudo virtualhost create example.dev\n\n# Create with custom directory\nsudo virtualhost create example.dev /var/www/mysite\n\n# Delete virtual host\nsudo virtualhost delete example.dev\n\n# List all hosts\nsudo virtualhost list\n\n# Get help\nsudo virtualhost --help\n```\n\n### Nginx\n```bash\n# Create virtual host\nsudo virtualhost-nginx create example.dev\n\n# Create with custom directory\nsudo virtualhost-nginx create example.dev /var/www/mysite\n\n# Delete virtual host\nsudo virtualhost-nginx delete example.dev\n\n# List all hosts\nsudo virtualhost-nginx list\n\n# Get help\nsudo virtualhost-nginx --help\n```\n\n---\n\n## 📖 Usage Guide\n\n### General Syntax\n```bash\nsudo virtualhost [OPTIONS] COMMAND DOMAIN [ROOTDIR]\nsudo virtualhost-nginx [OPTIONS] COMMAND DOMAIN [ROOTDIR]\n```\n\n### Commands\n\n#### Create Virtual Host\n```bash\nsudo virtualhost create example.dev\nsudo virtualhost create example.dev /var/www/custom_dir\n```\n\n**What it does:**\n- Creates web root directory with proper permissions\n- Generates Apache/Nginx configuration\n- Enables the site\n- Adds entry to /etc/hosts\n- Creates phpinfo.php test file\n- Reloads web server\n- Logs all operations\n\n#### Delete Virtual Host\n```bash\nsudo virtualhost delete example.dev\n```\n\n**What it does:**\n- Disables the site\n- Removes configuration\n- Removes /etc/hosts entry (with backup)\n- Prompts to delete web root\n- Reloads web server\n- Logs all operations\n\n#### List Virtual Hosts\n```bash\nsudo virtualhost list\nsudo virtualhost-nginx list\n```\n\nShows all enabled virtual hosts with their paths.\n\n#### Get Help\n```bash\nsudo virtualhost --help\nsudo virtualhost-nginx --help\n```\n\nShows comprehensive help and usage examples.\n\n#### Show Version\n```bash\nsudo virtualhost --version\nsudo virtualhost-nginx --version\n```\n\nDisplays script version information.\n\n### Options\n\n| Option | Description | Example |\n|--------|-------------|---------|\n| `-h, --help` | Show help message | `sudo virtualhost -h` |\n| `-V, --version` | Show version info | `sudo virtualhost --version` |\n| `-v, --verbose` | Enable verbose output | `sudo virtualhost -v create example.dev` |\n| `-d, --dry-run` | Preview without changes | `sudo virtualhost -d create example.dev` |\n| `-s, --skip-reload` | Skip web server reload | `sudo virtualhost -s create example.dev` |\n| `-e, --email` (Apache) | Set admin email | `sudo virtualhost -e admin@example.com create example.dev` |\n| `-p, --php-socket` (Nginx) | PHP-FPM socket | `sudo virtualhost-nginx -p unix:/run/php/php8.1-fpm.sock create example.dev` |\n\n---\n\n## 💡 Advanced Usage\n\n### Dry-Run Mode (Preview Changes)\nTest what would happen without making actual changes:\n```bash\nsudo virtualhost -d create example.dev\n```\n\nOutput shows all planned operations but doesn't modify anything.\n\n### Verbose Mode (Detailed Output)\nSee detailed step-by-step execution:\n```bash\nsudo virtualhost -v create example.dev\n```\n\nShows detailed logs of each operation.\n\n### Custom PHP Socket (Nginx)\nUse Unix socket instead of TCP:\n```bash\n# TCP socket (default)\nsudo virtualhost-nginx create example.dev\n\n# Unix socket\nsudo virtualhost-nginx -p unix:/run/php/php8.1-fpm.sock create example.dev\n```\n\n### Custom Admin Email (Apache)\nSet server admin email:\n```bash\nsudo virtualhost -e webmaster@company.com create example.dev\n```\n\n### Batch Operations\nCreate multiple hosts without reloading:\n```bash\nsudo virtualhost -s create site1.dev\nsudo virtualhost -s create site2.dev\nsudo virtualhost -s create site3.dev\nsudo systemctl reload apache2  # One reload at the end\n```\n\n---\n\n## 📊 Configuration\n\n### Default Paths\n```\nApache sites-available:  /etc/apache2/sites-available/\nApache sites-enabled:    /etc/apache2/sites-enabled/\nNginx sites-available:   /etc/nginx/sites-available/\nNginx sites-enabled:     /etc/nginx/sites-enabled/\nWeb root:                /var/www/\nLogs:                    /var/log/virtualhost/\n```\n\n### Logging\nAll operations are logged to: `/var/log/virtualhost/virtualhost-*.log`\n\nView logs:\n```bash\ntail -f /var/log/virtualhost/virtualhost-*.log\n```\n\n### Environment Variables\n```bash\n# Set custom log directory\nexport LOG_DIR=\"/custom/log/path\"\nsudo virtualhost create example.dev\n\n# Set custom admin email (Apache)\nexport EMAIL=\"admin@example.com\"\nsudo virtualhost create example.dev\n\n# Set custom PHP-FPM socket (Nginx)\nexport PHP_FPM_SOCKET=\"unix:/run/php/php8.1-fpm.sock\"\nsudo virtualhost-nginx create example.dev\n```\n\n---\n\n## 🔧 Configuration Details\n\n### Apache VirtualHost Template\nEach virtual host gets:\n- ServerAdmin email\n- ServerName and www alias\n- DocumentRoot configuration\n- mod_rewrite enabled for frameworks\n- Gzip compression\n- Error/Access logging\n- Security headers for hidden files\n\n### Nginx Server Block Template\nEach virtual host gets:\n- Server name configuration\n- PHP-FPM fastcgi configuration\n- Static file caching (30 days)\n- Security hardening\n- Per-domain logging\n- Framework-ready rewrites\n\n---\n\n## 📝 Examples\n\n### Simple Website\n```bash\nsudo virtualhost create mysite.dev\n# Creates: /var/www/mysite/\n# Visit: http://mysite.dev\n```\n\n### Custom Directory\n```bash\nsudo virtualhost create api.example.dev /var/www/projects/api\n# Creates: /var/www/projects/api/\n# Visit: http://api.example.dev\n```\n\n### Absolute Path\n```bash\nsudo virtualhost create data.example.dev /home/user/www/data\n# Creates: /home/user/www/data/\n# Visit: http://data.example.dev\n```\n\n### Development Environment\n```bash\n# Create multiple dev sites\nsudo virtualhost -s create project1.dev\nsudo virtualhost -s create project2.dev\nsudo virtualhost -s create project3.dev\nsudo systemctl reload apache2\n```\n\n### Testing Configuration\n```bash\n# Preview without making changes\nsudo virtualhost -d create example.dev\n\n# Dry-run with verbose output\nsudo virtualhost -dv create example.dev\n```\n\n---\n\n## 🐛 Troubleshooting\n\n### Issue: \"Run as root (use sudo)\"\n**Solution:** Always prefix commands with `sudo`\n```bash\nsudo virtualhost create example.dev\n```\n\n### Issue: \"Domain does not exist: example.dev\"\n**Solution:** Double-check the domain name or create it first\n```bash\nsudo virtualhost create example.dev  # Create first\nsudo virtualhost delete example.dev  # Then delete\n```\n\n### Issue: \"Configuration test failed\"\n**Solution:** Check web server configuration syntax\n```bash\n# Apache\napache2ctl configtest\n\n# Nginx\nnginx -t\n```\n\n### Issue: Cannot access virtual host in browser\n**Solution:** Verify /etc/hosts entry\n```bash\ngrep example.dev /etc/hosts\n# Should see: 127.0.0.1    example.dev\n```\n\n### Issue: Permission denied on web root\n**Solution:** Check directory ownership\n```bash\nls -la /var/www/example/\n# Should be owned by your user or www-data\n```\n\n### Issue: PHP not working\n**Solution:** Check PHP-FPM is running and properly configured\n```bash\n# Nginx\nsudo systemctl status php-fpm\n# or\nsudo systemctl status php8.1-fpm\n\n# Apache\napache2ctl -t  # Test configuration\n```\n\n### Issue: Port 80 already in use\n**Solution:** Check what's using port 80\n```bash\nsudo lsof -i :80\n# Kill the process or use different port\n```\n\n---\n\n## 📚 Logs and Debugging\n\n### View Logs\n```bash\n# View today's logs\ntail -f /var/log/virtualhost/virtualhost-apache-*.log\ntail -f /var/log/virtualhost/virtualhost-nginx-*.log\n\n# View all logs\nls -la /var/log/virtualhost/\n```\n\n### Check Web Server Logs\n```bash\n# Apache\ntail -f /var/log/apache2/example.dev_error.log\ntail -f /var/log/apache2/example.dev_access.log\n\n# Nginx\ntail -f /var/log/nginx/example.dev_error.log\ntail -f /var/log/nginx/example.dev_access.log\n```\n\n---\n\n## ✅ Verification\n\n### Test Virtual Host Creation\n```bash\n# Create\nsudo virtualhost create testsite.dev\n\n# Verify /etc/hosts entry\ngrep testsite.dev /etc/hosts\n\n# Verify site enabled\nls -l /etc/apache2/sites-enabled/ | grep testsite\n\n# Verify directory\nls -la /var/www/testsite/\n\n# Check in browser\ncurl http://testsite.dev\n\n# View logs\ntail -f /var/log/virtualhost/*.log\n```\n\n---\n\n## 🔒 Security Notes\n\n- Scripts require sudo (root privileges)\n- Domain validation prevents invalid characters\n- Permissions set to 755 for directories, 644 for files\n- Backups created for /etc/hosts modifications\n- Hidden files denied access in Apache/Nginx\n- Proper user/group ownership enforced\n- No SQL injection or command injection possible\n\n---\n\n## 🤝 Contributing\n\nFound a bug? Have a feature request? Contributions welcome!\n\n1. Fork the repository\n2. Create a feature branch (`git checkout -b feature/amazing-feature`)\n3. Commit changes (`git commit -m 'Add amazing feature'`)\n4. Push to branch (`git push origin feature/amazing-feature`)\n5. Open a Pull Request\n\n---\n\n## 📜 License\n\nThis project is licensed under the MIT License - see the LICENSE file for details.\n\n---\n\n## 📞 Support\n\nFor issues, questions, or suggestions:\n- Open an [GitHub Issue](https://github.com/shuvo-halder/virtualhost-automation/issues)\n- Check [Troubleshooting Section](#-troubleshooting)\n- Review [Examples](#-examples)\n\n---\n\n## 🚀 Changelog\n\n### Version 2.0.0 (2026-05-05)\n- ✨ Added comprehensive help system (`--help`, `--version`)\n- ✨ Added dry-run mode (`-d`) for safe testing\n- ✨ Added verbose logging (`-v`) for debugging\n- ✨ Added centralized logging system\n- ✨ Added domain validation and error handling\n- ✨ Added list command to show all virtual hosts\n- ✨ Added skip-reload option for batch operations\n- ✨ Added custom PHP-FPM socket support (Nginx)\n- ✨ Added custom admin email support (Apache)\n- 📚 Complete documentation overhaul\n- 🔒 Enhanced security features\n- ⚡ Performance improvements\n\n### Version 1.0.0 (2023-09-21)\n- Initial release\n- Basic create/delete functionality\n- Apache and Nginx support\n\n---\n\n## 👨‍💻 Author\n\n**Shuvo Halder** - [GitHub](https://github.com/shuvo-halder)\n\n---\n\n## 📎 Related Projects\n\n- [Apache Virtual Host Docs](https://httpd.apache.org/docs/2.4/vhosts/)\n- [Nginx Server Blocks](https://nginx.org/en/docs/http/server_names.html)\n- [PHP-FPM Setup](https://www.php.net/manual/en/install.fpm.php)\n\n---\n\n**Made with ❤️ for Linux Developers \u0026 System Administrators**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshuvo-halder%2Fvirtualhost-automation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshuvo-halder%2Fvirtualhost-automation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshuvo-halder%2Fvirtualhost-automation/lists"}