• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Virtual Hosting With MySQL:
 

Virtual Hosting With MySQL:

on

  • 6,686 views

 

Statistics

Views

Total Views
6,686
Views on SlideShare
6,686
Embed Views
0

Actions

Likes
0
Downloads
23
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Virtual Hosting With MySQL: Virtual Hosting With MySQL: Document Transcript

    • Technical Document Series Number 003 Virtual Hosting With MySQL: A Technical Guide for the Hosting Reseller Date: April 4, 2001 Version 1.0
    • by Matthew Feinberg Important Notice This document contains proprietary information of Ensim and its receipt or possession does not convey any rights to reproduce, disclose its contents, manufacture, use, or sell anything it may describe. Reproduction, disclosure, or use without Ensim's specific written authorization is strictly forbidden. Ensim Corporation makes no representations or warranties with respect to the contents or use of this document. It also reserves the right to revise this publication and make changes to the content at any time without the obligation to notify any person or entity of such revisions or changes. ServerXchange and WEBppliance are trademarks of Ensim Corporation. Netscape is a registered trademark of Netscape Communications Corporation. Windows is a registered trademark of Microsoft Corporation. Java, Solaris, SPARC are registered trademarks of Sun Microsystems. Linux is a registered trademark of Linus Torvalds. All other trademarks and copyrights are the property of their respective owners. Copyright © 1999 - 2001 Ensim Corporation. All rights reserved. Ensim Corporation © 1999, 2000, 2001 Ensim Corporation. All rights 1366 Borregas Avenue reserved. Ensim is a trademark. All other Sunnyvale, CA 94089 trademarks are the property of their respective (408) 745-3300 owners. Product information is subject to change www.ensim.com without notice.
    • Contents Virtual Hosting With MySQL: _________________________________1 Introduction ______________________________________________________ 1 Purpose _______________________________________________________ 1 Overview _____________________________________________________ 1 Preliminaries ______________________________________________________ 1 Things You Will Need to Have ___________________________________ 1 Assumptions ___________________________________________________ 1 What Has to be Done for MySQL _______________________________ 2 What Has to be Done for PHP4 _________________________________ 2 What Has to be Done for phpMyAdmin _________________________ 3 Creating Users and Databases ____________________________________ 4 Creating the Database ________________________________________ 4 Granting User Privileges ________________________________________ 6 Revoking User privileges ________________________________________ 7 Deleting the Database ________________________________________ 8 Giving Your Customer Database Access ________________________ 8 Notes: ________________________________________________________ 8 Glossary __________________________________________________________ 8 For Further Reading _______________________________________________ 8 MySQL Documentation Site: ________________________________ 8 PHP Links: __________________________________________________ 8 Third Party Links: ____________________________________________ 9 Virtual Hosting With MySQL i
    • ii Virtual Hosting With MySQL
    • Introduction Virtual Hosting With MySQL Introduction Purpose This document describes how to configure and use MySQL and phpMyAdmin in a virtually hosted environment. It gives step-by-step examples on providing a secure and user-friendly operating environment. Overview Administering MySQL in a shared environment requires care and planning to ensure the safety of customer data. This document describes the process of setting up MySQL and phpMyAdmin with WEBppliance in a secure way so one customer cannot see or harm another customer’s database(s). This process does not ‘integrate’ MySQL and phpMyAdmin. Rather, it is a primer on how to setup and manage MySQL User Administration. Resources for further reading on MySQL and Linux Administration are listed at the end of this document. Preliminaries Things You Will Need to Have Download phpMyAdmin (tar version with .php extensions from http:// www.phpwizard.net/projects/phpMyAdmin/ and have MySQL and PHP4 installed by your hosting provider. Assumptions It is assumed that your system has WEBppliance 2.3 or earlier with MySQL and PHP4 installed. To discover if you have php4 or MySQL installed, telnet to your Private Server and login with the unix ‘admin’ account provided by your hosting provider. Run the following command. # ls /etc/serverxchange/services/ Virtual Hosting With MySQL - VH0404010003c 1
    • Preliminaries You should see a list like this: analog frontpage mod_perl openssl sendmail vacation apache imap mod_php proftpd services_scripts virtualhosting bind majordomo mysql python telnet virtualwebhosting Please contact your hosting provider if you do not have mod_php and/or mysql listed. What Has to be Done for MySQL If MySQL is not installed on your private server you can ask your Hosting Provider to install MySQL. Use the MySQL installation provided by Ensim. It is assumed here that this is the case. Once MySQL is installed you can obtain the MySQL root password from the file `/usr/ share/mysql/passwd_ens` # cat /usr/share/mysql/passwd_ens 238328 ! your password will be displayed If you would like to change your mysql password, do: # mysqladmin –uroot –p238328 password new_passwd Add an stduser that has read only access to the database. This is a security precaution to prevent someone from stealing the MySQL root password from the config.inc.php file. # mysql -uroot –pnew_passwd -e"grant select on mysql.* to myadmin@localhost identified by 'pick a password not equal to mysql root' " What Has to be Done for PHP4 If PHP is not installed on your private server you can ask your Hosting Provider to install PHP4. Use the PHP4 installation provided by Ensim. It is assumed that this is the case. To test your php installation, create a file called /home/httpd/html/test.php. This file should only include the following line. <?php phpinfo(); ?> Note: You may need to ‘su web’ to write the file because the directory is owned by the user web. Virtual Hosting With MySQL-VH0404010003c 2
    • Preliminaries Go to http://yourserver/test.php. You see the PHP status page displayed (see Figure 1 on page -3). Figure 1. PHP Status Page What Has to be Done for phpMyAdmin FTP to the server, the phpMyAdmin_2.1.0php.tar.gz file you acquired from phpwizards.net. Telnet/ssh to the server and become root. Run the following commands. # tar zvxf phpMyAdmin_2.1.0php.tar.gz # cp -R phpMyAdmin /home/httpd/html/ # chown -R web.web /home/httpd/html/phpMyAdmin Read the INSTALL README file in /home/httpd/html/phpMyAdmin/. Using your favorite unix text editor, edit the /home/httpd/html/phpMyAdmin/config.inc.php file and change the following lines: $cfgServers[1]['adv_auth'] = false; ! change to true i.e. $cfgServers[2]['adv_auth'] = true; $cfgServers[1]['stduser'] = 'root'; ! change to myadmin i.e. $cfgServers[1]['stduser'] = 'myadmin'; $cfgServers[1]['stdpass']=' '; ! insert mysql root password: Virtual Hosting With MySQL - VH0404010003c 3
    • Creating Users and Databases i.e. $cfgServers[1]['stdpass'] = '213168'; Do a chmod to the /home/httpd/html/phpMyAdmin/config.inc.php. # chmod 0550 /home/httpd/html/phpMyAdmin/config.inc.php Stop and start MySQL. From the telnet/ssh session on the private server, restart mysql. # /etc/rc.d/init.d/mysql stop # /etc/rc.d/init.d/mysql start Creating Users and Databases Creating users and databases can be done from the command line or from the phpMyAdmin GUI. In this example we are using the phpMyAdmin GUI. For command line (CLI) options, see the MySQL manual. Creating the Database Connect to http://yourprivateserver/phpMyAdmin/index.php and login (see Figure 2 on page -5) with your MySQL root user and password. Virtual Hosting With MySQL - VH0404010003c 4
    • Creating Users and Databases Figure 2. phpMyAdmin GUI Login Note: This is your mysql root password, not the server root password. To guarantee that the name of the database is unique, call the database by the username of the site requesting the database. For this example we use “matthew”. Virtual Hosting With MySQL - VH0404010003c 5
    • Creating Users and Databases Enter the database name in the “Create new database” field and click “Create” (see Figure 3 on page -6). You should see the database name appear on the left pane menu. Figure 3. Entering the Database Name Granting User Privileges To grant the user access to this database, click the “mysql” link on the left menu (see Figure 4 on page -6). Figure 4. Granting the User Privileges Note: The use of “all” will allow the user to grant and reference privileges which may be undesirable. Enter the following in the “Run SQLquery/queries on database mysql” field (see Figure 4 on page -6). Click on “Go” when you are done. Virtual Hosting With MySQL - VH0404010003c 6
    • Creating Users and Databases grant select, update, insert, delete, drop, create, index, alter on matthew.* to matthew@localhost identified by "matthew999"; This is the special grant statement that saves you a lot of time spent on typing out complex SQL statements. The statement gives the user “matthew” select, update, insert, delete, drop, create, index and alter privileges, all privileges on all tables in the database named matthew with a password of matthew999. Similarly, you can grant a user limited access to a database (see Figure 5 on page -7). grant select, update, insert on matthew.guestbook to matthew@localhost identified by "matthew"; Figure 5. Granting the User Limited Access The statement gives the user “matthew” only select, update, insert, delete, drop, create, index and alter privileges, only on the guestbook table in database named “matthew” with a password of matthew. Index and Alter are needed for site users to create indices on their tables. To disallow a privilege, remove the privilege from the grant statement. Revoking User privileges To revoke privileges, you can revoke the user permissions. revoke index, alter on matthew.* from matthew@localhost; To delete the user from the mysql database run: delete from user where user=’matthew’ Virtual Hosting With MySQL - VH0404010003c 7
    • Glossary Deleting the Database To delete a database, choose the database from the left pane menu and click “Drop database” at the bottom of the page. Giving Your Customer Database Access Once you finish the steps needed to create a database for the customer you can direct them to http://yourprivateserver/phpMyAdmin/index.php to manage their database. Provide them with the login (matthew) and password (matthew999) you entered above. Notes: • Customer databases are not maintained under the Site Quota because the MySQL databases created remain under the ownership of the MySQL process. • You will need to carefully monitor the database sizes. • When you create the myadmin user make sure you choose a password separate from the mysql root password. Glossary SQL—An industry-standard language for creating, updating and, querying relational database management systems. Database—A collection of data arranged for ease and speed of search and retrieval. For Further Reading MySQL Documentation Site: http://www.mysql.com/doc/A/d/Adding_users.html http://www.unixguru.org/howtos/mysql/userperms.html http://www.mysql.com/documentation/mysql/bychapter/manual_Privilege_system.html http://www.mysql.com/articles/mysql_intro.html#SECTION0002000000 PHP Links: http://www.php.net Virtual Hosting With MySQL - VH0404010003c 8
    • For Further Reading Third Party Links: http://www.unixguru.org/howtos/mysql/userperms.html http://www.psiweb-guide.aa.psiweb.com/MySQL/user.html http://www.phpwizard.net/projects/phpMyAdmin/ http://www.phpwizard.net/projects/phpMyAdmin/documentation.html Virtual Hosting With MySQL - VH0404010003c 9