Issue with Virtual Host on Zend Server CE and Mac OSX - macos

I'm using Zend Server CE 5.6.0 on Mac OSX.
My httpd.conf has the following line, adding the virtual hosts file:
Include conf/extra/httpd-vhosts.conf
At that file, I have the following:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName localtextil.drupal.lh
DocumentRoot /usr/local/zend/apache2/htdocs/Obiz/LocalTextil-Portal/drupal
</VirtualHost>
So, by definition, when I try to access localtextil.drupal.lh, it should redirect me to its document root.
The problem is, when I try to access that host, I got an error.
And when I simply access localhost, I go to the site located on /usr/local/zend/apache2/htdocs/Obiz/LocalTextil-Portal/drupal.
What am I doing wrong here?

Two things - first is that the virtualhost definitions (as I understand it) override apache's mappings between directories and servernames. The first defined virtualhost is what apache will use as a default when it can't find a map - so it should be a generic setup (reflecting your original domainname, in your case, localhost) first, then your specific setup following it.
Second is that if your folder is outside of where you have given apache permissions to read, then you may get an error. The directory permissions are set by a DocumentRoot directive - however:
Now when a request arrives, the server will first check if it is using an IP address that matches the NameVirtualHost. If it is, then
it will look at each section with a matching IP address
and try to find one where the ServerName or ServerAlias matches the
requested hostname. If it finds one, then it uses the configuration
for that server. If no matching virtual host is found, then the first
listed virtual host that matches the IP address will be used.
As a consequence, the first listed virtual host is the default virtual
host. The DocumentRoot from the main server will never be used when an
IP address matches the NameVirtualHost directive. If you would like to
have a special configuration for requests that do not match any
particular virtual host, simply put that configuration in a
container and list it first in the configuration file.
The Apache document page on name based virtual hosting is here, it should help give some ideas. Basically you need to look at the definitions you have for DocumentRoot and the servernames, and go through them making sure they are all "ok".

Related

Alias in virtual host using xamp in Laravel 5.6 project

I created a virtual host in xampp for my Laravel 5.6 project.
I did this way:
I added 127.0.0.1 project.com in the hosts file in
C:\Windows\System32\drivers\etc
I changed the port 80 to 8003 in the httpd.conf file in C:\xampp\apache\conf (I changed everything from 80 to 8003 in this file)
I added this:
<VirtualHost *:8003>
DocumentRoot "C:/xampp/htdocs/project/public"
ServerName project.com
</VirtualHost>
in the httpd-vhosts.conf in C:\xampp\apache\conf\extra
I would like to use an alias because I do not want to use the url with the number port at the of the url. I just can access with this url: http://project.com:8003.
I want to enter to my project with the url like this: http://project.com
If you don't want to specify the port, you'll have to use port 80, as it's the standard for the http:// scheme. The browser doesn't magically know on what port a given service is running nor it scans all of them.
Also, the .dev tld is also a real domain and will most likely cause problems.

How To Set Up Apache Virtual Hosts on XAMPP (Windows) [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
The community reviewed whether to reopen this question 1 year ago and left it closed:
Original close reason(s) were not resolved
Improve this question
How To Set Up Apache Virtual Hosts on XAMPP (Windows)
##Full guideline to make VHOST (Virtual Host) on XAMPP/WAMP
Note: To start with, the only difference for this guideline, between XAMPP and WAMP or other Apache packages for Windows, is question where those packages are installed on your computer.
Introduction: vhost (virtual host) is a great solution if you intend to develop many independent project in php and keep them isolated from each others, like:
Project 1 is based on php and has local url address php.localhost
Project 2 is a Laravel project with url laravel.localhost
Project 3 is a Codeigniter with url codeigniter.localhost
Project 4 is a WordPress with url wordpress.localhost
You are expected to have installed the latest version of XAMPP/WAMP. Btw, in my case, I have only installed Apache and MySQL.
*Note: By default, most web servers will uses port 80 as default port, in some situation if you have another web server installed like (Microsoft IIS), it uses port 80 as well OR in other cases SKYPE does also some times use port 80 like it is the case for some in Windows 8/10 for some users, in that case you can do two thing’s
Change your Apache port to port 8080, 8081 etc. or some other free ports (note: 8080 can some times also give some problems)
OR Change your others software/IIS port and keep Apache to default port 80 in case of Skype, just kill the Skype app and restart it after installing Apache on port 80, Skype will automatically get new port.
I have chosen to change my Apache to port 8080.
Note:
For next section, we need to use text editor like notepad or regular IDE. I used sublime text editor.
If you keep Apache to default port 80, skip this part and move on to Virtual hosts
Change XAMPP/WAMP port (only if necessary)
if left default, then jump to Setting virtual host
Step 1. Edit httpd.conf
Click on Config -> Apache (httpd.conf)
Or you find the file here C:\XAMPP\apache\conf\httpd.conf, C:\XAMPP\apache2\conf\httpd.conf, C:\Bitnami\wampstack\apache\conf\httpd.conf or C:\Bitnami\wampstack\apache2\conf\httpd.conf or similar location.
Change the line with
Listen 80
To 8080 or other, free ports.
Listen 8080
While we have httpd.conf file open we need to ensure that httpd-vhosts.conf is included:
Include conf/extra/httpd-vhosts.conf
Virtual hosts
Note: By default server documents are locate on C:\XAMPP\htdocs or C:\Bitnami\wampstack\apache2\htdocs that’s fine if you have only one project or many small test files. However, if you need to develop many projects then it suggested separating them by virtual host, as mentioned earlier.
Step 2. Setting Virtual host
Create a folder for your projects; I have create one in c:\vhost you can call it projects etc.
In c:\vhost folder we create a sub-folder domain1 or project1 or any other, it is up to you (c:\vhost\project1)
Open httpd-vhosts.conf file C:\XAMPP\apache\conf\extra\httpd-vhosts.conf Add following code in line depending on how many vhost you want to create:
<Directory C:/vhost>
AllowOverride All
Require all granted
</Directory>
#this is the default address of XAMPP
<VirtualHost *:8080>
DocumentRoot "C:/XAMPP/htdocs/"
ServerName localhost
</VirtualHost>
#this is the first vhost address in XAMPP
<VirtualHost *:8080>
DocumentRoot "C:/vhost/project1/"
ServerName php.localhost
SetEnv NS_ENV variable_value
</VirtualHost>
#this is the second vhost address in XAMPP for project like Laravel
<VirtualHost *:8080>
DocumentRoot "C:/vhost/Laravel-Blog/public"
ServerName laravel.localhost
</VirtualHost>
etc
Note: If you work on Laravel projects you can create unlimited Laravel projects as well as other frameworks like codeigniter, Yii, etc., the point is to
have your Laravel project/s on c:\vhost\laravel1,
c:\vhost\laravel2 etc and make c:\vhost\laravel1\public as
DocumentRoot etc as showed before. Each Laravel project will have own
VirtualHost URL.
Save and close the file
Some additional information and notes:
If port is remain default 80 then the URL address will be localhost
If port is remain default 80 then the the VirtualHost tag should be changed to <VirtualHost *:80>
If port is changed to 8080, the URL address will be localhost:8080
And the vhost URL address could look like this project1.localhost:8080 etc
You can add unlimited projects and virtual host like this way.
We are not ready yet, read more.
Step 3. Edit Windows Host file
Stop Apache and MySQL services from XAMPP/WAMP.
Open hosts file in C:\windows\system32\drivers\etc
you need Administrator privilege to edit the file.
I suggest to edit the file directly with Sublime text editor.
Add 127.0.0.1 project1.localhost at the end of the file, Save and close the file.
127.0.0.1 localhost
127.0.0.1 php.localhost
127.0.0.1 laravel.localhost
127.0.0.1 codeigniter.localhost
127.0.0.1 wordpress.localhost
127.0.0.1 laravel2.localhost
etc. those are just examples
save the file
Final Step.
Start/Re-start your Apache and MySQL again.
**Addition (Suggestion)**
Note: Under you development process you might face problem having cache on, because you can risk updating some thing in Laravel and it won't appear in your browser. Therefore you might need to disable php cache under development process in your local environment.
Open file php.ini under php folder in your Apache (XAMPP or WAMP) folder and
change opcache.enable to 0 so it looks like this:
[opcache]
zend_extension=php_opcache.dll
; Determines if Zend OPCache is enabled
opcache.enable=0
Addition (Alternative solution)
Important: The following solution is not suitable to test Restful Api, canvas, heavy solutions, etc.it might give you some headaches, I would suggest virtual host solution with port 80 as default.
It is possible to deploy temporary Virtual Server with out necessarily configuring XAMPP/WAMP Virtual Host, start CMD console and run following php command:
php -S localhost:8001 -t c:\vhost\Laravel-Project\public
Port 8001 can be change to any available port number and be sure not conflicting with other software ports.
c:\vhost\Laravel... path should be changed to whatever your project path.
It is possible to start multiple servers but should have different port numbers.
In your browser you need only to write
http://localhost:8001/
Note on 403 Access forbidden error
If you get a 403 Access forbidden error when you browse to your site, you may need to add this to your httpd.conf file:
<Directory path_to_dir>
AllowOverride none
Require all granted
</Directory>
You can make your localhost to point to different folders on different port numbers. Follow these simple steps:
Step 1: Make your apache to listen to multiple ports. Go to C:\xampp\apache\conf\httpd.conf and search for the key word Listen you can see something like this Listen 80. Now tell your apache to listen to multiple ports, replace that with below content
Listen 80
Listen 8001
Listen 8002
Step 2: Now go to “C:\xampp\apache\conf\extra\httpd-vhosts.conf”, this is the actual player. At the end of the file you can specify something like this below:
DocumentRoot "C:/xampp/htdocs/project1"
ServerName localhost:8001
DocumentRoot "C:/xampp/htdocs/project2"
ServerName localhost:8002
Which tells your apache to take different folders on hitting different port numbers. That is when you hit localhost:8001/ it will take the contents from project1, similarly localhost:8002/ will point to your project2 folder.
By doing this we and run 2 different sites on our local machine.
Note: You need to restart your apache whenever you change something in httpd.conf or httpd-vhosts.conf.
Virtual Host create
C:\xampp\apache\conf\extra
Open httpd-vhost file then
Add
DocumentRoot "C:\xampp\htdocs\project\timegrid\public"
ServerName mytimegrid.me(ur choice)
C:\Windows\System32\drivers\etc
Open hosts file then add 127.0.0.1 mytimegrid.me(Your Domain Name)
N.B. you first open your editor(notepad etc....) as Run As Administrator mode otherwise you can not save these files. ok.
First of all, open your Notepad as an Administrator and
then click on file > open. Then go to your window driver now search for system32 folder and then search for drivers folder and then the etc folder.
Now you'll see a folder of empty files, so don't worry to see Text Documents (*.txt) at the bottom. Change the view to all files and then you will see the vhost file.
Open and enjoy!

I cann't call my localhost by ip address

I am trying to call my xampp localhost from another computer's browser, I have changed host file at C:\Windows\System32\Drivers\etc by appending (192.168.1.105 localhost) at the end this file and save it and then restart computer, but I could not call my localhost from another computer.
Thanks
You need to access port forwarding in your router and forward port 80 only as TCP. Also, the host file code should look something like YOUR IP YOUR IP and not YOUR IP localhost. Furthermore, you need to edit httpd-vhosts.conf from apache folder in xampp instalation with something like that
<VirtualHost *:80>
ServerAdmin whatever#whatever.com
DocumentRoot "PATH TO YOUR FOLDER"
ServerName YOUR IP
ServerAlias YOUR IP
</VirtualHost>
After that you must restart apache in XAMPP control panel (MySQL not necessary)
THE SOLUTION ABOVE WILL LET YOU SEE YOUR CONTENT FROM ANYWHERE AS LONG AS YOUR LOCAL PC IS TURNED ON AND HAVE INTERNET CONNECTION. THE SOLUTION BELOW (I DIDN'T TEST IT, BUT I GUESS IT WILL WORK) WILL LET YOU ACCESS YOUR CONTENT FROM LOCAL NETWORK ONLY.
edit your httpd-xampp.conf file as following and after that you should probably need to perform a browser cache cleaning
# New XAMPP security concept
#
<LocationMatch "^/(?i:(?:xampp|security|licenses|phpmyadmin|webalizer|server-status|server-info))">
Order deny,allow
#Deny from all
#Allow from 127.0.0.0/8
Allow from all
ErrorDocument 403 /error/HTTP_XAMPP_FORBIDDEN.html.var
</LocationMatch>
When you add 192.168.1.105 localhost on the other PC (the one you want to use to view your website), it will look for a website on the same machine. Delete the entry from the hosts file and enter the IP address in your browser and it should work if the webserver is running.

Joomla installation - access denied 403

I can already tell that I'm probably doing something hideously wrong, but I just can't get anything to work or even acknowledge me.
I have a working Joomla 1.5 site on a localhost setup on a lamp stack with Ubuntu (newest everything). I am working on upgrading the site to a newer version. I've followed the steps on the joomla site, which are simple, just extract the zip file on the server, just like I did for 1.5, and then go to the site. I am doing this in a subdirectory I've called upgrade, physically located at /var/www/upgrade/ and when i try to go to localhost/upgrade, I get a "FORBIDDEN" 403. I tried localhost/upgrade/administrator, localhost/index.php, localhost/administrator/index.php, and even localhost/installation/index.php and nothing works.
I went into the installation/ dir and made and saved the configuration.php and .htaccess in upgrade/ to no avail and as a last resort I even did a chmod -R 777 * (yeah I know), restarted apache but nothing changes.
Just to see if it was the install, I dl'd Joomla 3.2 and got the exact same result. All the while my 1.5 site is still happily working.
What am I doing wrong?
You want to setup a Virtual host for the new site. You can do this with either a port or a host.
So if you have your Apache conf setup correctly you can add another Virtual host with something along the lines of.
<VirtualHost *:80>
DocumentRoot /var/www/upgrade
ServerName upgrade.local
</VirtualHost>
You'll also need to add a hosts entry which points to your localhost/IP. Its worth checking out a good guide on setting all this up as theres quite a few steps. The Ubuntu one is pretty good if your on that Distro.
https://help.ubuntu.com/community/ApacheMySQLPHP
Specifically the bit on Virtual Hosts
ServerName means that the server will listen for hosts with that name. So, if you have a host such as upgrade.local pointing to your server then the VirtualHost entry will pick that up and point it to the directory /var/www/upgrade.
In order to point a local host to your server you need to add it to your machines hosts file. To add a new host like upgrade.local (you can call it whatever you want) you edit /etc/hosts and set the IP it points to.
127.0.0.1 upgrade.local
ServerName is not mandatory but I find it better as its easier to organise your local host sites.
The alternative is to do it by port (which means you can avoid having to change the hosts file). You need to listen for the port in this case.
Listen 3000
<VirtualHost *:3000>
DocumentRoot /var/www/upgrade
</VirtualHost>

VirtualHosts does not work on Mac OS 10.7

I want to create VirtualHosts on Mac OS 10.7 and therefore I edited the /etc/apache2/httpd.conf. I uncommented the line "Include /private/etc/apache2/extra/httpd-vhosts.conf" to include the virtual hosts. In the file /private/etc/apache2/extra/httpd-vhosts.conf I wrote the following:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "/var/www"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/var/www/someFolder"
ServerName myApplication.dev
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/var/www/someOhterFolder"
ServerName myApplication2.dev
</VirtualHost>
There were two example virtual hosts before which I deleted. In my /etc/hosts file I added the following:
127.0.0.1 myApplication.dev
127.0.0.1 myApplication2.dev
I restarted my Apache and typed myApplication.dev and myApplication2.dev in the browser but I get an error "server not found" and it makes www.myApplication.dev in the browser (the same for myApplication2.dev).
Did I forget something to configure? I activated PHP in httpd.conf, mysql is installed also, but that has nothing to do with virtual hosts, I think.
Thanks for your help!
apachectl has an option -S to check vhost.conf file syntax. You can find these lines in vhosts.conf file.
> # You may use the command line option '-S' to verify your virtual host
> # configuration.
So, when you run
sh-3.2# apachectl -S
if you get Syntax OK result it means that there is no problem in your vhosts.conf file.
httpd: VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80 is a NameVirtualHost
default server zz.xxxx.com (/private/etc/apache2/extra/httpd-vhosts.conf:27)
port 80 namevhost zz.xxxx.com (/private/etc/apache2/extra/httpd-vhosts.conf:27)
port 80 namevhost yy.xxxx.com (/private/etc/apache2/extra/httpd-vhosts.conf:35)
Syntax OK
If conf file has any problem it will tell you error line(s) like
sh-3.2# apachectl -S
Syntax error on line 33 of /private/etc/apache2/extra/httpd-vhosts.conf:
CustomLog takes two or three arguments, a file name, a custom log format string or format name, and an optional "env=" clause (see docs)
make sure that your vhosts.conf file has true configuration.
I had the exact same problem using OS X Lion. I fixed it by adding "::1 myhost.dev" to /etc/hosts:
127.0.0.1 myhost.dev
::1 myhost.dev
Incidentally, the ::1 also fixes a bug that makes page loading very slow on virtual hosts served from the Mac.
Are you using an HTTP proxy? If so, make an exception for myApplication.dev and myApplication2.dev.
What I meant was that the problem "server mot found" means that your browser cannot find the ip adresses of the hosts "myapplication.dev". This may be because you're using an http proxy, possibly one configured by your hosting company. In any case, you don't even reach the server, so you never get to try the virtual host configuration at all.
To just try the virtual host configuration, you can use telnet in a Terminal window and talk HTTP directly to the server, like this:
yourmacbox:~ yourname$ telnet 127.0.0.1 80
You should see the following text:
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Then you type
GET / HTTP/1.0
Host: myApplication.dev
Now, hopefully you should see some response from your web server. This shows that once you can connect to it, the virtual hosts things works.
I had the same problem, and noticed that the ServerRoot "/usr" was set as shown and incorrectly after the 10.7 upgrade. The httpd.conf file was still under /etc/apache2, but this setting in it was pointing to the wrong place. Once I had fixed that by changing to ServerRoot "/etc/apache2", all my previous virtual host configuration got picked up properly.
I also had to re-enable virtual hosts by uncommenting line 477 as mentioned here http://brettterpstra.com/fixing-virtual-hosts-and-web-sharing-in-mountain-lion/ That didn't quite kick in until I had fixed the path issue above.

Resources