Apache2 virtualhost ServerAlias not working - php

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.

Related

Laravel artisan serve problems

I've just installed Laravel on my vps, but I have some problems when running the command php artisan serve. It tells me that the application is running on https://127.0.0.1:8000. That means that it is running on my vps. But when I go to my vps in the browser I get this:
I've searched the whole internet for a solution and find one which tells me to create a new file: /etc/apache2/sites-available/laravel.conf and put this code in it:
<VirtualHost *:80>
ServerAdmin admin#example.com
DocumentRoot /var/www/html/development/public
ServerName subdomain.mywebsite.nl
<Directory /var/www/html/development/public>
Options +FollowSymlinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Btw, The ServerName is changed to my own website but I inserted an example here for privacy.
I also have changed the A record of the subdomain to the ip address of my vps.
After all I need to run the commands sudo a2ensite laravel.conf and sudo a2enmod rewrite
Ok, Now I need to restart my apache with sudo systemctl restart apache2.
But when I go to my subdomain is see this:
What am I doing wrong in here?

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 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

Virtual host misconfiguration with xampp on ubuntu

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

Creating a Virtual Host In PHP

I am trying to set up symfony on my Ubuntu system. Now as going through the installation tutorial of symfony I found to Create a virtual host for my (to be created) application. I did the same steps as bellow.
httpd.conf
NameVirtualHost 127.0.0.1:9090
Listen 127.0.0.1:9090
<VirtualHost 127.0.0.1:9090>
ServerName www.symfony.jobeet.lcl
DocumentRoot "/home/sfprojects/jobeet/web"
DirectoryIndex index.php
<Directory "/home/sfprojects/jobeet/web">
AllowOverride All
Allow from All
</Directory>
Alias /sf /home/sfprojects/jobeet/lib/vendor/symfony/data/web/sf
<Directory "/home/sfprojects/jobeet/lib/vendor/symfony/data/web/sf">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
And Here is My /etc/hosts file
127.0.0.1 www.symfony.jobeet.lcl
Now I restarts my lampp server and entered www.symfony.jobeet.lcl in my browser it takes me to http://www.symfony.jobeet.lcl/xampp/ this Url. If I try without using virtual host, It works fine. also when I try www.symfony.jobeet.lcl:9090 It works. I expect it should work without giving the port number. Am I doing something wrong ?
I have created the simple bash script to simplify the process of new hosts creation. So that you don't have to do anything with config files, etc. Check if you are interested here.
Creating new host is as simple as running a command from terminal $ sudo ./newhost.sh. Then you will be asked to enter desired host name.
Change this lines
NameVirtualHost 127.0.0.1:9090
Listen 127.0.0.1:9090
<VirtualHost 127.0.0.1:9090>
to
NameVirtualHost 127.0.0.1:80
Listen 127.0.0.1:80
<VirtualHost 127.0.0.1:80>

Categories