Wednesday 14 January 2009

Getting phpMyAdmin working in Ubuntu

This morning went on Animal for an hour until just before 10am, then went on my comp to do some work with my website.

First I googled about chrooting my virtualhosts/user, and couldn't find much that I could understand. Two links I found useful were VSFTP chroot or jail users - limit users to only their home directory howto and Stuart Herbert's PHP blog, which has a few posts on the different methods of securing a shared hosting environment.

After reading that for a bit, I checked if I was chrooted on my webhost, and I wasn't. So I guess finding out how to chroot a virtualhost isn't important. I did find that I could access non-php files outside of the user's home directory (in my local environment, didn't try it on the webserver!), which seemed like quite a security risk if this was how the webserver was set up (which it very likely isn't).

Later on I realised I could fix this problem by changing permissions on files/folders outside the user's home root so that the permissions for 'Others' was 'List files only' rather than 'Access files'. An easier way would probably be to set Apache2 to default folder/file permissions to deny from all, then just change to allow for the user's home folder in the virtualhost setup.

Before lunch a couple of guys came round to install the green cone which I ordered back in December.

After lunch I followed a bit more of the netbeans tutorial in setting it up to work with php, which involved installing the Xdebug apache module. Because I was using php5-cgi rather than mod_php5 I had to make a couple of manual changes to php.ini to get it to work. Weirdly php.ini didn't have any links to the gd, mysql, mysqli or PDO modules, but phpinfo() said these were all loaded.

After getting that set up I needed a way to setup databases and users in mysql, so I installed phpmyadmin. First off I couldn't get phpmyadmin to load, it just had a message about unknown file type .phtml or sumat, and a download box popped up for index.php. I figured this was something to do with suPHP and not having suPHP set up for the localhost virtualhost. So I tried accessing phpMyAdmin via my main working virtualhost, and that gave a suPHP error message to say that that the file was outside the area that the user was allowed to execute php scripts. I think that was the error, or otherwise it was about the UID of the file being less than the UID of the user. Eitherway, I got both those of those errors, one after fixing the other one.

I did some googling, but couldn't see how to fix this, so I just setup a new virtualhost for phpmyadmin, and a new user webapps. I set the virtualhost document root to '/usr/share/phpmyadmin' and the webapps home dir to there as well. I also had to 'chown -R webapps:webapps /usr/share/phpmyadmin' as well, as before the file files were all owned by root in group root, so suPHP couldn't execute them. In the virtualhost block I made sure I changed the user and group to run php scripts as to webapps.

Finally after much testing and messing around I got phpMyAdmin to load, but it had an error sumat like "conf error change password in $cfg['blowfish_secret']". After some googling I got it working by adding "$cfg['blowfish_secret'] = 'holla';" to '/etc/phpmyadmin/config.inc.php'. But then I tried changing the password in '/var/lib/phpmyadmin/blowfish_secret.inc.php' and that broke it. I messed around for a while, then finally gave up and reinstalled phpMyAdmin through the Synaptic package manager. But the file still had the password I'd made up in it, so I deleted the file, then reinstalled phpMyAdmin again. Then I added "$cfg['blowfish_secret'] = 'holla';" to '/etc/phpmyadmin/config.inc.php' again and it worked again.

After logging in as admin I found I couldn't add databases. So I tried logging in as root, and it worked and I could now add databases. Next I exported my database from my MySQL database in windows. I couldn't copy across a file from windows to my Ubuntu virtual machine. I did some googling and it seems that you can't copy files across with VMWare Server 2 and need VMWare Workstation for this ability. Oh well. It seemed the solution was to setup FTP on your virtual machine and then ftp the files across to it. I don't expect to be needing to transfer files from Windows to Ubuntu or Ubuntu to windows very often, so I didn't bother setting up ftp.

I copied the sql from the MySQL export operation, and pasted it into a file on Ubuntu and then did the import. There didn't seem to be any way to export a user, so I had to set up a new user on the Ubuntu MySQL installation and hope I did it the same as what was already setup in my windows environment and on the webhost.

After getting that setup I needed to copy all my website files across from windows to the Ubuntu VM. I used Nero to create an ISO file with the files on it, which I inserted into the Ubuntu Virtual Machine. There was some trouble with Nero being weird, but I did get it to work eventually.

After copying all the files across from the virtual CD to my working web directory on Ubuntu I had to change the Access permissions on all the files to be read-write by the owner and read by the group. The .htaccess files were owned by root, so I had to switch back to my admin account so I change their ownership to the user whose directory the site is in. I have to do this switching back forth between accounts quite a bit, and it gets quite annoying as you have to put your password in again each time you switch accounts.

I did find a useful tip when I googling for help on one of the many problems I was having - you can run sudo synaptic from terminal, and then you can edit, delete, copy files, and change permissions easily rather than having to do it all from the terminal window.

After sorting this out, I tested my site, but got an error that it couldn't connect to the database, the user was rejected. After some more googling and messing around, I found the problem was that I had setup my user for any host, and I needed to change it so it was for localhost only. After that it worked.

After getting that working it was dinner time. After dinner I watched Lost with Mac and Ben. I did a bit more website stuff in Ubuntu, then watched Fargo with Mac.

Food
Breakfast: Tangerine orange marmalade toast sandwich; cup o' tea.
Lunch: 2x cheese-on-toasts; ½ honey sandwich; slice of madeira cake; chocolate wafer biscuit; cup o' tea.
Dinner: Slice of pepperoni deep pan pizza; slice of 4 cheese deep pan pizza with added yellow pepper; chips; peas. Pudding was a peach and passion fruit creamy yoghurt and a dark chocolate digestive biscuit. Coffee; Sainsbury's caramel chocolate; white chocolate coins.
Supper: Tangerine orange marmalade toast sandwich; cup o' tea.

1 comment:

Skypirate said...

it seems to be with linux, recently, everytime I try and do something that used to be reasonably simple and straightforward, there's now spanners in the works, like this "unknown file type error"... trouble is my ability is fairly limited to apt-get and stuff just working. it used to be like that. all i want is a bare-bones install running cacti to monitor some switches....