2

Is there a very simple way of creating password access using .htaccess whilst testing. I don't want to do anything that would interfere with the application. Is there a way of doing this within OpenShift?

disruptive
  • 5,687
  • 15
  • 71
  • 135

1 Answers1

4

You can use password protection with .htaccess and .htapasswd to avoid public access on your site while it's not yet launched.

In your .htaccess add these:

AuthUserFile /absolute/path/to/your/.htpasswd
AuthType Basic
AuthName "Just testing"
Require valid-user

Then you need the password file. You can create it with this unix command:

htpasswd -c /absolute/path/to/your/.htpasswd testusername

You will be asked for the password for this user and the .htpasswd file will be created for you with the credentials. The password is stored hashed.

Without -c you can add further users to existing files:

htpasswd /absolute/path/to/your/.htpasswd nextusername

For access you can submit auth data within url. Most browser support that, some gives you a warning about phishing:

http://testusername:password123@www.example.com/
Sven R.
  • 1,049
  • 17
  • 24
  • Thanks. Where should I put the file on OpenShift? I have tried this in the repo directory and restarted the app, but it doesn't appear to work right. – disruptive Jul 14 '14 at 19:25
  • Can you put the file in the same directory as the .htaccess? The path to the .htpasswd must be an absolute path. – Sven R. Jul 14 '14 at 19:34
  • I have tried this. I worry that its OpenShift issue as the absolute path is something like: /var/lib/openshift/6857643785658746/app-root/repo/html I worry that the path changes i.e. 6857643785658746 – disruptive Jul 14 '14 at 20:01
  • Okay, and do you have access to others directories? Can you put it into /home/someuser/ or even better into /var/lib/openshift/? The concrete path doesn't matter, it just have to be absolute. – Sven R. Jul 14 '14 at 20:12
  • Any other stable directory? – Sven R. Jul 14 '14 at 20:57
  • Hmm thats a tough one - I can put it in repo but I that doesn't seem to work. I cannot write into var/lib/openshift/6857643785658746 either. – disruptive Jul 14 '14 at 21:06
  • Where do you place the .htaccess on a standard apache + mod_wsgi deployment? – caliph Jul 06 '16 at 12:39
  • I want to add another thing, you can check if the apache2.conf has the .htaccess enabled if it's not you wouldn't be able to make it work. To enable .htaccess you must put `AllowOverride All` under then above answer will work as it is. – Habib Rehman Jan 14 '22 at 07:52