Showing posts with label web development. Show all posts
Showing posts with label web development. Show all posts

Wednesday, May 6, 2009

Manage MySQL datadir folder

Mysql no-doubtly is the most popular database server among web user for it available on most hosting and SMEs. It's distribution also available on most linux distro, including the popular Ubuntu.

Mysql data file is the base of mysql database storage. Relocating folder usually for harddrive partition storage management issue. Managing MySQL data file is kinda tricky, because since Ubuntu 8.04, MySQL data file is protected by apparmor by default. Meaning, we cant simply move around files related to MySQL, as all location need to be registered.

Basic step is to edit mysql config file, in /etc/mysql/my.cnf.
Make sure the service is stopped.


$ sudo /etc/init.d/mysql stop
$ sudo vi /etc/mysql/my.cnf

Look for datadir directive, change it to your new location. Datadir location has to be actual location, not a symbolic link. Save and quit the editor. Dont forget to move old database location into the new folder, most importantly "mysql", as the folder contains user authentication info. Otherwise you'll find unable to log in to the database.

Apparmor Part

Apparmor is a security software for Linux. Apparmor protects unauthorised changes to system critical files. To open apparmor protection for MySQL, open a shell terminal, and type :

$ sudo vi /etc/apparmor.d/usr.sbin.mysqld

Add the new location:


/var/www/mysql_datadir/ r,

/var/www/mysql_datadir/** rwk,


Restart apparmor by :


$ sudo /etc/init.d/apparmor restart

If everything went right, mysql start status should showing [ok], otherwise, consulting syslog somehow could help. Type this before restarting mysql service

$ tail -f /var/log/syslog


In other terminal,

$ sudo /etc/init.d/mysql start

Now your database is located in folder you prefer to.

Wednesday, May 28, 2008

Integrate PHPBB login to your website

PHPBB is one of most widely used forum board system. Build on strength platform of PHP, PHPBB free yet stable and easy to configure. We can aware if a system using PHPBB as its forum board system, by its unique layout and themes.

For some website that doesn't have own member management system can use PHPBB for their user / login based system. PHPBB provide a solid member management system, sign up interface, also nice member profile interface.

For sign up, easiest way is using existing PHPBB signup form. More customization is required to match your website theme. Simply edit profile_add_body.tpl template under your phpbb/template/templatename/ folder. It's all in html + smarty code.

Next is to link a login form (on your main website) to phpbb login verification system. You need to create a form contain 3 main object : user name, password, and Login button


<form name="frmPhpBBLogin" action="your_phpbb_login.php" method="post">

User name : <input name="username" type="text">

Password : <input name="'password'" type="password">

<input value="'Login'" type="'submit'">

</form>




To get login info which stored in PHPBB session, simply get it from COOKIE data by
PHP Code snippet
-----------
$session_data = isset($_COOKIE['phpbb2_data'])?unserialize(stripslashes($_COOKIE['phpbb2_data'])) : array();
if (isset($session_data['userid'])) GetPHPBBMemberDetail($session_data['userid'])
function GetPHPBBMemberDetail($id) {
$myQR = "SELECT * FROM `phpbbdb`.`phpbbprefix_users` WHERE `user_id`='$id'";
$myRE = mysql_query($myQR);
return mysql_fetch_assoc($myRE);
}

------------
Note :
- Actual cookie variable name may vary, you can do a var_dump($_COOKIE) to find out.
- Change `phpbbdb` to your actual PHPBB database name
- Chnage `phpbbprefix_` to actual PHPBB table naming prefix
You must have mysql access to get all the data.

To log out simply hit PHPBB's logout url, normally at login.php?logout=true