Setup virtual host for intranet in apache2 – suse linux

Posted on

Setup virtual host for intranet in apache2 – suse linux – A server stack is the collection of software that forms the operational infrastructure on a given machine. In a computing context, a stack is an ordered pile. A server stack is one type of solution stack — an ordered selection of software that makes it possible to complete a particular task. Like in this post about Setup virtual host for intranet in apache2 – suse linux was one problem in server stack that need for a solution. Below are some tips in manage your linux server when you find problem about linux, virtualhost, intranet, , .

We have a websites (foldername /srv/www/vhosts/wp-intranet hosted on a server in our LAN. We need a Vhost for it so that the website is reachable at “http://192.168.20.25/intranet” and/or “http://intranet.mycompany.de

I followed the instructions in the documentation, but it does not work. This is the VirtualHost config (/etc/apache2/vhost.d/wp-intranet.conf)

<VirtualHost 192.168.20.25>
  ServerName intranet.mycompany.de
  DocumentRoot /srv/www/vhosts/wp-intranet
  ServerAdmin myname@mycompany.de
  ErrorLog /var/log/apache2/intranet.mycompany.de_errorlog
  CustomLog /var/log/apache2/intranet.mycompany.de_customlog common
  <Directory "/srv/www/vhosts/wp-intranet">
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>

I also added NameVirtualHost *:80 to /etc/apache2/listen.conf.

Then I made a hosts entry on my windows client:

192.168.20.25   intranet.mycompany.de

But if I navigate to intranet.mycompany.de from my windows computer, then the file /srv/www/htdocs/index.html opens.

I also restarted the apache service (service apache2 restart)

I hope someone can point me to the right direction. The documentation is not helpful, I followed each step but it does still not work.

In the <VirtualHost> Directive, the syntax is <VirtualHost addr[:port] [addr[:port]] ...>. While a fully qualified domain name for the IP address is supported, it’s not recommended. As Apache distinguishes the hostname from the Host: header by ServerName (and optionally with ServerAlias), you don’t need it there. Try <VirtualHost *:80>.

I finally solved it. The official documentation is missing important informations and is not up to date.

I had to include my vhost configuration file /etc/apache2/vhost.d/wp-intranet.conf in /etc/apache2/httpd.conf

IncludeOptional /etc/apache2/vhosts.d/wp-intranet.conf

Then I noticed that I am unable to restart the service apache2.

Job for apache2.service failed because the control process exited with
error code. See “systemctl status apache2.service” and “journalctl
-xe” for details.

I executed systemctl status apache2.service and got:

● apache2.service - The Apache Webserver
   Loaded: loaded (/usr/lib/systemd/system/apache2.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Tue 2018-07-10 12:59:07 CEST; 10s ago
  Process: 2017 ExecStop=/usr/sbin/start_apache2 -DSYSTEMD -DFOREGROUND -k graceful-stop (code=exited, status=1/FAILURE)
  Process: 7622 ExecReload=/usr/sbin/start_apache2 -DSYSTEMD -DFOREGROUND -k graceful (code=exited, status=0/SUCCESS)
  Process: 2008 ExecStart=/usr/sbin/start_apache2 -DSYSTEMD -DFOREGROUND -k start (code=exited, status=1/FAILURE)
 Main PID: 2008 (code=exited, status=1/FAILURE)

Jul 10 12:59:07 intern start_apache2[2008]: AH00526: Syntax error on line 8 of /etc/apache2/vhosts.d/wp-i...onf:
Jul 10 12:59:07 intern start_apache2[2008]: Invalid command 'Order', perhaps misspelled or defined by a m...tion
Jul 10 12:59:07 intern systemd[1]: apache2.service: Main process exited, code=exited, status=1/FAILURE
Jul 10 12:59:07 intern start_apache2[2017]: AH00548: NameVirtualHost has no effect and will be removed in...f:41
Jul 10 12:59:07 intern start_apache2[2017]: AH00526: Syntax error on line 8 of /etc/apache2/vhosts.d/wp-i...onf:
Jul 10 12:59:07 intern start_apache2[2017]: Invalid command 'Order', perhaps misspelled or defined by a m...tion
Jul 10 12:59:07 intern systemd[1]: apache2.service: Control process exited, code=exited status=1
Jul 10 12:59:07 intern systemd[1]: Failed to start The Apache Webserver.
Jul 10 12:59:07 intern systemd[1]: apache2.service: Unit entered failed state.
Jul 10 12:59:07 intern systemd[1]: apache2.service: Failed with result 'exit-code'.
Hint: Some lines were ellipsized, use -l to show in full.

So I figured out that the virtual host configuration from the official documentation has syntax errors. I had to change it to this:

<VirtualHost *:80>
  ServerName intranet.mycompany.de
  DocumentRoot /srv/www/vhosts/wp-intranet
  ServerAdmin edward.black@mycompany.de
  ErrorLog /var/log/apache2/intranet.mycompany.de_errorlog
  CustomLog /var/log/apache2/intranet.mycompany.de_customlog common
  <Directory "/srv/www/vhosts/wp-intranet">
    #Order allow,deny
    AllowOverride All
    #Allow from all
    Require all granted
  </Directory>
</VirtualHost>

Now I was able to restart apache2 and if I navigate to http://intranet.mycompany.de/ then the wordpress site opens!

Leave a Reply

Your email address will not be published.