trueCamelType trueCamelType - 3 months ago 11
PHP Question

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?

Answer

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.