Im trying to redirect to a web page on my localhost, I have done all the nessesary configurations from my hosts files and v-hosts it picks up my address from my C:\Windows\System32\drivers\etc hosts file which is name.local but does not show the main page. Keeping in mind the site has both front and backend access. I'm new and wanna work on my application locally before i can start editing it on the server.
You posted this additional comment containing your vhost definition and hosts file contents
v-host file
<VirtualHost 127.0.0.1:80>
DocumentRoot "c:/xampp/htdocs/intranet"
ServerName gep.local
ServerAlias gep.local
CustomLog "c:gep.local-access_log" combined
ErrorLog "c:gep.local-error_log"
<Directory "c:/xampp/htdocs/intranet">
DirectoryIndex index.php
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
host file:
127.0.0.1 gep.local
Here are a few suggestions:-
Have you rebooted or restarted the DNS Client to activate your HOSTS file changes.
from a command window run started using 'Run as Administrator' do this
net stop "DNS Client"
then once it reports as STOPPED
net start "DNS Client"
This will refresh the windows DNS Cache. ( Double quotes are required as there is a space in the service name )
First change <VirtualHost 127.0.0.1:80> to <VirtualHost *:80>
If you are using Apache 2.2.x you also need a NameVirtualHost *:80 parameter as the first parameter in the vhost definition file. If you are using Apache 2.4.x I believe they removed this requirement so it is not necessary on that version of Apache.
So
new v-host file
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "c:/xampp/htdocs/intranet"
ServerName gep.local
ServerAlias gep.local
CustomLog "c:/gep.local-access_log" combined
ErrorLog "c:/gep.local-error_log"
<Directory "c:/xampp/htdocs/intranet">
DirectoryIndex index.php
Options Indexes FollowSymLinks
AllowOverride All
Order Allow,Deny
Allow from all
</Directory>
</VirtualHost>
Then of course to test it use the address `http://gep.local' in your browser address bar to get to this new virtual host.
Related
After reading ubuntu AMP community and Apache 2.4 configuration.
I was wondering if there is a way to imitate the same behavior of the http docs used in XAMPP or bitnami stacks but using the default LAMP. Which uses apache 2.4
In XAMP you would assign an extra number to your httpd-vhost.conf like this:
Listen *:9000
<virtualhost *:9000>
ServerName localhost
DocumentRoot "~/xamp/apache2/htdocs/html/app-name/"
</virtualhost>
<Directory "~/xamp/apache2/htdocs/html/app-name/">
Options Indexes FollowSymLinks
AllowOverride all
</Directory>
Then Edit your httpd.conf files like:
//....Some code..... */
<Directory>
AllowOverride all
<Directory />
//...Some code...
and uncomment this line:
//....Some code..... */
# Virtual hosts
include conf/extra/httpd-vhosts.conf
//...Some code...
My question is:
Is there is a way to configure Apache 2.4 just by dropping all my vhost's in one single file, without having to go through the process of configuring etc/apache2/sites-available and then adding names to etc/hosts?
Then completing the process by including some things like above just like Bitnami or Xamp stacks will do so your localhost will be able to serve not only static html files but an entire application's folder.
What works is the following in (for example) your 000-default.conf:
<VirtualHost *:80>
ServerName site1.vm
ServerAdmin webmaster#localhost
DocumentRoot /var/www/site1/web/
ErrorLog ${APACHE_LOG_DIR}/site1_error.log
CustomLog ${APACHE_LOG_DIR}/site1_access.log combined
<Directory /var/www/site1/web/>
Options All
AllowOverride All
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName site2.vm
ServerAdmin webmaster#localhost
DocumentRoot /var/www/site2/web/
ErrorLog ${APACHE_LOG_DIR}/site2_error.log
CustomLog ${APACHE_LOG_DIR}/site2_access.log combined
<Directory /var/www/site2/web/>
Options All
AllowOverride All
</Directory>
</VirtualHost>
This way all you have to do is add the site to the conf file, add the host to your hosts file, and reload apache2 service. Hope that is what you were looking for.
I'm trying to do something simple with virtual hosts in Apache 2.4 (using Wampserver 2.5)
I want to be able to have several virtual hosts and access them simply by :
www.project1.dev
www.project2.dev
So I made the following configuration in httpd.conf by reading the official guide :
NameVirtualHost \*:80
#
# Project 1
#
<VirtualHost *:80>
DocumentRoot "C:/wamp/www/myProject1/"
ServerName www.project1.dev
ErrorLog "logs/project1-error_log "
CustomLog "logs/project1-access_log" common
<Directory "C:/wamp/www/myProject1/">
AllowOverride all
Require all granted
</Directory>
</VirtualHost>
#
# Project 2
#
<VirtualHost *:80>
DocumentRoot "C:/wamp/www/myProject2/"
ServerName www.project2.dev
ErrorLog "logs/project2-error_log "
CustomLog "logs/project2-access_log" common
<Directory "C:/wamp/www/myProject2/">
AllowOverride all
Require all granted
</Directory>
</VirtualHost>
I also added them to my hosts file
127.0.0.1 http://project1.dev
127.0.0.1 http://project2.dev
But while I'm testing after restart wamp services, both http://project1.dev and http://project2.dev point at C:/wamp/www/myProject1/
The second path C:/wamp/www/myProject2/ related to project2.dev seems to be ignored.
Am I missing something?
Thanks.
You have not defined http://project2.dev anywhere - just http://www.project2.dev. So Apache defaults back to first config as it can't find a match.
Add the following config to the first vhost:
ServerAlias project1.dev
and similarly this to the second:
ServerAlias project2.dev
Then restart Apache.
The simple answer is that as of Apache 2.4 the NameVirtualHost *:80 syntax is no longer required or allowed! It throws an error and causes Apache not to start. The error will appear in the apache error log if you look for it.
Oh and NameVirtualHost \*:80 was never right!
So just remove the line NameVirtualHost \*:80 completely.
As soon as you define a Virtual Host, the localhost in httpd.conf gets ignored so you should define that in httpd-vhost.conf as well, otherwise the other 2 VH defs look fine, except for the ServerName and missing ServerAlias and the missing Options
<VirtualHost *:80>
DocumentRoot "C:/wamp/www/"
ServerName localhost
<Directory "C:/wamp/www/">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Require local
</Directory>
</VirtualHost>
#
# Project 1
#
<VirtualHost *:80>
DocumentRoot "C:/wamp/www/myProject1/"
ServerName project1.dev
ServerAlias www.project1.dev
ErrorLog "logs/project1-error_log "
CustomLog "logs/project1-access_log" common
<Directory "C:/wamp/www/myProject1/">
AllowOverride all
Options Indexes FollowSymLinks MultiViews
Require all granted
</Directory>
</VirtualHost>
#
# Project 2
#
<VirtualHost *:80>
DocumentRoot "C:/wamp/www/myProject2/"
ServerName project2.dev
ErrorLog "logs/project2-error_log "
CustomLog "logs/project2-access_log" common
<Directory "C:/wamp/www/myProject2/">
AllowOverride all
Options Indexes FollowSymLinks MultiViews
Require all granted
</Directory>
</VirtualHost>
Quote: But while I'm testing after restart wamp services, both http://project1.dev and http://project2.dev point at C:/wamp/www/myProject1/
If there is an error in your VH definitions, Apache will default to the first correctly defined VH in the httpd-vhosts.conf, so thats what is probably happening
As to your HOSTS file it should include references to the IPV4 and IPV6 stack, especially as windows seems to use the IPV6 stack more and more, afterall that where we are moving to, eventually, and it should not include httpd:// so it should be like this :-
#IPV4 stack ip addresses
127.0.0.1 localhost
127.0.0.1 project1.dev
127.0.0.1 project2.dev
#IPV6 stack ip addresses
::1 localhost
::1 project1.dev
::1 project2.dev
Once you have changed the HOSTS file, you either need to reboot, or do the following in a command windows launches with "Run as Administrator"
net stop dnscache
net start dnscache
I just started learning php and I am trying to host locally my own php website by using XAMPP.
I wanted to create virtual host with:
URL: myphpwebsite.local
Port: 8088
But when I attempted to access this website through the browser I got a:
Not Found
HTTP Error 404. The requested resource is not found.
Does anyone know what the problem is?
My httpd-vhosts.conf
NameVirtualHost 127.0.0.1:8088
<VirtualHost 127.0.0.1:8088>
DocumentRoot "C:/xampp/htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost myphpwebsite.local>
DocumentRoot "C:/Microsoft/Workspace/myphpwebsite"
ServerName myphpwebsite.local
ErrorLog "C:/Microsoft/Workspace/myphpwebsite/logs/myphpwebsite.local.error.log"
CustomLog "C:/Microsoft/Workspace/myphpwebsite/logs/myphpwebsite.local.custom.log" combined
<Directory "C:/Microsoft/Workspace/myphpwebsite">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
And my C:\Windows\System32\drivers\etc\hosts file:
127.0.0.1 localhost
127.0.0.1 myphpwebsite.local
Any help would be appreciated!
make sure there's file/htaccess/index or whatever in directory you want to open, 404 may comes from that ;)
try using one below, eventually replace your port:
<VirtualHost *:80>
DocumentRoot "C:/Microsoft/Workspace/myphpwebsite"
ServerName myphpwebsite.local
</VirtualHost>
the question is your Apache running/serving on port 8088?
For example my xamp is running on 80 and 443...
xamp control panel is very handy, it has nice logs button that will open your log files to show you php and apache errors etc. check it out.
Try going with default port, if it works it means that you need to play with ports if you really want to.
just a quick tip, .com is shorter than .local and if you're using chrome and it works like mine then most of the time something.local will redirect you to google search (and I like my search there, you can switch it off ;))
I don't know if I am much help, but using WAMP, here are my settings. I am listening on port 80, I use 8080 for my tomcat server.
hosts file
127.0.0.1 local.mysite.com
httpd-vhosts.conf
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
....
<Directory "c:/wamp/www">
Options Indexes MultiViews FollowSymLinks
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Directory>
<VirtualHost *:80>
ServerName localhost
DocumentRoot "c:/wamp/www"
</VirtualHost>
<Directory "c:/wamp/www/path/to/site/root">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<VirtualHost *:80>
ServerName local.mysite.com
DocumentRoot "c:/wamp/www/path/to/site/root"
ServerAdmin me#email.com
ProxyPreserveHost Off
RewriteEngine On
AllowEncodedSlashes NoDecode
#AllowEncodedSlashes On
ErrorLog "c:/wamp/www/path/to/logs/error.log"
CustomLog "c:/wamp/www/path/to/logs/access.log" common
</VirtualHost>
....
Then I can access my local site like this: http://local.mysite.com
Hope this helps...
The NameVirtualHost directive needs to match the value of VirtualHost exactly, and you need to specify the port in each instance. If you want to use port 8088 for myphpwebsite.local, you'd need to do:
NameVirtualHost 127.0.0.1:8088
<VirtualHost 127.0.0.1:8088>
DocumentRoot "C:/xampp/htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost 127.0.0.1:8088>
DocumentRoot "C:/Microsoft/Workspace/myphpwebsite"
ServerName myphpwebsite.local
ErrorLog "C:/Microsoft/Workspace/myphpwebsite/logs/myphpwebsite.local.error.log"
CustomLog "C:/Microsoft/Workspace/myphpwebsite/logs/myphpwebsite.local.custom.log" combined
<Directory "C:/Microsoft/Workspace/myphpwebsite">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Notice the VirtualHost opening tags are identical; it's the ServerName value that actually tells Apache which domain this particular directive applies to. Restart your server after making the changes. Check out this page for more information: http://httpd.apache.org/docs/2.2/vhosts/name-based.html
Hope this helps!
Make sure that the port you are using is not being used by another service.
I have a VPS with apache2 installed and I would like to access some PHP projects without a domain name just with the IP address. For example:
http://162.243.93.216/projecta/index.php
http://162.243.93.216/projectb/index.php
I have other projects with domain like example.com, in my directory /var/www/
/html/
info.php
/projecta/
/projectb/
/example/
When I go to
http://162.243.93.216/info.php then /var/www/html/info.php is opened.
My file 000-default.conf
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
" http://162.243.93.216/info.php then /var/www/html/info.php is opened "
I am assuming this already works (If not, uncomment the ServerAlias line shown in the conf below)
You now want to map
http://162.243.93.216/projecta/ to /var/www/projecta
http://162.243.93.216/projectb/ to /var/www/projectb
For this you need to use the Apache Alias directive.
Update your 000-default.conf file to:
<VirtualHost *:80>
# ServerAlias 162.243.93.216
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
Alias /projecta /var/www/projecta
Alias /projectb /var/www/projectb
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Create a new virtual host file, and setup like this:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerAlias 192.168.1.1
DocumentRoot /somewhere/public_html
<Directory /somewhere/public_html/>
Options Indexes FollowSymLinks MultiViews ExecCGI
AllowOverride Authconfig FileInfo
Require all granted
</Directory>
</VirtualHost>
add the serveralias and it will recognize the IP address as well ...
if you want to add more IP addresses (like local network second interface), you can add more serveralias lines ...
Step Six — Set Up Local Hosts File (Optional)
If you have been using example domains instead of actual domains to test this procedure, you can still test the functionality of your virtual hosts by temporarily modifying the hosts file on your "LOCAL COMPUTER". This will intercept any requests for the domains that you configured and point them to your VPS server, just as the DNS system would do if you were using registered domains. This will only work from "YOUR COMPUTER", though, and is simply useful for testing purposes.
Note: Make sure that you are operating on your local computer for these steps and not your VPS server. You will need access to the administrative credentials for that computer.
If you are on a Mac or Linux computer, edit your local hosts file with administrative privileges by typing:
sudo vi /etc/hosts
If you are on a Windows machine, you can find instructions on altering your hosts file here.
The details that you need to add are the public IP address of your VPS followed by the domain that you want to use to reach that VPS:
127.0.0.1 localhost
127.0.1.1 guest-desktop
server_ip_address example.com
server_ip_address example2.com
reference:https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-centos-7?utm_source=Customerio&utm_medium=Email_Internal&utm_campaign=Email_CentOSDistroNginxWelcome&mkt_tok=eyJpIjoiTnpWbU5tUTJPV1F5TVRBMyIsInQiOiJhd0JCQVI0NDd0ZWprUDFaaDlhbENcL0lyTjdSbnhwMEpkTE1QcXJTcHl1ZXFhNURKVmVBZHFKMk92RW1kSFwvMHowOW0zcExhaUdyOU42U2lLbk1Cd2FRYzB4XC9lbkhlWnd1ekZOcW1sZVhRYlwvT0xrTUpmQ2dEK2dNVUw4alFrc00ifQ%3D%3D
I'm following this tutorial to learn how to start a project using ZendFramework
http://framework.zend.com/manual/1.12/en/learning.quickstart.create-project.html
When I get to setup a virtual host I get stuck. If I do exactly as the tutorial says, it shows me an error (in all my project, zend or not), says the file wasn't found.
Then I found this tutorial on StackOverflow very handy
Can't run zend framework MVC application on WAMP
Following what the guy on the bottom of the page says takes me to the same error when I try to access my app as zendProject.local/
This is what I got
on hosts (Windows/System32/drivers/etc/hosts) file
127.0.0.1 blog.local
on httpd-vhosts.conf file
<VirtualHost 127.0.0.1>
ServerName blog.local
DocumentRoot /blog/public
SetEnv APPLICATION_ENV "development"
<Directory /blog/public>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Can you tell me what I am doing wrong? The browser still says Not Found The requested URL /public was not found on this server when I go to http://blog.local/
I'm running WAMP on Windows. And this is the absolute path to the 'blog' project C:\wamp\www\blog
#Edit RiggsFolly
this is what I got now in the httpd-vhosts.conf file
<VirtualHost *:80>
ServerName localhost
DocumentRoot "C:/wamp/www"
<Directory "C:/wamp/www">
AllowOverride All
# make sure this is only allowed to be accessed by the local machine
# then if/when you open one of your other sites up to the internet and somebody uses your IP
# they will get directed here as its the first VH def and then receive a 403 not allowed to access
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName blog.local
DocumentRoot "C:/websites/blog/public"
Options Indexes FollowSymLinks
SetEnv APPLICATION_ENV "development"
<Directory "C:/websites/blog/public">
DirectoryIndex index.php
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
And I created a new directory at C:/ called 'websites' as you suggested
You need to be a little more specific with your folder locations. I guess this tutorial was written for Unix and you are using windows.
For Apache 2.2.x use this syntax:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName blog.local
DocumentRoot "C:/wamp/www/blog/public"
Options Indexes FollowSymLinks
SetEnv APPLICATION_ENV "development"
<Directory "C:/wamp/www/blog/public">
DirectoryIndex index.php
AllowOverride All
Order Allow,Deny
Allow from all
</Directory>
You would be better avoiding the Allow from all and using Allow from localhost 127.0.0.1 ::1 until you actually want to allow the universe to see your sites.
For Apache 2.4.x use this syntax:
<VirtualHost *:80>
ServerName blog.local
DocumentRoot "C:/wamp/www/blog/public"
Options Indexes FollowSymLinks
SetEnv APPLICATION_ENV "development"
<Directory "C:/wamp/www/blog/public">
DirectoryIndex index.php
AllowOverride All
Require all granted
</Directory>
Note NameVirtualHost *:80 no longer required for Apache 2.4.x
Again you would be better avoiding the Require all granted and using Require local until you actually want to allow the universe to see your sites.
EDITED After comment from Questioner:
Right, that's the Apache default. If you enter a url it cannot find a Virtual Host definition for it will default to the first Virtual Host definition you gave it, the blog in your case.
Ok, so now you need to create a Virtual Host for each of your other projects, and MOST IMPORTANTLY the first one needs to be localhost and only be allowed to be accessed from the local PC for a bit of extra security.
Now personally I would take this opportunity to move my actual sites to a totally separate folder structure outside the \wamp\ folder structure so there is no confusion with rights given to the \wamp\www folder and my other sites.
So for example, create a folder c:\websites\www and in that folder create a folder for each of your projects eg
c:\websites\www\blog
c:\websites\www\project2
Then point your virtual hosts to the relevant folder containing the site code ( this can be on another disk if you like ). This allows you to specify the Apache security ( who is allowed in to this site) specifically for each of your VHOSTS. So when you want a client or friend to be able to play with one site, you just change the security on that one site while you let them play.
Like this:
<VirtualHost *:80>
ServerName localhost
DocumentRoot "C:/wamp/www"
<Directory "C:/wamp/www">
AllowOverride All
# make sure this is only allowed to be accessed by the local machine
# then if/when you open one of your other sites up to the internet and somebody uses your IP
# they will get directed here as its the first VH def and then receive a 403 not allowed to access
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName blog.local
DocumentRoot "C:/websites/www/blog/public"
Options Indexes FollowSymLinks
SetEnv APPLICATION_ENV "development"
<Directory "C:/websites/www/blog/public">
DirectoryIndex index.php
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName project2.dev
DocumentRoot "C:/websites/www/project2"
Options Indexes FollowSymLinks
<Directory "C:/websites/www/project2">
DirectoryIndex index.php
AllowOverride All
Require local
# this site also available to other PC's on my internal network
Require ip 192.168.0
</Directory>
</VirtualHost>
Remember, for each new Virtual Host site you create you also need to add that ServerName (project2.dev) to the hosts file.
hosts file:
127.0.0.1 blog.local
127.0.0.1 project2.dev
I hope this helps.