apache2 multiple virtualhost but only first one works - php

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

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?

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.

Why isn't apache2 redirecting to https, or acting how I expect with mediawiki?

I have a mediawiki site on Ubuntu 14.04, that is working perfectly, and is housed at /var/www/html
I'm trying to get https setup on the server, and I haven't been able to get that done yet. Here's my current port 80 configs, and I'll show what I'm trying below that.
/etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
ServerName mywiki.com
ServerAlias http://mywiki.com
DocumentRoot /var/www/html
</VirtualHost>
/var/www/html/LocalSettings.php
#this is the only relevant line...I think.
$wgServer = "http://mywiki.com"
The changes I'm making, in order, are below
1. Change $wgServer value to //mywiki.com
2. Edit /etc/apache2/sites-available/default-ssl.conf to the following
<VirtualHost _default_:80>
ServerName mywiki.com
Redirect permanent / https://mywiki.com
</VirtualHost>
<VirtualHost _default_:443>
ServerName mywiki.com
ServerAlias https://mywiki.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/my.crt
SSLCertificateKeyFile /etc/apache2/ssl/my.key
</VirtualHost>
3. Stop apache from using the old 000-default.conf file by running sudo a2dissite 000-default.
4. Start using the new ssl default file by running sudo a2ensite default-ssl.
5. Restart Apache2 sudo /etc/init.d/apache2 restart
At this point, apache2 restarts correctly, and there are no errors from the output or in the error.log. However, when I go to the site by typing mywiki.com it doesn't redirect me to https, and now it shows the :80 section of the site as the Index of / html/.
When I try to manually go to https://mywiki.com, I get a page not available, like it's not even trying.
Where am I going wrong?
This was a silly solution, but I imagine on a product like mediawiki, I won't be the last to make this mistake.
I never enabled the ssl module
sudo a2enmod ssl
I went through tens of tutorials on how to setup ssl on mediawiki, and none of them mentioned this. It's pretty obvious if you work on lots of websites, but I don't, and hopefully this helps someone in the future.
You are missing a ServerName. This might be it. Could you attempt this configuration:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName mywiki.com
Redirect permanent / https://mywiki.com
</VirtualHost>
<VirtualHost _default_:443>
ServerName mywiki.com
ServerAlias www.mywiki.com
DocumentRoot /var/www/html
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/my.crt
SSLCertificateKeyFile /etc/apache2/ssl/my.key
</VirtualHost>

How to point default virtual host in Ubuntu 14.04 LTS

I recently purchased linode hosting where i did successfully hosted a website. And its opening by domain-name.com and also when i enter server IP it opens default /var/www/domain-name.com/public_html
Now i want to host another site in it and created another virtual host with domain-name-2.com and enabled that and did reload my apache server.
Now when i enter again the server IP in browser like http://11.22.33.44/ it shows the first website (/var/www/domain-name.com/public_html) i hosted by default.
But i want to point some other folder so that when i hit http://11.22.33.44 it will show that folder's index.html not /var/www/domain-name.com/public_html
How to do that?
Not sure if I understand correctly, you want
http://11.22.33.44/ -> /var/www/domain-name.com/some_other_folder
http://domain-name.com/ -> /var/www/domain-name.com/public_html
Am I correct?
If that is the case, go to /etc/apach2/site-available
in 000-default.conf
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/domain-name.com/some_other_folder
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Create a new file called "domain-name.com.conf" in the same folder
Write the following into the file:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/domain-name.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
To enable virtual host, type into terminal:
$ sudo a2ensite domain-name.com
Basically 000-default.conf wasn't working as it was disabled.
enable it by following command -
sudo a2ensite 000-default.conf
I was wondering why it opening my 000-domain-name.com.conf it's because may be as default conf has been disabled so apache search for other conf file alphabetically as act that as default conf.
Also if you want to disable default conf
sudo a2dissite 000-default.conf
Both above command require apache to be restarted by following command -
sudo service apache2 restart

How Can I setup Subdomains un

I am trying to setup WordPress multi site on my ubuntu 10.04 laptop with apache2.
For normal WordPress installs in create an entry in the /etc/hosts file and create virtual hosts entry in /etc/apace2/sites-available directory and then soft link it to sites-enabled directory.
For sub domains, I added the server alias directive. But that is not doing anything. Do I have a syntax error. Please advice.
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName mysite.com
ServerAlias mysite.com *.mysite.com
DocumentRoot /home/myhome/Sites/public_html/mysite.com
#if using awstats
ScriptAlias /awstats/ /usr/lib/cgi-bin/
#we want specific log file for this server
CustomLog /var/log/apache2/example.com-access.log combined
</VirtualHost>
You must restart or reload Apache after making changes to your Apache configuration file. What does it tell you when you run:
sudo /etc/init.d/apache2 restart
Does it show you any error messages? That will tell you if you have a syntax error. For your reference, here is an example of using ServerAlias that I have on my own server. Note the difference between mine and yours. Maybe you should remove the initial mysite.com part and just leave *.mysite.com?
Let me know if that helps.
<VirtualHost *:80>
ServerAdmin jesse#domain.com
ServerAlias www.domain.com
DocumentRoot /var/www/vhosts/domain.com/httpdocs
ServerName domain.com
ErrorLog /var/log/domain.com-error_log
CustomLog /var/log/domain.com-access_log common
</VirtualHost>

Categories