Virtual host misconfiguration with xampp on ubuntu - php

I have Linux Ubuntu 13.10LTS installed on my computer with XAMPP 1.8.2. I am trying to add a virtual host and I am done. But when i enter www.example.com in the address bar it shows www.example.com/xampp which is not desired by me.
below is the configurations I used to create that:
httpd-vhosts.conf:
<VirtualHost *:80>
ServerAdmin root#example.com
DocumentRoot /var/www/example.com/public_html/
ServerName www.example.com
</VirtualHost>
/etc/hosts:
127.0.0.1 localhost
127.0.1.1 mustafa-Latitude-E5430-vPro
127.0.1.1 www.portal.com
what is the problem?

You need to add www.example.com to your /etc/hosts file:
127.0.1.1 www.example.com

Allow the usage of custom virtual hosts
sudo gedit /opt/lampp/etc/httpd.conf
Uncomment below line from httpd.conf by removing "#"
Include etc/extra/httpd-vhosts.conf
3.Create a custom domain in the hosts file of your system
sudo gedit /etc/hosts
4.Add Below line in hosts fils
127.0.0.5 www.myawesomeproject.com
5.Create your first virtual host
sudo gedit /opt/lampp/etc/extra/httpd-vhosts.conf
<VirtualHost 127.0.0.5:80>
DocumentRoot "/opt/lampp/htdocs/my-first-project"
DirectoryIndex index.php
<Directory "/opt/lampp/htdocs/my-first-project">
Options All
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Restart server by using below command.
sudo /opt/lampp/lampp restart

Related

MAMP all virtual hosts point to htdocs folder

I've read through all the questions I could find but none of them have worked for me. I'm trying to set up a couple of virtual hosts on my MAMP apache install. Currently, typing localhost takes me to my htdocs as expected. However, typing mysite.dev should take me to another directory but it instead drops me off at htdocs.
hosts
##
# Host Database
#
#
# localhost is used to configure the lookback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
127.0.0.1 mysite.dev
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
I've uncommented in httpd.conf
# Virtual hosts
Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
And I've set up my httpd-vhosts.conf a bunch of different ways with the same result. The current state is:
# Use name-based virtual hosting.
#
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin mysite.dev
DocumentRoot "/Applications/MAMP/htdocs/mysite/public"
ServerName mysite.dev
ServerAlias www.mysite.dev
ErrorLog "logs/mysite.dev"
CustomLog "logs/mysite.dev" common
</VirtualHost>
Any help would be greatly appreciated. Thanks!
You might miss some steps. First of all
run mamp with apache 80 and mysql 3306 port. this will automatically change the httpd.conf file with those port. close mamp
go to httpd.conf and go to line: 575 and uncomment this line from
# Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
to
Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
If it is not line 575 search with the text and u will find the line.
Next in httpd-vhosts.conf, add your virtual urls/hosts. sample below
<VirtualHost *:80>
DocumentRoot "/Applications/MAMP/htdocs/Project"
ServerName dev.project.com
ServerAlias www.dev.project.com
</VirtualHost>
dev.project.com is just sample and you can name it however you want. server alias is optional but better to keep it just likeserver name but with an extra "www." as it is shown above.
next add those to hosts file like
127.0.0.1 dev.project.com
better to add all possibilities like below
127.0.0.1 dev.project.com http://dev.project.com www.dev.project.com http://www.dev.project.com
save the hosts file and restart mamp. Cheers!!!
I THINK YOU GUYS MISSED STEP 2

Apache virtual hosts doesn't work

I would want to setup virtual hosts, on my apache.
sudo a2enmod vhost_alias -> Module vhost_alias already enabled
i have this 2 files:
/var/www/test/index.php and /var/www/test2/index.php
And i want to load them respectivly
http://test.local/ and http://www.test.local/
or
http://test2.local/ and http://www.test2.local/
my conf file: (/etc/apache2/sites-enabled/000-default.conf)
UseCanonicalName Off
<VirtualHost *:80>
ServerAlias *.local
VirtualDocumentRoot /var/www/%1+
</VirtualHost>
VirtualDocumentRoot /www/hosts/%0/docs
VirtualScriptAlias /www/hosts/%0/cgi-bin
I don't undestand what i'm doing wrong, help me please. I am googling for 2 days but nothing. I have readed http://httpd.apache.org/docs/2.0/vhosts/mass.html but it doesn't help me.
Could you tell me how i should config my files?
Did you add in your /etc/hosts file this lines ?
127.0.0.1 test.local
127.0.0.1 www.test.local
127.0.0.1 test2.local
127.0.0.1 www.test2.local
EDIT
Try with this config:
<VirtualHost *:80>
ServerName test.local
DocumentRoot /var/www/test
<Directory "/var/www/test/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
Until this works try just with one domain, then you will configure the aliases for the others one
Then save this file in /etc/apache2/sites-available/test.local.conf
Then
sudo a2ensite test.local.conf
sudo /etc/init.d/apache2 reload
go to http://test.local

Apache2 virtualhost ServerAlias not working

I am using Laravel 5.4 .(Apache 2.4.8)
/etc/hosts:
127.0.0.1 project.local
/etc/apache2/sites-available/project.conf
<VirtualHost *:80>
DocumentRoot /var/www/html/project/public
ServerName project.local
ServerAlias *.project.local
<Directory /var/www/html/project/public>
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from all
</Directory>
commands:
sudo nano /etc/hosts
sudo nano /etc/apache2/sites-available/project.conf
sudo a2ensite project.conf
sudo service apache2 reload
project.local ~> Works
somesubdomain.project.local or www.project.local ~> Not working .
Any help ? Thanks.
You still need to add an entry in your hosts file for every subdomain you want to hit:
/etc/hosts
127.0.0.1 project.local www.project.local somesubdomain.project.local
Please note that the hosts file does not support wildcard domains. For example:
127.0.0.1 *.project.local # WILL NOT WORK
There is another answer on stackoverflow here that suggests using DNSMASQ to achieve what you are trying to do. Otherwise you may want to consider setting up a DNS server. (See BIND or PowerDNS). Depending on how much network access you have, your router may be able to help out too.

Virtual host redirecting to the xampp folder, but only getting This site can’t be reached

I know I'm probably missing something simple, but I've exhausted all resources trying to get this working.
I'm running my Apache on Port:5000 and trying to direct to lsapp.dev instead of http://localhost:5000/lsapp/public/ with:
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/lsapp/public"
ServerName lsapp.dev
</VirtualHost>
I have tried VirtualHost *:5000 but still can't get it work?
you can use this on command line in your project root
php artisan serve --port=your_port_number
or do this:
edit httpd-vhosts.conf that is located in C:\xampp\apache\conf\extra\httpd-vhosts.conf and add following lines at the end of the file:
# VirtualHost for LSAPP.DEV
<VirtualHost lsapp.dev:80>
DocumentRoot "C:\xampp\htdocs\lsapp\public"
ServerAdmin lsapp.dev
<Directory "C:\xampp\htdocs\lsapp">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
our apache is listening to lsapp.dev connections, but we have to configure our hosts file that allows to redirect lsapp.dev to the localhost that is located in C:\Windows\System32\drivers\etc
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.1 lsapp.dev
Set your Virtual host file like this.
<VirtualHost *:80>
DocumentRoot "D:\laravel Task\laravel\blog" //here set your project storage path
ServerName localhost.test.com // set your url for your project
<Directory "D:\laravel Task\laravel\blog"> // again set your project storage path
AllowOverride All
Order allow,deny
Allow from all
Require all granted
set your hosts file like this
127.0.0.1 localhost.test.com
Now you can Run your project
localhost.test.com
//OR//
If you dont want to use virtual host, then you can run your project like this
goto your project folder=>
command line in your project root=>php artisan serve
your project will run in
http://127.0.0.1:8000/

apache2 multiple virtualhost but only first one works

I am running Apache/2.4.12 on Ubuntu and I added 2 .conf files in the /etc/apache2/sites-available/ folder, and enabled them. Both sites are using the same Symfony PHP files.
aaa.conf
Listen 8080
<VirtualHost *:8080>
ServerName local.aaa.com
ServerAlias www.local.aaa.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/aaa/web
<Directory "/var/www/html/aaa/web">
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/aaa_error.log
CustomLog ${APACHE_LOG_DIR}/aaa_access.log combined
</VirtualHost>
bbb.conf
Listen 8081
<VirtualHost *:8081>
ServerName local.bbb.com
ServerAlias www.local.bbb.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/bbb/web
<Directory "/var/www/html/bbb/web">
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/bbb_error.log
CustomLog ${APACHE_LOG_DIR}/bbb_access.log combined
</VirtualHost>
The problem I am having is that after a service apache2 reload only the first site that I open works. So for example:
1st scenario
- I do the reload
- I open local.aaa.com:8080 it works
- I open local.bbb.com:8081 it doesn't work, I get a PHP Fatal error: Class 'AppBundle\\AppBundle' not found
2nd scenario
- I do the reload
- I open local.bbb.com:8081 it works
- I open local.aaa.com:8080 it doesn't work, I get a PHP Fatal error: Class 'AppBundle\\AppBundle' not found
EDIT
#Ryan Vincent:
netstat -a shows both sites runnnig
All your Listen directives should be in the main apache configuration file provided by Ubuntu(/etc/apache2/apache2.conf).
The sites-enabled folder must only contain the proper symbolic links generated with a2ensite to sites-available, which is where you have to place your virtualhost configurations.
Once you moved them there, enable every virtualhost and reload apache.
sudo a2ensite aaa.conf
sudo a2ensite bbb.conf
sudo service apache2 reload
I had the same problem.
It has been solved by adding a rule on my firewall (UFW).
The ports i use are 18180 and 18181.
Connexion on port 18180 was OK, but not with 18181.
I tried with UFW disabled, but it didn't work, so i decided to add the rules "allow 18181/tcp" and "allow 18181/udp" and the problem is solved.
It's weird it didn't work with UFW disabled, but it's like that lol
I hope this will help

Categories