I want to create VHost on my machine.
My config:
/etc/hosts
127.0.0.1 mysite.dev
/etc/apache2/sites-available/mysite.dev
<VirtualHost *:80>
SetEnv APPLICATION_ENV "development"
ServerName mysite.dev
DocumentRoot /home/michal/Public/mysite/public/frontend
<Directory /home/michal/Public/mysite/public/frontend>
Options Indexes FollowSymLinks Includes
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
After I run
sudo a2ensite mysite.dev
sudo /etc/init.d/apache2 restart
Now when I type mysite.dev to the browser, I see standard Apache index.html ("It works!"). Why? Where should I find my problem?
Not very clear from your question exactly what you want to achieve. If you want forward to specific URL say HTTPS URL then it can be achieve using following lines:
<VirtualHost *:80>
ServerName localhost:80
RedirectMatch permanent ^(.*)$ https://localhost:8443$1
</VirtualHost>
If you are trying to configure apache server , jboss server and mod_jk then you can refer this link
OK, this was asked like a year ago but today I ran into this same problem and probably the solution I found will be very helpful for somebody else, so here it is.
What worked for me was renaming the soft links in /etc/apache2/sites-enabled, appending the extension .conf to every link in that folder.
So if we had the following links:
/etc/apache2/sites-enabled$ ls -l
lrwxrwxrwx 1 root root 23 Nov 30 2012 site1 -> ../sites-available/site1
lrwxrwxrwx 1 root root 23 Nov 30 2012 site2 -> ../sites-available/site2
we should rename both to site1.conf and site2.conf
/etc/apache2/sites-enabled$ sudo mv site1 site1.conf
/etc/apache2/sites-enabled$ sudo mv site2 site2.conf
and then of course, restart apache
/etc/apache2/sites-enabled$ sudo /etc/init.d/apache2 restart
The reason why this worked forme is that Apache has changed sometime in the recent past the way this files should be named in order for them to be loaded correctly, as described in the last lines of apache2.conf file.
# Include the virtual host configurations:
IncludeOptional sites-enabled/*.conf
You are seeing default index.html page because you haven't disabled Apache default virtual host, Disable the default Apache virtual host using the command:
sudo a2dissite 000-default.conf
Related
I have a website which I used to deploy in localhost running the command: sudo /etc/init.d/apache2 start and then typing the URL: http://XXX/myfirstphpsite/src where XXX is my IP address and myfirstphpsite/src the repertory containing my website.
However, now I want to type the following URL:
http://pharaohohparis.tld instead of the last URL to deploy in local my website.
For that, I did the following:
I went to the repertory: /etc/apache2/sites-available/ and created a new file named: pharaohofparis.tld.conf in which I inserted:
<VirtualHost *:80>
ServerName pharaohofparis.tld
DocumentRoot /var/www/html/myfirstphpsite/src
<Directory /var/www/html/myfirstphpsite/src>
Options Indexes FollowSymLinks Includes
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I actived the virtual host by typing:
sudo a2ensite pharaohofparis.tld.conf
sudo service apache2 reload
I edited the file /etc/hosts by adding the line:
127.0.0.1 pharaohofparis.tld
However, when I type the URL: http://pharaohofparis.tld, I got the DNS error "DNS_PROBE_FINISHED_NXDOMAIN". How can I fix this ?
EDIT: THE PROBLEM WAS LINUX SUBSYSTEM. THERE WAS NO PROBLEM IS A REAL UBUNTU.
As I said in my Edit above: the problem was apparently Linux Subsystem. There was no problem is a real Ubuntu.
I have created apache virtual host as in the link:
[set up apache virtual hosts ][1]
https://www.youtube.com/watch?v=Vd2aLTZDLQg
But i am not able access the web page from google . I tried out following link also but it also didnt worked
[how to create virtual host on apache][1]
https://www.youtube.com/watch?v=PaEs4-3Rrok
Please suggest what i do wrong why the virtual host not working
I'm trying to help you by giving a resume of steps you need to do to make your virtual host working. Make your own changes to adapt it with your project (name, location...etc)
I suppose that you have a running website which you can access it using http://127.0.0.1/example.com
I suppose that you want to create a virtual host to access it using http://example.dev
I suppose that the folder "example.com" is under "/var/www/"
I suppose that you are working on Ubuntu (or using a Windows 10 Ubuntu Bash)
Step 1
sudo nano etc/apache2/sites-available/example.com.conf
Copy/paste the following content inside it:
<VirtualHost *:80>
ServerName www.example.dev
ServerAlias example.dev
ServerAdmin changeThisWithYourEmail
DocumentRoot /var/www/example.com/
DirectoryIndex index.php
<Directory "/var/www/dev">
Options Multiviews FollowSymLinks
MultiviewsMatch Any
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/example_error.log
CustomLog ${APACHE_LOG_DIR}/example_access.log combined
</VirtualHost>
Step 2
sudo a2ensite example.com.conf
Step 3
sudo nano /etc/hosts
and then add this line at the end of the file:
127.0.1.1 example.dev
Step 4
sudo service apache2 restart
Step 5
Check if http://example.dev is showing the same result as http://example.com
I'm currently creating an application using AWS AMI, and it comes w/ an httpd 2.4.10. Here was the steps I followed on creating the vhost
sudo mkdir /etc/httpd/sites-available
sudo mkdir /etc/httpd/sites-enabled
edited /etc/httpd/conf/httpd.conf to have IncludeOptional sites-enabled/*.conf
created realtydig.conf inside /etc/httpd/sites-available
symlinked it to /etc/httpd/sites-enabled
sudo apachectl restart
sudo service httpd restart
*still the default httpd page is the one showing, vhost not pointing to domain
here's the vhost
xml
<VirtualHost *:80>
ServerName beta.realtydig.com
DocumentRoot /var/www/realtydig/laravel
<Directory "var/www/realtydig/laravel/public">
AllowOverride all
</Directory>
</VirtualHost>
I would like to understand, what happened wrong. It seems to be loading up since error occured w/ some of my previous typos when i was trying to restart the application.
If "nothing happened" then I assume that you see just white empty page in browser. Usually some other vhost will be see if current vhost is not activated.
DocumentRoot must be pointing to the public folder like this
DocumentRoot /var/www/realtydig/laravel/public
You can debug by creating test.html inside the DocumentRoot and try to access it from the browser.
I have various virtual hosts for my web development work, including
cnm. The
sites-available/cnm
my file says very simply:
<VirtualHost *:80>
ServerName cnm
DocumentRoot /var/www/cnm/public_html
</VirtualHost>
I upgraded to Ubuntu 13.10, and when I point my browser to cnm/, I see the
/var/www/index.html file that seems to be indicated in the default file
sites-available/000-default.conf
which says (among other things):
<VirtualHost *:80>
DocumentRoot /var/www
What do I need to do to get Apache to read my cnm document root when I browse to cnm/ ?
NOTES:
I already tried renaming my sites-available/cnm file to sites-available/cnm.conf and enabling it with a2ensite cnm and service apache2 reload. That is a good thing, but it changes nothing.
I already tried changing <VirtualHost *:80> to <VirtualHost cnm.localhost> or to <VirtualHost cnm>. That did nothing.
Ubuntu 13.10 uses apache 2.4, you should check all your apache configuration. But for this present case you should note that a2ensite and a2dissite commands won't be able to see your files in /etc/apache2/sites-available if it does not end with .conf, so rename it to sites-available/cnm.conf and run a2ensite cnm.
Then your Virtualhost definition is certainly better with *:80, it means this virtualhost is activated for all IP interfaces (*) on port 80. cnm.localhost or cnm are not valid values here, only IP numbers (Ip of your apache server) or * for all, and a port number.
Then check how you configuration is read by apache, running theses commands:
# load apache env
# be careful, there is a dot and a space
. /etc/apache2/envvars
# Check apache Virtualhosts config
apache2 -S
You should get something like:
VirtualHost configuration:
*:80 is a NameVirtualHost
default server something (/etc/apache2/sites-enabled/000-default.conf:1)
port 80 namevhost something (/etc/apache2/sites-enabled/000-default.conf:1)
port 80 namevhost cnm (/etc/apache2/sites-enabled/cnm.conf:4)
If it is ok, and if you have the right Ip in your hosts file for cnm, and you can test that with a ping, then using http://cnm/ should use the Virtualhost having cnm in the ServerName.
If you have an answer from the default Virtualhost then it means apache is not finding the name used in your Host header in the list of ServerName and ServerAlias available for that IP/port and fallbacks to the default Virtualhost. If you are really stuck (and you did not forgot to restart) you can always remove the default Virtualhost and keep only the one you are working on.
I found the answer to my issue. I needed to delete the files in /etc/apache2/sites-enabled.
Delete files in /etc/apache2/sites-enabled
Rename config files in /etc/apache2/sites-available to have a .conf ending
For each file in sites-available, run sudo a2ensite mysite.
Run sudo service apache2 reload
I couldn't find any step by step tutorial on how to make it work on my side. I gathered bits and pieces here and there, so for those who need all the steps to follow, here there are:
$ sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/local-mydefault.conf
$ sudo gedit /etc/apache2/sites-available/local-mydefault.conf
Paste the following into the local-mydefault.conf file (Change the path '/your/full/path' to where you want to have your files. And change username to your own username):
# ------------------------------------------------------
<VirtualHost *:80>
ServerName localhost
ServerAdmin webmaster#localhost
DocumentRoot /your/full/path
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /your/full/path>
DirectoryIndex index.php
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Require all granted
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
User username
Group username
# ------------------------------------------------------
Then type the following commands
$ cd /etc/apache2/sites-available/
$ sudo a2ensite local-mydefault.conf
$ sudo a2dissite 000-default.conf
$ sudo /etc/init.d/apache2 restart
I found the answer to this issue:
When upgrading to Ubuntu 13.10, the DocumentRoot does not seem to make a difference.
This is because Apache 2.4 moved the Directory configuration somewhere else. Your old .conf files still have these lines:
DocumentRoot "/var/www/myVhost"
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory "/var/www/myVhost">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
Remove (or comment out) the <Directory> directives so you only have:
DocumentRoot "/var/www/myVhost"
Now reload your settings: service apache2 reload and DocumentRoot is back. :)
Rename the file configuration "cnm" with the extension .conf
mv sites-available/cnm sites-available/cnm.conf
a2ensite sites-available/cnm.conf
And ready!
service apache2 reload
I have the same issue
on way is to disable 000-default and reload apache ,but this isn't the solution becuase you must have just one vhost at a same time :(
sudo a2dissite 000-default.conf
sudo service apache2 reload
I ran into a similar issue. My server name and my FQDN were the same to the default was running into the /var/www/html directory. I disabled the default configuration and my site worked like a breeze. Thanks #regilero.
sudo a2dissite 000-default.conf
fixed it for me.
Hello I have been looking through internet articles forums to solve my issue and so far it has been to no avail. I am trying to set up an Apache virtual host for my FuelPHP development on localhost but I keep getting slammed with the error 403 message. Here is my current setup.
#/etc/apache2/sites-enabled/000-default
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin webmaster#example.com
DocumentRoot "/home/supercomputer/Desktop/PHP/fuelProject/public"
ServerName localhost.home
<Directory "/home/supercomputer/Desktop/PHP/fuelProject/public" >
Options Indexes FollowSymLinks MultiViews Includes ExecCGI
AllowOverride All
Order Allow,Deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
I have pointed my Docroot to the public folder inside my fuelProject. Also to make sure Apache had access to the server files, I set the permissions for all of the files recursively to read, write, and execute just to be a 100% safe. Any clues as to what else could be going wrong?
PS: I am running ubuntu raring (13.04)
PSS: And I am trying to visit localhost.home and localhost.home/index.php. I also get the following warnings upon restarting the server
* Restarting web server apache2 apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[Fri May 03 15:46:58 2013] [warn] NameVirtualHost *:80 has no VirtualHosts
... waiting apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[Fri May 03 15:46:59 2013] [warn] NameVirtualHost *:80 has no VirtualHosts
Here is the correct way of adding Vhost for fuelphp application or any other php application
<VirtualHost *:80>
ServerName localhost.home
DocumentRoot /home/supercomputer/Desktop/PHP/fuelProject/public
ServerAdmin webmaster#localhost
<Directory /home/supercomputer/Desktop/PHP/fuelProject/public>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
And also the below line is not required I dont know why you have added
NameVirtualHost *:80
After doing all above add a host entry to your machine to do that
sudo vi /etc/hosts
add an entry of the virtual host
127.0.0.1 localhost.home
After doing all these things
restart Apache by running
sudo /etc/init.d/apache2 restart
And just load http://localhost.home in your browser you should be able to see your site up and running .
If you still get forbidden error .you need to give permissions to your whole application folder
follow run these commands to do so
sudo chown -R www-data:www-data /home/supercomputer/Desktop/PHP
sudo chmod -R 775 /home/supercomputer/Desktop/PHP
At last add yourself to www-data group
sudo adduser yourUserName www-data
The configuration I posted were working. The problem was with permissions. I had set only my containing fuel project folder to permission 777 but for some reason apache wanted access to almost all the folders containing it. Weird I know but setting all the permissions to 777, it worked. Reading the darn apache log sure helped. If you are having a similar problem, I suggest find the apache log and ACTUALLY READ IT
Testeed on Ubuntu 14.04: I did everything above but I didn't work. I missed to allow access to the directory in my apache2.conf. This is needed if you don't use a standard directory like /var/www or /usr/share/.
<Directory /usr/local/vufind>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
This was mentioned on the4 default PHP site. It's worth reading it!