Ich bin sicher, dass diese Frage oft gestellt wird, aber ich habe kein Problem. Ich verwende XAMPP, wo ich das Zend-Framework konfiguriere.
XAMPP läuft auf Port 8081 as 80 wird von einem Windows-Prozess belegt, den ich für den virtuellen Host verwenden muss, den ich mit folgendem Code in C:/xampp/Apache/config/extra/httpd-vhosts.config
(oder C:/xampp/Apache/conf/extra/httpd-vhosts.conf
in neueren Releases) konfiguriere.
<VirtualHost *:80>
ServerName comm-app.local
DocumentRoot "C:/xampp/htdocs/CommunicationApp/public"
SetEnv APPLICATION_ENV "development"
<Directory "C:/xampp/htdocs/CommunicationApp/public"
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
und aktualisieren Sie auch die hosts-Datei mit 127.0.0.1 comm-app.local
und versuchen Sie, Apache neu zu starten, es wird jedoch ein Fehler angezeigt.
15:03:01 [Apache] Error: Apache shutdown unexpectedly.
15:03:01 [Apache] This may be due to a blocked port, missing dependencies,
15:03:01 [Apache] improper privileges, a crash, or a shutdown by another method.
15:03:01 [Apache] Press the Logs button to view error logs and check
15:03:01 [Apache] the Windows Event Viewer for more clues
15:03:01 [Apache] If you need more help, copy and post this
15:03:01 [Apache] entire log window on the forums
Ich sehe zwei Fehler:
<VirtualHost *:80> -> Fix to :8081, your POrt the server runs on
ServerName comm-app.local
DocumentRoot "C:/xampp/htdocs/CommunicationApp/public"
SetEnv APPLICATION_ENV "development"
<Directory "C:/xampp/htdocs/CommunicationApp/public" -> This is probably why it crashes, missing >
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
-> MIssing close container: </VirtualHost>
Feste Version:
<VirtualHost *:8081>
ServerName comm-app.local
DocumentRoot "C:/xampp/htdocs/CommunicationApp/public"
SetEnv APPLICATION_ENV "development"
<Directory "C:/xampp/htdocs/CommunicationApp/public">
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Eine Sache zu erwähnen:
Sie können den Befehl immer versuchen und ausführen:
service Apache2 configtest
Dies sagt Ihnen, wann Sie eine fehlerhafte Konfiguration erhalten haben, und kann Ihnen vielleicht sogar sagen, wo das Problem liegt.
Darüber hinaus hilft es, die Nichtverfügbarkeit in einem LIVE-System zu vermeiden:
service Apache2 restart
wird heruntergefahren und dann nicht mehr gestartet, das ist alles, was Sie vorher wissen, "Ich habe etwas falsch gemacht, ich sollte das zuerst beheben", aber der Apache selbst läuft noch mit der alten Konfiguration. :)
Schritt 1) C:\WINDOWS\system32\drivers\etc\ Öffnen Sie die Datei "hosts":
127.0.0.1 localhost
127.0.0.1 test.com
127.0.0.1 example.com
Schritt 2) xampp\Apache\conf\extra\httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot C:/xampp/htdocs/test/
ServerName www.test.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot C:/xampp/htdocs/example/
ServerName www.example.com
</VirtualHost>
Schritt 3) C:\xampp\Apache\conf\httpd.conf. Scrollen Sie am Ende zum Abschnitt Supplemental configuration (Ergänzende Konfiguration) und suchen Sie den folgenden Abschnitt (um die Zeile 500). Entfernen Sie das # vom Anfang der zweiten Zeile, sodass der Abschnitt jetzt so aussieht:
#Virtual hosts
Include conf/extra/httpd-vhosts.conf
Schritt 4) Starten Sie XAMPP Neu und starten Sie es in Ihrem Browser:
www.example.com or www.test.com
Schreiben Sie diese Codes am Ende der Datei C:\xampp\Apache\conf\extra\httpd-vhosts.conf.
DocumentRoot "D:/xampp/htdocs/foldername"
ServerName www.siteurl.com
ServerAlias www.siteurl.com
ErrorLog "logs/dummy-Host.example.com-error.log"
CustomLog "logs/dummy-Host.example.com-access.log" common
zwischen dem virtuellen Host-Tag.
und bearbeiten Sie die Datei. System32/Drivers/etc/hosts verwenden Notepad als Administrator
füge den unteren Teil der Datei hinzu
127.0.0.1 www.siteurl.com
Diesen Code in C:\xampp\Apache\conf\extra\httpd-vhosts.conf hinzufügen
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs"
ServerName qa-staging.com
ServerAlias www.qa-staging.com
<Directory "c:/xampp/htdocs">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Füge jetzt deinen virtuellen Hostnamen in der folgenden Datei hinzu.
C:\Windows\System32\drivers\etc\hosts
127.0.0.1 qa-staging.com
Wenn Sie diesen Code nicht in der Host-Datei speichern können, klicken Sie mit der rechten Maustaste auf notpad. Wählen Sie Als Administrator ausführen aus. Dann können Sie Ihren benutzerdefinierten Code jetzt speichern. Starten Sie Ihr XAMP
Ändern Sie einfach den Port in 8081
und der folgende virtuelle Host funktioniert:
<VirtualHost *:8081>
ServerName comm-app.local
DocumentRoot "C:/xampp/htdocs/CommunicationApp/public"
SetEnv APPLICATION_ENV "development"
<Directory "C:/xampp/htdocs/CommunicationApp/public">
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "D:/projects/yourdirectry name"
ServerName local.yourdomain.com
<Directory "D:/projects/yourdirectry name">
Require all granted
</Directory>
</VirtualHost>
Speichern Sie die Apache-Konfigurationsdatei.
für detaillierte Informationen siehe this
Apache Virtual Host Dokumentation Das Einrichten eines virtuellen Hosts (vhost) bietet mehrere Vorteile:
VirtualHost-Direktive Enthält Direktiven, die nur für einen bestimmten Hostnamen oder eine bestimmte IP-Adresse gelten
Location Directive Wendet die beigefügten Anweisungen nur auf übereinstimmende URLs an
Beispiel ändert Konfigurationsdatei - D:\xampp\Apache\conf\extra\httpd-vhosts.conf
<VirtualHost *:80>
ServerAdmin localhost
DocumentRoot "D:/xampp/htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost localhost:80>
ServerAdmin [email protected]
DocumentRoot "/www/docs/Host.example.com"
#DocumentRoot "D:\xampp\htdocs\phpPages"
ServerName Host.example.com
ErrorLog "logs/Host.example.com-error_log"
TransferLog "logs/Host.example.com-access_log"
</VirtualHost>
# To get view of PHP application in the Browser.
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "D:\xampp\htdocs\app1"
ServerName app1.yash.com
ServerAlias app1.yash.com
ErrorLog "logs/app1.yash.com-error.log"
CustomLog "logs/app1.yash.com-access.log" combined
# App1 communication proxy call to Java War applications from XAMP
<Location /ServletApp1>
ProxyPass http://app1.yashJava.com:8080/ServletApp1
ProxyPassReverse http://app1.yashJava.com:8080/ServletApp1
Order Allow,Deny
Allow from all
</Location>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "D:\xampp\htdocs\app2"
ServerName app2.yash.com
ErrorLog "logs/app2.yash.com-error.log"
CustomLog "logs/app2.yash.com-access.log" combined
# App1 communication proxy call to Java War applications from XAMP
<Location /ServletApp2>
ProxyPass http://app1.yashJava.com:8080/ServletApp2
ProxyPassReverse http://app1.yashJava.com:8080/ServletApp2
Order Allow,Deny
Allow from all
</Location>
</VirtualHost>
Aktualisieren Sie Ihre Windows-Hosts-Datei "Öffnen Sie Ihre Windows-Hosts-Datei in C:\Windows\System32\drivers\etc\hosts.
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.1 test.com
127.0.0.1 example.com
127.0.0.1 myssl.yash.com
D:\xampp\Apache\conf\httpd.conf, [httpd-ssl.conf](http://httpd.Apache.org/docs/2.2/mod/mod_ssl.html)
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost> directive.
# Listen 0.0.0.0:80 | [::]:80
Listen 80
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule speling_module modules/mod_speling.so
# ServerAdmin: Your address, where problems with the server should be e-mailed.
# This address appears on some server-generated pages, such as error documents.
# e.g. [email protected]
ServerAdmin [email protected]
ServerName localhost:80
DocumentRoot "D:/xampp/htdocs"
<Directory "D:/xampp/htdocs">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
# Virtual hosts
Include "conf/extra/httpd-vhosts.conf"
# ===== httpd-ssl.conf - SSL Virtual Host Context =====
# Note: Configurations that use IPv6 but not IPv4-mapped addresses need two
# Listen directives: "Listen [::]:443" and "Listen 0.0.0.0:443"
Listen 443
## SSL Virtual Host Context
<VirtualHost _default_:443>
DocumentRoot "D:\xampp\htdocs\projectFolderSSL"
ServerName myssl.yash.com:443
ServerAlias myssl.yash.com:443
ServerAdmin [email protected]
ErrorLog "logs/error.log"
<IfModule log_config_module>
CustomLog "logs/access.log" combined
</IfModule>
## Redirecting URL from Web server to Application server over different machine.
# myssl.yash.com:443/ServletWebApp
<Location /path>
ProxyPass http://Java.yash2.com:8444/ServletWebApp
ProxyPassReverse http://Java.yash2.com:8444/ServletWebApp
Order Allow,Deny
Allow from all
</Location>
#SSLCertificateFile "conf/ssl.crt/server.crt"
SSLCertificateFile "D:\SSL_Vendor\yash.crt"
#SSLCertificateKeyFile "conf/ssl.key/server.key"
SSLCertificateKeyFile "D:\SSL_Vendor\private-key.key"
#SSLCertificateChainFile "conf/ssl.crt/server-ca.crt"
SSLCertificateChainFile "D:\SSL_Vendor\intermediate.crt"
</VirtualHost>
# ===== httpd-ssl.conf - SSL Virtual Host Context =====
@sehen
In Ihrem Laufwerk:\xampp\Apache\conf\extra\httpd-vhosts.conf gibt es ein Beispiel, das Sie mit Ihrer Konfiguration bearbeiten können:
##<VirtualHost *:80>
##ServerAdmin [email protected]
##DocumentRoot "C:/xampp/htdocs/dummy-Host.example.com"
##ServerName dummy-Host.example.com
##ServerAlias www.dummy-Host.example.com
##ErrorLog "logs/dummy-Host.example.com-error.log"
##CustomLog "logs/dummy-Host.example.com-access.log" common
##</VirtualHost>
Es wäre so, als Beispiel und nicht vergessen, VirtualHost für localhost selbst hinzuzufügen, um die Möglichkeit zu haben, phpmyadmin und ein anderes Projekt gleichzeitig auf dem Port 80 auszuführen, als Beispiel werde ich mit store.local project :
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "c:/xampp/htdocs/store.local/public"
ServerName www.store.local
ServerAlias store.local
<Directory C:/xampp/htdocs/store.local>
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
dann müssen Sie wie oben erwähnt Folgendes hinzufügen: C:\windows\system32\drivers\hosts am Ende der Datei
127.0.0.1 store.local
127.0.0.1 www.store.local
starten Sie Apache neu und versuchen Sie es im Browser:
store.local or www.store.local
vielleicht müssen Sie beim ersten Mal folgendes hinzufügen:
http://store.local or http://www.store.local
um andere Ports zu verwenden, müssen Sie vor Ihrem VirtualHost Folgendes hinzufügen:
Listen 8081 or another which you prefer
verwenden Sie dann einfach den Port für Ihren VirtualHost:
<VirtualHost *:8081>
ServerAdmin [email protected]
DocumentRoot "c:/xampp/htdocs/store.local/public"
ServerName store.local
ServerAlias www.store.local
<Directory C:/xampp/htdocs/store.local>
AllowOverride All
Require all granted
</Directory>
starten Sie dann Apache neu und versuchen Sie es im Browser
store.local:8081 or www.store.local:8081
und nur Projekte, für die Sie den Port hinzufügen, werden auf diesem Port ausgeführt, z. B. andere Projekte und phpmyadmin werden noch auf Port 80 ausgeführt
Ich habe es mit folgender Konfiguration behoben.
Listen 85
<VirtualHost *:85>
DocumentRoot "C:/xampp/htdocs/LaraBlog/public"
<Directory "C:/xampp/htdocs/CommunicationApp/public">
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Ich bin ein bisschen spät zur Party, aber ich habe dieses kleine Bash-Skript für Mac geschrieben, das einen VirtualHost über das Terminal erstellt:
#!/bin/bash
echo "Welcome to the VirtualHostCreator! Press <RETURN> to continue."
read
echo "Enter the name the VirtualHost you would like to create. No spaces or dashes, please."
read hostname
echo "Enter the document root of the VirtualHost."
read doc_root
echo "Creating VirtualHost \"$hostname\". You may be prompted for your password."
hosts_file="/etc/hosts"
vhosts_file="/Applications/XAMPP/xamppfiles/etc/extra/httpd-vhosts.conf"
restart_command="Sudo /Applications/XAMPP/xamppfiles/xampp restart"
cat >> $vhosts_file << EndOfMessage
<VirtualHost ${hostname}>
ServerName ${hostname}
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/${doc_root}"
</VirtualHost>
EndOfMessage
Sudo sh -c "echo \"127.0.0.1 $hostname\" >> $hosts_file"
$restart_command
Ich bin sicher, dass es einige Verbesserungen gibt, die vorgenommen werden können, und es gibt nur die zwei erforderlichen Optionen für den vhost (Servername und Dokumentstammverzeichnis). Dies erledigt den Job jedoch viel schneller und effizienter als das Öffnen und Bearbeiten aller Dateien manuell und startet XAMPP anschließend automatisch neu.
Dies setzt voraus, dass Sie den Standardinstallationspfad für XAMPP haben, der alle geändert werden kann.
Das Problem mit xampp besteht in meinem Fall darin, dass ein anderer Ordner als htdocs angegeben wird, insbesondere bei mehreren Domänen und dedizierten Ordnern. Dies liegt daran, dass httpd-ssl.conf
auch auf <VirtualHost>
verweist.
Entfernen Sie dazu den gesamten Eintrag <VirtualHost>
unter httpd-ssl.conf
Von dort aus werden alle Einstellungen, die Sie in Ihrem httpd-vhosts.conf
vornehmen, erwartungsgemäß sowohl als http
- als auch als https
-Referenz aktualisiert.
Wenn Sie eine einfache Installation benötigen
https://github.com/scyzho/xampp
laden Sie sie in Ihren htdocs-Ordner herunter
und geben Sie Ihren Host ein
Schritt 1) Öffnen Sie die Hostdatei unter "C:\Windows\System32\drivers\etc".
Hinzufügen
127.0.0.1 vipsnum.mk
Schritt 2) Öffnen Sie die httpd-vhosts.conf-Datei unter "C:\xampp\Apache\conf\extra".
Hinzufügen
<VirtualHost vipsnum.mk:80>
ServerName vipsnum.mk
DocumentRoot "C:/xampp/htdocs/vipnum/"
SetEnv APPLICATION_ENV "development"
<Directory "C:/xampp/htdocs/vipnum/">
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
1. C:\xampp\Apache\conf\https.conf
Virtual hosts
Include conf/extra/httpd-vhosts.conf
2. C:\Windows\System32\drivers\etc\hosts
127.0.0.1 localhost
127.0.0.1 helpdesk.local
3. C:\xampp\Apache\conf\extra\httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/helpdesk/public"
ServerName helpdesk.local
</VirtualHost>
Now, Restart Apache and go through the link.
URL : http://helpdesk.local