Apache conf setup to serve subdomain site alongside OwnCloud deploy - apache

I have deployed OwnCloud 8 on a Ubuntu 14.04 instance to the domain box.example.com. I would like to host some static html on the same VM and have apache point project.example.com to it at /var/www/html.
In apache the file /etc/apache2/conf-available/owncloud.conf was created by OwnCloud containing:
#I changed the first line as follows
##Alias /owncloud "/var/www/owncloud/" # commented out
Alias / "/var/www/owncloud/"
<Directory "/var/www/owncloud">
Options +FollowSymLinks
AllowOverride All
<IfModule mod_dav.c>
Dav off
</IfModule>
SetEnv HOME /var/www/owncloud
SetEnv HTTP_HOME /var/www/owncloud
</Directory>
How can I add a new subdomain VM in apache so that I'll have two working sites: box.example.com (OwnCloud instance) and project.example.com (static html). So far with everything I have tried project loads the OwnCloud front-end and does not open the static html.
Do I need to touch /etc/hosts?
I will update with examples of things I am trying and outcomes.

You can add both virtualhost in the same file (after the first ) directive or create another file in /etc/apache2/sites-available/ . You can start from the existing default file and adapt the servername and directory where your "project" is, and any other directive as needed.
Beware, if you run Apache2.4, the files should be named anyname.conf, for instance box.example.com.conf
And don't forgot to reload your apache server after having enabled the site.
You also need to set-up your DNS, in a zone file, for both box.example.com and project.example.com to point to the IP of your server.

You could create virtual host config files like /etc/apache/sites-available/01-owncloud.
<VirtualHost *:80>
ServerName box.example.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/owncloud
<Directory /var/www/owncloud/>
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/owncloud-error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/owncloud-access.log combined
Redirect 301 /.well-known/carddav /remote.php/carddav
Redirect 301 /.well-known/caldav /remote.php/caldav
</VirtualHost>
Then enable it with a2ensite 01-owncloud.
Don't forget to set NameVirtualHost *:80 somewhere in a conf. I used /etc/apache2/ports.conf.

Related

XAMPP Virtual Hosts not working

Before marking this as answered, please read the entire thing because yes there is a good amount of these questions but NONE of the answers on them have worked at all.
For the last 6 months I've looked at around 50 different form posts here and around the web to try and get my XAMPP virtual hosts working.
Hosts File
127.0.0.1 localhost
127.0.0.1 vws.localhost
127.0.0.1 instancegaming.net
127.0.0.1 vws.instancegaming.net
http-vhosts File (Updated 7/26)
# Virtual Hosts
#
# Required modules: mod_log_config
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.4/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
#
# Use name-based virtual hosting.
#
# NameVirtualHost *:80
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ##ServerName or ##ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
ServerName localhost
DocumentRoot "C:\xampp\htdocs"
<Directory "C:\xampp\htdocs">
DirectoryIndex index.php
</Directory>
</VirtualHost>
I'm at a loss of what to do, I've tried putting all fields to localhost then to instancegaming.net but nothing seems to work. I've read the Apache log and there's only SSL errors floating around.
When I try going to [ http:// ] vws.localhost, vws.192.168.0.47, vws.instancegaming.net all of which give the same error in chrome:
ERR_NAME_NOT_RESOLVED
Then I tried emptying chromes host cache, but that didn't help either.
Sidenote: I reinstalled XAMPP 4 times trying to make this work.
Follow these steps if you are in windows environment (7 & 10 tested) with XAMPP:
Add in hosts file [C:\Windows\System32\drivers\etc]
127.0.0.1 vws.localhost
127.0.0.1 instancegaming.net
127.0.0.1 vws.instancegaming.net
Add this in httpd.conf [C:\__Server\apache\conf] . though some says there are security risks with this but couldn't find a way without this
<Directory />
AllowOverride none
Require all granted
</Directory>
Add these in httpd-vhosts.conf [C:\__Server\apache\conf\extra]
<VirtualHost *:80>
ServerName localhost
DocumentRoot "C:\__Server\htdocs"
<Directory "C:\__Server\htdocs">
DirectoryIndex index.php
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName tools.com.at
DocumentRoot "E:\phpStorms\git\tools-class"
SetEnv APPLICATION_ENV "development"
<Directory "E:\phpStorms\git\tools-class">
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName laravel.test.com.at
DocumentRoot "E:\laravel.test.com.at\public"
SetEnv APPLICATION_ENV "development"
<Directory "E:\laravel.test.com.at\public">
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
template of this
<VirtualHost *:80>
ServerName nameInHostsFile
DocumentRoot "pathOfTheWindowsFileLocationWhichWillBeDocumentRoot"
SetEnv APPLICATION_ENV "development"
<Directory "pathOfTheWindowsFileLocationWhichWillBeDocumentRoot">
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Note 1: My xampp installed on C:\__Server location
Note 2 : My folder name is laravel.test.com.at and its in E: drive E:\laravel.test.com.at
Note 3: Always copy folder location from address bar in windows explorer, so there is no mistakes.
Note 4: You must restart XAMPP after editing httpd-vhosts.conf every time.
Note 5: Use uncommon part in url [i.e .com.at] so that it is unique and there is no issue resolving dns.
Update: troubleshoot#Jacob Jewett
After a fresh copy of XAMPP installation in C drive -
just add/append these line in httpd-vhosts.conf file
<VirtualHost *:80>
ServerName localhost
DocumentRoot "C:\xampp\htdocs"
<Directory "C:\xampp\htdocs">
DirectoryIndex index.php
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName vws.localhost
DocumentRoot "C:\xampp\vws"
SetEnv APPLICATION_ENV "development"
<Directory "C:\xampp\vws">
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Add append this in httpd.conf file
<Directory />
AllowOverride none
Require all granted
</Directory>
ADD PATH variable for php [C:\xampp\php], and also check that there isn't another php path in the PATH variable.
restart xampp and browse localhost
Additionally make sure that the line
Include etc/extra/httpd-vhosts.conf
is not quoted out in httpd.conf
The answer I found that works is to to this in the hosts file.
192.168.0.47 localhost somthing.instancegaming.net
One thing I'd like to add here: For anyone who is sure everything is setup correctly, make sure you don't use any underscores in the alias string within your hosts file; for some reason it can't accept underscores.
I have similar issue, vhosts not working. But in my case I found there was the permission issue with host file. Hope this helps for some one. hosts file ignored, how to troubleshoot?
If pings are successful but a Virtual Host is not working with XAMPP 7.3.1 and Windows 10 Pro the problem may be interference with the World Wide Web Publishing Service.
On my system, Apache and MySQL start successfully but the virtual host cannot be browsed till I stop the WWWPS service (in Windows Services). The virtual host then becomes instantly available. It instantly stops working when the WWWPS is started again.
I fixed the problem by just restarting my computer after setting up the System32 file hosts and the apache vhosts.

Apache VirtualHost and localhost

I'm working with XAMPP on Mac OS X.
I'm trying to run a Symfony website properly for a client, and I really don't know Symfony (yet). I just want to install and launch it.
I've changed my /etc/hosts file this way:
127.0.0.1 www.mysite.local
And the httpd.conf file this way:
<VirtualHost *:80>
ServerName www.mysite.local
DocumentRoot /Applications/MAMP/htdocs/mysite/web
DirectoryIndex index.php
<Directory /Applications/MAMP/htdocs/mysite/web>
AllowOverride All
Allow from All
</Directory>
Alias /sf /Applications/MAMP/htdocs/mysite/lib/vendor/symfony/data/web/sf
<Directory "/Applications/MAMP/htdocs/mysite/lib/vendor/symfony/data/web/sf">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
Now, the site is working (yay!), but I can't access any more any of my other local sites because localhost is rendered as www.mysite.local.
Where am I wrong?
This worked for me!
To run projects like http://localhost/projectName:
<VirtualHost localhost:80>
ServerAdmin localhost
DocumentRoot path/to/htdocs/
ServerName localhost
</VirtualHost>
To run projects like http://somewebsite.com locally:
<VirtualHost somewebsite.com:80>
ServerAdmin webmaster#example.com
DocumentRoot /path/to/htdocs/somewebsiteFolder
ServerName www.somewebsite.com
ServerAlias somewebsite.com
</VirtualHost>
The same for other websites:
<VirtualHost anothersite.local:80>
ServerAdmin webmaster#example.com
DocumentRoot /path/to/htdocs/anotherSiteFolder
ServerName www.anothersite.local
ServerAlias anothersite.com
</VirtualHost>
localhost will always redirect to 127.0.0.1. You can trick this by naming your other VirtualHost to other local loop-back address, such as 127.0.0.2. Make sure you also change the corresponding hosts file to implement this.
For example, my httpd-vhosts.conf looks like this:
<VirtualHost 127.0.0.2:80>
DocumentRoot "D:/6. App Data/XAMPP Shared/htdocs/intranet"
ServerName intranet.dev
ServerAlias www.intranet.dev
ErrorLog "logs/intranet.dev-error.log"
CustomLog "logs/intranet.dec-access.log" combined
<Directory "D:/6. App Data/XAMPP Shared/htdocs/intranet">
Options Indexes FollowSymLinks ExecCGI Includes
Order allow,deny
Allow from all
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
(Notice that in <VirtualHost> section I typed 127.0.0.2:80. It means that this block of VirtualHost will only affects requests to IP address 127.0.0.2 port 80, which is the default port for HTTP.
To route the name intranet.dev properly, my hosts entry line is like this:
127.0.0.2 intranet.dev
This way, it will prevent you from creating another VirtualHost block for localhost, which is unnecessary.
This is normal if you see it. Since it is the first virtual host entry, it will show local host.
Let’s say for example you didn't want that page to show. All you want to show is the "Apache, it works" page, so you would make a vhost entry before mysite.local as local host and point it to the "it works" page.
But this is normal. I had this problem before, so don't worry!
You may want to use this:
<VirtualHost *:80>
DocumentRoot "somepath\Apache2.2\htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
as your first virtual host (place it before other virtual hosts).
I had the same issue of accessing localhost while working with virtualHost. I resolved it by adding the name in the virtualHost listen code like below:
In my hosts file, I have added the below code (C:\Windows\System32\drivers\etc\hosts) -
127.0.0.1 main_live
And in my httpd.conf I have added the below code:
<VirtualHost main_live:80>
DocumentRoot H:/wamp/www/raj/main_live/
ServerName main_live
</VirtualHost>
That's it. It works, and I can use both localhost, phpmyadmin, as well as main_live (my virtual project) simultaneously.
Additional description for John Smith's answer from the official documentation. To understand why it is.
Main host goes away
If you are adding virtual hosts to an existing web server, you must
also create a block for the existing host. The
ServerName and DocumentRoot included in this virtual host should be
the same as the global ServerName and DocumentRoot. List this virtual
host first in the configuration file so that it will act as the
default host.
For example, to work properly with XAMPP, to prevent VirtualHost overriding the main host, add the follow lines into file httpd-vhosts.conf:
# Main host
<VirtualHost *:80>
ServerName localhost
DocumentRoot "/xampp/htdocs"
</VirtualHost>
# Additional host
<VirtualHost *:80>
# Over directives there
</VirtualHost>
For someone doing everything described here and still can't access:
XAMPP with Apache 2.4:
In file httpd-vhost.conf:
<VirtualHost *>
DocumentRoot "D:/xampp/htdocs/dir"
ServerName something.dev
<Directory "D:/xampp/htdocs/dir">
Require all granted #apache v 2.4.4 uses just this
</Directory>
</VirtualHost>
There isn't any need for a port, or an IP address here. Apache configures it on its own files. There isn't any need for NameVirtualHost *:80; it's deprecated. You can use it, but it doesn't make any difference.
Then to edit hosts, you must run Notepad as administrator (described below). If you were editing the file without doing this, you are editing a pseudo file, not the original (yes, it saves, etc., but it's not the real file)
In Windows:
Find the Notepad icon, right click, run as administrator, open file, go to C:/WINDOWS/system32/driver/etc/hosts, check "See all files", and open hosts.
If you were editing it before, probably you will see it's not the file you were previously editing when not running as administrator.
Then to check if Apache is reading your httpd-vhost.conf, go to folder xampFolder/apache/bin, Shift + right click, open a terminal command here, open XAMPP (as you usually do), start Apache, and then on the command line, type httpd -S. You will see a list of the virtual hosts. Just check if your something.dev is there.
According to this documentation: Name-based Virtual Host Support
You may be missing the following directive:
NameVirtualHost *:80
Just change <VirtualHost *:80> to <VirtualHost 127.0.0.1:80>.
Then the default DocumentRoot will serve for all domains or IP addresses that point to your server and specified VirtualHost will work.
It may be because your web folder (as mentioned "/Applications/MAMP/htdocs/mysite/web") is empty.
My suggestion is first to make your project and then work on making the virtual host.
I went with a similar situation. I was using an empty folder in the DocumentRoot in httpd-vhosts.confiz and I couldn't access my shahg101.com site.
I am running Ubuntu 16.04 (Xenial Xerus). This is what worked for me:
Open up a terminal and cd to /etc/apache2/sites-available. There
you will find a file called 000-default.conf.
Copy that file: cp 000-default.conf example.local.conf
Open that new file (I use Nano; use what you are comfortable with).
You will see a lot of commented lines, which you can delete.
Change <VirtualHost *:80> to <VirtualHost example.local:80>
Change the document root to reflect the location of your files.
Add the following line: ServerName example.local And if you need to, add this line: ServerAlias www.example.local
Save the file and restart Apache: service Apache2 restart
Open a browser and navigate to example.local. You should see your website.
For anyone using Windows and the Bitnami WAMP Stack Manager Tool this virtual host configuration should go into Bitnami\apache2\conf\bitnami\bitnami.conf
Note: Some settings in Directory section is not a must.
For example, my virtual host configuration for site.com would be as follows:
<VirtualHost site.com:80>
DocumentRoot "C:/Bitnami/apache2/htdocs/site/docroot"
<Directory "C:/Bitnami/apache2/htdocs/site/docroot">
Options Indexes FollowSymLinks
AllowOverride All
<IfVersion < 2.3 >
Order allow,deny
Allow from all
</IfVersion>
<IfVersion >= 2.3 >
Require all granted
</IfVersion>
</Directory>
</VirtualHost>
Remember that configuration for vhost as mentioned, by other friends, sagits's answer is needed.

Apache,may I have multiple documentRoot?

I'm building a Zend website.The project (local) has the following structure:
/app
/controllers
/views
/public
/css
/images
/js
.htaccess
index.php
Because the .htaccess and index.php files reside within th public directory,the public directory must be identifiable by apache as the website's document root and root directory.
So I should go to edit the "DocumentRoot from c:/wamp/www/ to c:/wamp/www/my-zend-app/public" inside the httpd.conf file.
But if I do so I can't reach my other projects inside "c:/wamp/www/".. can I keep both the documentRoots?
EDIT
I tried with uncommenting the httpd.conf line about "httpd-vhost.conf" and edited the file:
[httpd-vhost.conf]
<VirtualHost *:80>
ServerAdmin webmaster#dum.com
DocumentRoot "C:\wamp\www\my-zend-app\application\public"
ServerName website.loc
ErrorLog "C:\wamp\www\my-zend-app\application\public\error.log"
CustomLog "C:\wamp\www\my-zend-app\application\access.log" common
</VirtualHost>
right after edited the windows hosts file adding:
127.0.0.1 website.loc
but it's not working.I'm running WAMPSERVER 2.1
Add a <Directory> Directive to your <VirtualHost> directive for the new document root
<VirtualHost *:80>
...
<Directory "C:/wamp/www/my-zend-app/application/public">
Options Includes Indexes FollowSymLinks
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Create a second virtual host using a different port or using ServerName (and editing hosts file to resolve locally.
The easier one is just using different virtual hosts on different ports but remember also adding Listen yourPort on the main config to make apache listen that port too.

How do I create a VirtualHost on Zend Server?

I am using zend server and I added one VirtualHost into the extra/httpd-vhosts.conf file and removed # from the httpd.conf file.
This is what I added into the extra/httpd-vhosts.conf file:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName quickstart.local
DocumentRoot D:/quickstart/Code
<Directory D:/quickstart/Code>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
When I access quickstart.local it is working fine, but it also affects localhost (i.e when I try to load http://localhost/, I see the same site I do for http://quickstart.local/.
How do I resolve this issue? I want both localhost (I use this for another project) and quickstart.local to be separate.
I have the same problem. Try to add a host to zend.conf or
add
Include conf/extra/httpd-vhosts.conf
to htppd.conf
You can add a new vhost by adding the directives to a new file:
/path/to/zend/etc/sites.d/vhost_[my-site].conf
Replace [my-site] with whatever you want (no spaces).
Then, be sure you restart apache:
sudo /path/to/zend/bin/apachectl restart
I had similar issue when trying to add own sites. Solution for me was to comment both vhost examples in vhosts file and also uncomment or add the
127.0.0.1 localhost
into hosts file in %windir%/system32/drivers/etc folder
... ofcourse if you need to uncomment vhost_alias module and include for httpd-vhosts file..
[FILE PATH] \xampp\apache\conf\extra\httpd-vhosts.conf or, if you are
using Apache 2.4 or above:
<VirtualHost *:80>
ServerName dev.zendapp
DocumentRoot "G:/xampp/htdocs/io2018/zend2018/zendApps"
SetEnv APPLICATION_ENV "development"
<Directory "G:/xampp/htdocs/io2018/zend2018/zendApps">
DirectoryIndex index.php
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
After change. C:\Windows\System32\drivers\etc\hosts
127.0.0.1 dev.zendapp
Restart Your xampp Server

Apache configuration for Symfony website with virtual hosts

I'm trying to configure my local Apache2 server to host several Symfony websites using virtual hosts, but I just can't make it to alias lib/vendor/symfony/data/web/sf directory as /sf. I see that using %1 and %2 in alias statement is the source of the problem, but I can't find the right solution. I added to /etc/hosts entry 127.0.0.1 jobeet.sandbox.sfdevel, I created in my home directory directory ~/Projekty/sandbox/jobeet. My Apache2 site configuration reads as follows:
<VirtualHost *:80>
ServerName localhost
ServerAlias *.sfdevel
VirtualDocumentRoot /home/alef/Projekty/%2/%1/web
<Directory /home/alef/Projekty/%2/%1/web>
AllowOverride All
Allow from All
</Directory>
Alias /sf /home/alef/Projekty/%2/%1/lib/vendor/symfony/data/web/sf
<Directory /home/alef/Projekty/%2/%1/lib/vendor/symfony/data/web/sf>
AllowOverride All
Allow from All
</Directory>
ErrorLog /var/log/apache2/sfdevel_error.log
LogLevel warn
CustomLog /var/log/apache2/sfdevel_access.log combined
</VirtualHost>
When I change /home/alef/Projekty/%2/%1/lib/vendor/symfony/data/web/sf to /home/alef/Projekty/sandbox/jobeet/lib/vendor/symfony/data/web/sf it works just fine, but I want to use several separate Symfony websites. What changes should I include in my Apache2 configuration?
I'm not sure if you can create aliases this way. There's nothing about it in the apache documentation.
I'd think about removing Alias from your virtualhost definition anyway. Symbolic link will work the same:
cd /home/alef/Projekty/sandbox/jobeet/web
ln -s ../lib/vendor/symfony/data/web/sf