Pages

Thursday, 9 October 2014

.htaccess on UbuntuServer 14.04

I had to set-up pretty quickly a web server. Unfortunately I lose time by typing those command, rather than just copy pasting in the ssh.

sudo apt-get update

sudo  apt-get install apache2 mysql-server php5 php-pear php5-mysql

With this we are done with apache. Now let us configure htacess:

In /etc/apache2
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>

Now lets generate a htpasswd file
sudo htpasswd -c /var/.htpasswd-all <username>

Create the .htaccess file. Here we filter out which files can have access, but also you can use part of the file name.

<FilesMatch "^(file1|file2|something3|something5|some7).*$">
AuthName "<username>"
AuthUserFile /var/.htpasswd-all
AuthType basic
Require valid-user
</FilesMatch>

Reload apache:
sudo /etc/init.d/apache2 reload

References:
http://www.askapache.com/htaccess/htaccess.html#Password_Protect_wp-login-php
https://help.ubuntu.com/community/EnablingUseOfApacheHtaccessFiles
http://httpd.apache.org/docs/2.2/programs/htpasswd.html