I've installed XAMPP on Ubuntu in '/opt/lampp' directory and would like to set up some VirtualHosts. Apache Virtual Host tutorial instructs to place
<VirtualHost *:80>
...
</VirtualHost>
code in '/etc/apache2/sites-available/[virtualhostname].conf'. The problem is that I don't have 'apache2' folder in '/etc'. I also don't have 'sites-available' directory in '/opt/lampp/apache2'.
I have '/opt/lampp/etc/httpd.conf' and '/opt/lampp/etc/extra/httpd-vhosts.conf' files though. Which ones shall I use to set the VH up?
You should use /opt/lampp/etc/extra/httpd-vhosts.conf, but before you should add your servername to your .hosts file and uncomment inclusion of of the httpd-vhosts.conf in the /opt/lampp/etc/httpd.conf.
Related
I'm trying to set up a local development environment for a PHP project. The project is placed in the htdocs folder, and i wanna be able to access it on a virtual host environment so all the links and so on works, and treats it as the root directory.
So, here is what i have done:
C:\Windows\System32\drivers\etc
hosts
127.0.0.1 bakeboss.test
C:\xampp\apache\conf\extra
httpd-vhosts
<VirtualHost *:80>
DocumentRoot "C:\xampp\htdocs\bakeboss"
ServerName bakeboss.test
<Directory "C:\xampp\htdocs\bakeboss">
</Directory>
</VirtualHost>
Apache starts up fine, but if i try to go to (in my browser):
www.bakeboss.test
NOTHING happens - cannot find it, cannot connect. If i go to localhost/bakeboss it works, but obviously not the way i want it.
What am i missing here?
I have a server with multiple websites hosted and distinguishable using name-based virtual hosting of apache.
How do I set it so that a specific website is hosted when the ip of my server is entered in the address bar?
What you want to use is the _default_ VirtualHost.
<VirtualHost _default_:80>
DocumentRoot /www/default80
# ...
</VirtualHost>
It's described here. Basically if nothing else match the request the _default_ host will be used.
EDIT
This could also be written as:
<VirtualHost *>
DocumentRoot /www/default
# ...
</VirtualHost>
Is is important that this is the first VirtualHost in the configuration since Apache will start matching them from top to bottom, selecting the one that fit the best based on ServerName and ServerAlias.
This post might also be of interest:
Apache default VirtualHost
just find the Include sites-enabled/ line in your apache2.conf file and add the path to the conf file you want to be site default above it. from:
Include sites-enabled/
to
Include sites-enabled/mydefault.conf
Include sites-enabled/
When you first install apache2, there is a site configuration file named 000-default.conf. This is going to be the default because it is very likely to appear first in the list of files under /etc/apache2/sites-enabled.
To have your own file as the default, you can either replace the file under /etc/apache2/sites-available/000-default.conf with your own, or replace the link like so:
sudo rm /etc/apache2/sites-enabled/000-default.conf
sudo ln -s ../sites-available/my-site-setup.conf /etc/apache2/sites-enabled/000-default.conf
Then restart apache2 (or just reload).
The _default_ as mentioned by the other answer is for defining a virtual host which can be found with the default IP address. It's not the default virtual host.
<VirtualHost _default_:80>
...
is equivalent to
<VirtualHost *:80>
...
The * is a globing pattern which matches any IP addresses.
Note:
Replacing the 000-default.conf file is okay, but in most cases the installation package is going to view that as a modified file and manage it in some weird way which is why I think it's cleaner to only change the soft link.
Keep it clean, don't delete or edit anything in /etc/apache2/sites-available/.
Create all new site configurations in /etc/apache2/sites-available/. Copy whatever site configuration you want enabled to /etc/apache2/sites-enabled/. Only make sure /etc/apache2/sites-enabled/ has only one configuration file.
Sample format for new apache site configurations in Ubuntu 20.04 LTS is
<VirtualHost *:80>
ServerName http://localhost
ServerAdmin admin#mysite.com
DocumentRoot /var/www/html/mysiteroot/public
<Directory /var/www/html/mysiteroot>
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Notice that 000-default.conf is by default in both directories mentioned above and should only be replaced by your new configuration in /etc/apache2/sites-enabled/ so that it can be restored anytime you need it.
Restart Apache2 service after you make any configuration changes.
I have Zend Server installed on my machine (windows 7 home edition) and I´m trying to set up a virtual host on a folder that is located in our server. For some reasons, I can't set an apache web server in there, so it must be done in my own computer.
But I can't get it done. My virtual host setup in httpd-vhosts.conf is like this:
<VirtualHost *:8081>
ServerAdmin web#web.com.br
DocumentRoot "\Data\Websites\Online\TheClientName\Site"
ServerName clientname.local
ServerAlias clientname.local
ErrorLog "logs/clientname.log"
</VirtualHost>
And the hosts file:
172.17.10.1/Data/Websites/Online/TheClientName/Site clientname.local
I have checked the Apache log. There's a Warning:
Warning: DocumentRoot [C:/Data/Websites/Online/TheClientName/Site] does not exist
I got full access to this folder, and I have it mapped like a local drive. I tried to set the DocumentRoot as follows, but no luck; Apache does not restarts after setting the 'Z:\'.
"Z:\Data\Websites\Online\TheClientName\Site"
I wonder if there is a way to point this v-host to server folder. Any ideas?
I'm following Zend beginner tutorial. In that actually following need to be setup in the local server Apache httpd.conf in Linux PC.
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "/usr/local/apache/htdocs/square/public"
ServerName square.localhost
</VirtualHost>
But I've a Windows 7 installed with Xampp in my local. Could anyone please help me on this how to put this in my local httpd.conf file.
Change DocumentRoot "/usr/local/apache/htdocs/square/public" to a public folder of your project. For example, to "C:\XAMPP\www\square\public" or wherever your project's public folder is located.
Also make sure you have this line in your hosts file : 127.0.0.1 localhost
I am using Apache Friends XAMPP in Windows (Local Server). I setup the virtual host in httpd-vhosts.conf in an Apache configuration directory like this
NameVirtualHost *:80
<VirtualHost *:80>
ServerName test.example.com
DocumentRoot "E:\xampp\htdocs\example"
</VirtualHost>
This works fine when I browse the URL
http://test.example.com
Is it possible to create virtual host from Apache .htaccess dynamically?
The context for VirtualHost has to be server config. See the Apache docs.
This means that the directive may be
used in the server configuration files
(e.g., httpd.conf), but not within any
or
containers. It is not allowed in
.htaccess files at all.
(Directive Dictionary)
It seems to be impossible. Because your .htaccess is used only after your host is resolved by root configuration files of a server like httpd.conf, apache2.conf.
To put simply, .htaccess in the www directory or in its subdirectories will only be processed after root configuration files are processed.
I mean you type http://host.name and apache finds the destination and uses .htaccess file on the host to perform some operations if needed.