How to setup MYSQL and phpMyAdmin

Posted by Jay     25 June, 2008    521 views   

This process can be complicated to some people but its very easy as if you use ports to install both programs and follow my simple instructions. First you will need to pick a mysql version that is right for you in /usr/ports/databases/. I would suggest you find the recommended version online that most people use. You can use sites such as google.com to find out what most people are using. Once you find the correct version you would like to use then cd to the port that you wish to install and type “make install”. If any options come up you won’t need to make any changes unless you know for sure that you will need to. I do recommend you do some reading again on particular applications that you will be running and their requirements. Once this is installed you will need to install PHP. Again, its important to read up on which version of PHP is right for you. The best way to install PHP is to install it from php-extentions in ports. Once you figure out which PHP is right for you cd to /usr/ports/lang/php[X]-extentions where [X] = the PHP you want to use. Be sure that you don’t already have PHP installed before you complete this step. When the options pop up for PHP you just want to make sure you have the mysql options checked (both of them). Proceed with the install until its complete. Finally we install phpMyAdmin. Type “cd /usr/ports/databases/phpmyadmin ; make install”. When that completes installing we will move on to the next step.

First we need to start mysql by typing:

$ mysqld_safe &

Perhaps the most important step is after you install mysql you will want to set a root password for it so go ahead and do that by typing (at the root prompt):

$ mysqladmin -u root password ’somepassword’

Something that is smart to do for security is to change the user root to something else. We’ll do that in this next step by typing the following:

$ mysql -u root -p mysql

Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 72 to server version: 4.0.0-alpha-log

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

mysql> UPDATE user set user = ‘admin’ where user = ‘root’;
Query OK, 2 rows affected (0.00 sec)
Rows matched: 2 Changed: 2 Warnings: 0

mysql> quit;
Bye

$ mysqladmin -u root -p reload
Enter password:

Once you have done this you are ready to move on to the phpmyadmin step. If you have an apache webserver you will want to put the following in the config file where the other Aliases are or in your vhost file where your main site is:

Alias /phpmyadmin “/usr/local/www/phpMyAdmin”

AllowOverride None
Options Indexes FollowSymlinks MultiViews
Order allow,deny
Allow from all
AuthName “Secure PHP Myadmin site ”
AuthType Basic
AuthUserFile /usr/local/www/phpMyAdmin/.htpasswd
Require valid-user

This particular method will enable .htpasswd to hold the password to access the phpmyadmin site. This is essential to the security of your server if you are going to set it up this way.

Go ahead and “cd /usr/local/www/phpMyAdmin/” then you want to create an .htpasswd with your username and password decrypted. To do this type the following:

$ htpasswd -nb username password > .htpasswd
$ chmod 640 .htpasswd

Once you have done this you will need to put your root username and root password in a file that phpmyadmin needs to access all the databases. To do this type:

$ ee /usr/local/www/phpMyAdmin/config.inc.php

Go ahead and make the two lines below read with your passwords in place of mine:

$cfg['Servers'][$i]['user'] = ‘myuser’; // MySQL user
$cfg['Servers'][$i]['password'] = ‘mypass’; // MySQL password (only needed with ‘config’ auth_type)

You can exit and save this file and go ahead and pull up phpmyadmin on your site by typing http://www.yoursite.com/phpmyadmin in your browser.

Post to Twitter  Post to Delicious  Post to Digg    Post to StumbleUpon

Categories : MySQL, Scripts Unix, Web & Scripts Tags : ,

Comments

No comments yet.


Leave a comment

(required)

(required)