Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder The Noob Coder's Avatar
    Join Date
    Jul 2012
    Location
    The City that Never Sleeps
    Posts
    99
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Can't .htaccess to work with Apache 2 and Codeigniter

    Hey Everyone,

    I've spent the entire day Googling trying to find a solution to my problem, but so far have had no luck. In short, my problem is that password protecting with .htaccess is not working.

    I've placed the following .htaccess file in the directory that I want to password protect:
    Code:
    AuthUserFile /var/.htpasswd
    AuthType Basic
    AuthName "Administrative Area"
    Require valid-user
    I have double checked that the password file exists in the directory specified and is spelled properly. I used the htpasswd command to create it and see that there is a user listed in it along with an encrypted password.

    Both the .htaccess file and the .htpasswd file have read permissions for everyone.

    When I navigate over to the directory in my browser I'm expecting a pop up asking me for a user name and password but so far, nothing like that has shown up and the page loads as normal. I read a lot of posts online that talk about setting "AllowOverride" to "All" in my httpd config file, which I did for all instances, but still no luck.

    I even created my own Directory directive in the httpd file like so:
    Code:
    <Directory "/var/www/html/application/controllers/admin">
    AllowOverride All
    </Directory>
    But as you can guess, this also didn't work.

    Another thing that I tried was putting garbage in the .htaccess file. From what I read, if there is a line that isn't syntactically correct, it should throw an error or something in the browser, but I received no such error when I had this as my .htaccess file:

    Code:
    AuthUserFile /var/.htpasswd
    AuthType Basic
    AuthName "Administrative Area"
    Require valid-user
    some garbage here
    I guess the file is being ignored?

    Through out the process, I've restarted the server after each operation with "service httpd restart". You might be wonder why I would be using htaccess if I have root access to the server, but that is only because this is my own server that I am using for development. I won't have this level of access on the final production server, so I need to use htcaccess and get it working.

    As mentioned in the title, I am using the Codeigniter PHP framework and I don't know if that could be causing an issue as well. The server is running CentOS.

    Does anyone have any other trouble shooting tips they could suggest that would help me narrow down the problem?

  • #2
    New Coder The Noob Coder's Avatar
    Join Date
    Jul 2012
    Location
    The City that Never Sleeps
    Posts
    99
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Since posting, I've also tried changing the owner of both .htaccess and .htpasswd to apache and moving both files into the same directory (the directory that I want to password protect). I know that .htpasswd should be kept out of the publicly accessible web directory, but I was running out of options.

  • #3
    Regular Coder Linux_Sage's Avatar
    Join Date
    Mar 2014
    Location
    Sterling,VA
    Posts
    105
    Thanks
    0
    Thanked 10 Times in 10 Posts
    Make sure mod_rewrite is enabled.

    Code:
    a2enmod rewrite
    Within the console to do so

  • #4
    New Coder The Noob Coder's Avatar
    Join Date
    Jul 2012
    Location
    The City that Never Sleeps
    Posts
    99
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Linux_Sage View Post
    Make sure mod_rewrite is enabled.

    Code:
    a2enmod rewrite
    Within the console to do so
    Thanks for your reply. I tried that but the command "a2enmod" wasn't found. Is it in some weird path that I have to include first?

  • #5
    Regular Coder Linux_Sage's Avatar
    Join Date
    Mar 2014
    Location
    Sterling,VA
    Posts
    105
    Thanks
    0
    Thanked 10 Times in 10 Posts
    Try to run it as root or use

    Code:
    sudo a2enmod rewrite
    If it works, then be sure to restart apache to apply the changes.

  • #6
    New Coder The Noob Coder's Avatar
    Join Date
    Jul 2012
    Location
    The City that Never Sleeps
    Posts
    99
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I was already logged in as root when I ran the command.

  • #7
    Regular Coder Linux_Sage's Avatar
    Join Date
    Mar 2014
    Location
    Sterling,VA
    Posts
    105
    Thanks
    0
    Thanked 10 Times in 10 Posts
    What version/Distro of Linux are you using? You're probably using one that doesn't do things that way. Try the instructions for your particular distro from this page:

    Linux disable unneeded modules in Apache to save memory


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •