Can't add subdomain on LAMP VM Instance on Google Compute Engine - apache

I'm trying to add the blog.mydomain.com subdomain in Apache on a Google Cloud LAMP VM Instance.
In the /etc/apache2/sites-available folder there are three files: default, default-ssl, and lamp-server. I assumed lamp-server is the file being used, so I copied this file to blog.mydomain.com and edited the contents to be:
<VirtualHost *:80>
ServerName blog.mydomain.com
ServerAlias blog.mydomain.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/blog.mydomain.com/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/blog.mydomain.com/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
After saving this new file I did sudo a2ensite blog.mydomain.com and then service apache2 reload. After doing this my main website (www.mydomain.com) went down and only would show a page that says "Error establishing a database connection". This message did not come from my application.
What am I doing wrong?

This doesn't make any sense. If you add blog.mydomain.com by issuing a2ensite which creates virtualhost record in sites-available and in sites-enabled which shouldn't impact your original website unless you changes something.
If there is an entry for www.mydomain.com in the virtualhost and its goes to the right folder, you should not get "Error establishing a database connection" I'm guessing this is a wordpress instance.
Make sure your blog.mydomain.com points to the server ip address. Ping it before adding it to the servers web servers configuration.
Also get rid of these lines from the blog.mydomain.com configuration:
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
and restart the web server and load blog.mydomain.com and www.mydomain.com.
The message "Error establishing a database connection" is probably coming from the /var/www/blog.mydomain.com/ directory.

Related

Apache 2 Forbidden 403 Error despite "Require all granted"

I am getting the apparently infamous apache 2 forbidden error #403, and I tried following the guides on the subject, but none seem to be working.
I am using Ubuntu Server and Apache 2.4.41
My website structure looks like /var/www/html/index.html
My apache2.conf [/etc/apache2/apache2.conf]:
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/html>
Order allow,deny
Allow from all
Require all granted
</Directory>
My vhosts.conf [/etc/apache2/sites-available/000-default.conf]:
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
Require all granted
</Directory>
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
From an Apache standpoint, your configuration seems ok.
Please verify the permissions on your /var/www/html directory. The user that runs Apache should have at least read and traversal (x) permission.
I gave the user running Apache2 permissions to the /var/www/html folder, and was then able to access the website.
Here is a URL with several permissions, I don't know specifically which one was responsible, but I believe it was sudo chmod g+w /var/www/html
https://askubuntu.com/questions/767504/permissions-problems-with-var-www-html-and-my-own-home-directory-for-a-website

HTTP ERROR 500?

I'm trying to set up my project on xampp.
<VirtualHost *:80>
ServerAdmin test#test.biz
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs/test/public"
ServerName testproject.dev
ErrorLog "logs/dummy-host2.example.com-error_log"
CustomLog "logs/dummy-host2.example.com-access_log" common
<Directory "/Applications/XAMPP/xamppfiles/htdocs/test/public">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
I uncomment line in httpd.conf for virtual hosts, but stil im getting error 500. Any suggestion? I m using MAC OS.
Also in hosts i added:
127.0.0.1 testproject.dev
Any suggestion?
It's impossible to help you without checking the log. You should enable Apache HTTP Server's logging and check the events. I guess that the log in your case is dummy-host2.example.com-error_log. Look through the events and find out what's wrong with this configuration.

Can't configure virtual host in apache ubuntu

I've tried to configure virtual host on apache for project on laravel. For this I created file in /etc/apache2/sites-available/app.conf:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName app
DocumentRoot /var/www/html/app/public
<Directory />
Options All
AllowOverride All
</Directory>
<Directory /var/www/html/app/public>
Options All
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
ServerSignature On
</VirtualHost>
Then I've activated the host:
sudo a2ensite app.conf
And had following message in the terminal:
Enabling site app.
To activate the new configuration, you need to run:
service apache2 reload
Then I reloaded it
Also I've modified the '/etc/hosts':
127.0.1.1 Alexandra
127.0.0.1 app
So, now when i go on app/ in browser, it shows me folders of the project:
Index of /
app/
laravel/
project/
site/
Now if I want to display 'welcome page', I should go to app/app/public
Where is mistake in my configuration process?
Your app.conf should be edited to:
DocumentRoot /var/www/html/app/public/app/public
It appears you installed laravel in /var/www/html/app/public/app
UPDATE
You probably have the default site's DocumentRoot set to /var/www/html. If this is the case, then please:
Install laravel in:
/var/www/app
Define it's DocumentRoot as:
/var/www/app/public
Restart apache
sudo service apache2 restart

Stop Apache from serving content from apache root directory

I noticed this by chance earlier and after a quick Google, really couldn't find anything to help. I'm genuinely having trouble even explaining the problem!
When I access http://mydomain.com/error/README I appear to be getting the error readme found in /var/www/error/README. My virtual host for mydomain.com is document root is pointing to /var/www/html/mydomain, and /var/www/html/mydomain/error/ does not exist.
Naturally I feel this shouldn't be happening and although I haven't been able to replicate it, my main concern is that a user could in fact access anything off of /var/www/ not just /var/www/error/
Linux version: CentOS release 6.5 (Final)
Apache version: Apache/2.2.15
My virtual host file is:
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName mydomain.com
ServerAlias www.mydomain.com
DocumentRoot /var/www/html/mydomain
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/html/mydomain/>
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
LogLevel error
CustomLog /var/log/httpd/mydomain_access.log combined
ErrorLog /var/log/httpd/mydomain_error.log
</VirtualHost>
Naturally I feel this shouldn't be happening and although I haven't been able to replicate it, my main concern is that a user could in fact access anything off of /var/www/ not just /var/www/error/
You probably have the following directive in your httpd.conf:
Alias /error/ "/var/www/error/"
This just redirects all your error queries to /var/www/error (e.g. if you need www.example.com/error/README it would redirect me to one of the README in that director). Removing the alias should fix your problem.
If you are concerned about access to your other directories then I, as a complete newbie to apache, would recommend.
Auditing your httpd.conf and removing any aliases that you don't need.
Modifying your containers to have "Deny from all" and "AllowOverride None" in all of them.
If you have selinux enabled, then remove the httpd security contexts from those directories.

Apache2 host two sites on the same server

I am trying to host subversion and wiki on the same site.
I have created two files in /etc/apache2/sites-available
in "subversion"
I have
<VirtualHost -myserverIP-:80>
ServerAdmin webmaster#localhost
ServerName svn.example.com
DocumentRoot /var/svn/repos
<Location /svn/repos>
DAV svn
SVNPath /var/svn/repos
AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /etc/apache2/passwords
Require valid-user
</Location>
</VirtualHost>
and in "wiki" I have
<VirtualHost -myserverIP-:80>
ServerAdmin webmaster#localhost
ServerName wiki
ServerAlias -myserverIP-
DocumentRoot /home/www/wiki/html
<Directory /home/www/wiki/html>
AllowOverride None
Options -Indexes -MultiViews -SymLinksIfOwnerMatch +FollowSymLinks
Order allow,deny
allow from all
</Directory>
<Location /wiki>
</Location>
<DirectoryMatch "^/home/www/wiki/html/(data|conf|bin|inc)/">
Order allow,deny
Deny from all
Satisfy All
</DirectoryMatch>
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
ErrorLog /home/www/wiki/logs/error.log
CustomLog /home/www/wiki/logs/access.log combined
</VirtualHost>
However now, when I browse to the IP address of the server, I get the contents of the /var/svn/repos directory, wheras when I just had the wiki page, I got the wiki index page. I can actually go to -IPaddress-/svn/repos and see the SVN repository, but -IPaddress-/wiki does not work.
Thanks for the tips
Both your virtual hosts are on port 80 on the same machine. Apache can only guess which one you want to use. It is guessing the subversion one and browsing to the DocumentRoot specified.
You need to differentiate the virtual hosts, or browse to the server using the server name rather than IP.
Instead you could setup the SVN location inside your other virtual host.
Also consider using /etc/apache2/mods-available/dav_svn.conf depending on your Operating System.
However now, when I browse to the IP address of the server, I get the contents of the /var/svn/repos directory, wheras when I just had the wiki page, I got the wiki index page. I can actually go to -IPaddress-/svn/repos and see the SVN repository, but -IPaddress-/wiki does not work.
When you make a request to apache and the hostname you are using isn't defined by any ServerName or ServerAlias in any of the vhosts, apache returns the default vhost, which is always the first vhost in the file (or in the file with the name that's the smallest lexiconical order, e.g. 00-default_vhosts.conf). In your case, your SVN vhost is first so it is the "default" vhost. If you swap the 2 around the other one would be the "default" vhost.