Suponemos que tenemos todo instalado Apache,PHP y Mysql.
- Instalamos libapache2-mod-auth-mysql: sudo apt-get install libapache2-mod-auth-mysql
- Habilitamos el modulo:
cd /etc/apache2/mods-enabled
sudo ln -s /etc/apache2/mods-available/auth_mysql.load - Arrancamos Mysql y creamos la base de datos:
mysqladmin -u root password <password>mysql -uroot -pmysql> grant all on auth.* to auth_user@localhost identified by ‘<password>’;mysql> flush privileges;mysql> create database auth;CREATE TABLE `clients` (
`username` varchar(25) NOT NULL default ”,
`passwd` varchar(25) NOT NULL default ”,
`groups` varchar(25) NOT NULL default ”,
PRIMARY KEY (`username`),
KEY `groups` (`groups`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;INSERT INTO `clients` VALUES (‘<username>’, ‘<password>’, ‘<group>’); - Editamos el Archivo de Configuración de Apache apache2.conf:
Digitamos: sudo nano/etc/apache2/apache2.confAgregamos las siguientes lineas al final del archivo:Auth_MySQL_Info localhost <auth_user> <password>
<Directory “<web directory>”>
Options +Indexes FollowSymLinks MultiViews
AllowOverride AuthConfig Options FileInfo Limit
Order allow,deny
Allow from all
</Directory>Ajustamos <auth_user>, <password> y <web directory> escribes en web directoy la direccion de la carpeta que contendrá la seguridad .htaccess ejemplo: <Directory /var/www/prueba/>
Reiniciamos apache Apache 2: sudo /etc/init.d/apache2 restart
- Finalmente colocamos en .htaccess las siguientes lineas:
AuthMYSQL on
AuthMySQL_Authoritative on
AuthMySQL_DB auth
AuthMySQL_Password_Table clients
AuthMySQL_Group_Table clients
AuthMySQL_Empty_Passwords off
AuthMySQL_Encryption_Types Plaintext
AuthBasicAuthoritative Off
AuthUserFile /dev/nullAuthName “<description>”
AuthType Basic<Limit GET POST>
require group <group>
</Limit> - Para autenticar con varios Grupos hacemos espacio y escribimos el nombre del otro grupo:
<Limit GET POST>
require group <group1> <group2>
</Limit> - LISTOO eso es todo….
Advertisement