I use homestead and Laravel 5.4 and I need to enable sub-domains, in my main windows 10 machine I added a hosts in (C:\WINDOWS\system32\drivers\etc\hosts) record :
192.168.10.10 myapp.dev
192.168.10.10 website.myapp.dev
so this works ok, when I navigate to website.myapp.dev it displays homepage as if I go to myapp.dev, and also my homestead server is apache2 not nginx
In this route when I go to website.myapp.dev I get the expected output (website.myapp.dev) in the log:
Route::get('/', function(Illuminate\Http\Request $request){
\Log::info($request->fullUrl()); // logs website.bikser.dev
});
however my this route is not firing up when I go to website.myapp.dev :
Route::domain('{account}.myapp.dev')->group(function () {
Route::get('/{account}', 'WebsiteController#view');
});
So I need this route to work so I could use sub-domains , I didn't change anything in .htaccess file coz I don't know if I should and also I tried to edit apache2.conf and add this lines:
<VirtualHost *:80>
ServerName myapp.dev
ServerAlias *.myapp.dev
</VirtualHost>
but still my {account}.myapp.dev route does not fire up , pls help
EDIT:
just added this code as was suggested by : #headmax, but when I navigate to myapp.dev it says
NotFoundHttpException , this is the code that I added :
<VirtualHost *:80>
ServerName myapp.dev
DocumentRoot home/vagrant/code/public
<Directory "home/vagrant/code/public/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
#Require local
Require all granted
</Directory>
</VirtualHost>
First change the right of your new doc root :
sudo chown -R $USER:$USER home/vagrant/code/public
Note: The default Apache configuration in Debian 8 requires that each
virtual host file end in .conf.
We copy the default vhost for your own site.conf 000-default.conf
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/myapp.dev.conf
You need to edit the file and add here your virtualhost paste
sudo nano /etc/apache2/sites-available/myapp.dev.conf
We need the simple way look like this :
<VirtualHost *:80>
ServerAdmin admin#myapp.dev
ServerName myapp.dev
ServerAlias www.myapp.dev
DocumentRoot /home/vagrant/code/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Now that we have created our virtual host files, we can enable.
sudo a2ensite myapp.dev.conf
Output: Enabling site myapp.dev. To activate the new configuration,
you need to run: service apache2 reload
Restart Apache
service apache2 reload //to reload configuration
sudo systemctl restart apache2 //to apply the configuration change
Now your are done test the site.
You need a root directory to tell apache where are stored you site files.
Here example myapp.dev is a folder and the public folder are (a child) where public files stored.
<VirtualHost *:80>
ServerName myapp.dev
DocumentRoot home/vagrant/code/public
<Directory "home/vagrant/code/public/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
#Require local
Require all granted
</Directory>
</VirtualHost>
Related
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.
I got a local directory, which will need a DocumentRoot.
When I go to serverip/nivon-zuidholland I must have a DocumentRoot of public.
How would I manage this in apache2 config?
I inserted this in my apache2.conf. I tried to put this into my sites-available/nivon-zuidholland.conf but this doesn't work as well.
I can't restart apache2 because it returns DocumentRoot not allowed here.
<Directory "/var/www/html/nivon-zuidholland">
AllowOverride All
DocumentRoot /var/www/html/nivon-zuidholland/public
</Directory>
In your /etc/hosts add this:
127.0.0.1 nivon-zuidholland.local
Create a directory: /var/www/nivon-zuidholland (set group to www-data)
Create a Virtual host file: /etc/apache2/sites-available/nivon-zuidholland.conf
<VirtualHost *:80>
ServerName nivon-zuidholland.local
ServerAdmin webmaster#nivon-zuidholland.local
DocumentRoot /var/www/nivon-zuidholland
ErrorLog ${APACHE_LOG_DIR}/nivon-zuidholland_error.log
CustomLog ${APACHE_LOG_DIR}/nivon-zuidholland.log combined
</VirtualHost>
Place a symbolic link to this vhost conf file in sites-enabled directory
ln -s /etc/apache2/sites-available/nivon-zuidholland.conf /etc/apache2/sites-enabled/nivon-zuidholland.conf
Restart Apache server: sudo service apache2 restart
You should be able to access the site by going to: http://nivon-zuidholland.local/
I am trying to setup a vhost in ubuntu, my file is like
/var/www/vhost/domain1.com/app
/var/www/vhost/domain1.com/public
/var/www/vhost/domain2.com/app
/var/www/vhost/domain2.com/public
the vhost in /etc/apache2/site-avalable/domain1.com.conf is :
<virtualhost *:80>
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
ServerAdmin webmaster#domain1.com
ServerName domain1.com
ServerAlias *.domain1.com
DirectoryIndex index.php
DocumentRoot /var/www/vhosts/domain1.com/public
LogLevel warn
ErrorLog /var/www/vhosts/domain1.com/log/error.log
CustomLog /var/www/vhosts/domain1.com/log/access.log combined
</virtualhost>
problem
the vhost folder and all the files after that (the children) are accessible in the web browser. I know I have to put some sort of htaccess but i don't know how and where I have to put it.
If you use apache 2.4 and you develop on a local machine:
Create a new configuration file for your website:
$ sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/domain1.com.conf
Edit the file like so:
<VirtualHost *:80>
ServerName domain1.com
ServerAlias *.domain1.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/vhost/domain1.com/public
ErrorLog /var/www/vhosts/domain1.com/log/error.log
CustomLog /var/www/vhosts/domain1.com/log/access.log combined
</VirtualHost>
Enable the website
$ sudo a2ensite domain1.com
Restart apache
$ sudo service apache2 restart
Add the following line to your /etc/hosts file
127.0.1.1 domain1.com
Now it should work, go to http://domain1.com and check it out.
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
As i tried to configure my virtual host in apache. I put something like this,
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /xampp/htdocs/gift
ServerName gift.loc
</VirtualHost>
And in my hosts file i put something like this,
127.0.0.1 localhost
127.0.0.1 gift.loc
And i run it on the browser,
http://gift.loc - is fine
But when i tried using this,
http://localhost/othersite - can't found
Do i missed somehting to configure? ANy ideas...
Thanks in advance,
You need a VirtualHost entry for every host you want apache to handle. The first one in the config file will be used as the default if no other VirtualHosts match the request.
For example if we have:
<VirtualHost *:80>
DocumentRoot /xampp/htdocs/gift
ServerName gift.loc
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /example/htdocs/gift
ServerName example.com
</VirtualHost>
A request for foobar.org will get handled by the gift.loc virtual host.
you need to put localhost in the vhosts.conf
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /xampp/htdocs/
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /xampp/htdocs/gift
ServerName gift.loc
</VirtualHost>
This works fine (Make sure you restart apache). If you need to check your configuration you can (on linux at least) run httpd -S.
There are few steps you need to follow to setup the virtual host on ubuntu:
Let say that your project folder name is myProject
Step 1:Place your folder inside /var/www/html
sudo mv ~/myProject /var/www/html/
Step 2: Give ownership of project folder to www-data
sudo chown -R www-data:www-data /var/www/html/myProject
Step 3:Create new site inside Sites available:
cd /etc/apache2/sites-available/
ls
Here you will see existing 000-default.conf and default-ssl.conf .Copy the content of both file into one file and replace your folder name or copy this one into new file named myProject.conf
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/myProject/
ServerName project.com
ServerAlias www.project.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:443>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/myProject/
ServerName project.com
ServerAlias www.project.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /etc/ssl/certs/mobidev_cert.pem
SSLCertificateKeyFile /etc/ssl/certs/mobidev_key.pem
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
</VirtualHost>
Include the path of self signed certificate also in this as shown ssl key and ssl certificate that can be downloaded easily.
Step 4:Add your project into apache configuration file.
sudo vi /etc/apache2/apache2.conf
put this lines in the file:
DocumentRoot "/var/www/html/myProject"
<Directory /var/www/html/myProject/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Step 5:Add your virtual server name (specified in myProject.conf) into host file.add that line:
sudo gedit /etc/hosts
127.0.1.1 project.com
Step 6:Now all set ,enable site,restart apache
sudo a2ensite /etc/apache2/sites-availabl/myProject.conf
sudo systemctl reload apache2
sudo update-rc.d apache2 defaults
sudo update-rc.d mysql defaults
sudo a2enmod ssl
sudo a2ensite default-ssl
Just hit project.com in your browser.
From the docs, it looks like we need to create a block for each different host that you would like to serve.
Further in the same doc, If you are adding virtual hosts to an existing web server, you must also create a block for the existing host.