apache, mysql and php installation and configuration chapter 2 mysql installation and configuration

15
Apache, MySQL and PHP Apache, MySQL and PHP Installation and Installation and Configuration Configuration Chapter 2 Chapter 2 MySQL Installation and MySQL Installation and Configuration Configuration

Upload: alyson-webster

Post on 18-Jan-2016

253 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Apache, MySQL and PHP Installation and Configuration Chapter 2 MySQL Installation and Configuration

Apache, MySQL and PHP Installation Apache, MySQL and PHP Installation and Configurationand Configuration

Chapter 2Chapter 2MySQL Installation and MySQL Installation and

ConfigurationConfiguration

Page 2: Apache, MySQL and PHP Installation and Configuration Chapter 2 MySQL Installation and Configuration

MySQL InstallationMySQL Installation

Installing with Windows :

•Go to the source Web site, www.mysql.com, and click “downloads (GA)” on the navigation bar, choose MySQL Community Server, click download.•Select Platform “Microsoft Windows”.•Choose latest stable version and click the MSI file to initiate download. (If you don’t have an account you must register first)•Unzip the file to a temporary directory of your choice.•Click setup.exe to run the installation program. You will see the first of the Installation Wizard screens.•Click Next to display the informational screen.We highly recommend that you read this screen before you continue.•Click Next, which brings you to the Choose Destination Location screen.

Page 3: Apache, MySQL and PHP Installation and Configuration Chapter 2 MySQL Installation and Configuration

MySQL InstallationMySQL Installation

Installing with Windows :

•If the default directory is acceptable, simply click Next; otherwise, click Browse and select a different destination•Click Next.•The next screen allows you to customize your installation; typical installation is sufficient for most users.•Click the setup type you prefer, and click Next to begin the installation.After installing the appropriate files, the final screen will simply indicate the installation is complete. Click Finish to end the wizard

Page 4: Apache, MySQL and PHP Installation and Configuration Chapter 2 MySQL Installation and Configuration

MySQL InstallationMySQL Installation

Installing with Linux :

•Go to the source Web site, www.mysql.com, and click “downloads (GA)” on the navigation bar, choose MySQL Community Server, click download.•Select Platform for your appropriate Linux Distro.•Choose latest stable version and grab the tarball. (If you don’t have an account you must register first).•Open a console window and change the directory (cd) to the folder where you downloaded the tarball.•If there isn’t a user on the system dedicated to running the mysql daemon (typically mysql), you’ll need to create one. To do this, in the console, enter the following commands :

groupadd mysqluseradd –g mysql mysql

Page 5: Apache, MySQL and PHP Installation and Configuration Chapter 2 MySQL Installation and Configuration

MySQL InstallationMySQL InstallationInstalling with Linux :

•Extract the tarball, and change to the directory it creates :

VERSION is the (sub)version of the mysql source tarball you downloaded.•Next, configure the source this way :

Using the --prefix switch tells the installer where to put the mysql libraries and binaries after they’re built.•Compile the source :

tar –xzf mysql-VERSION.tar.gzcd mysql-VERSION

./configure --prefix=/usr/local/mysql

make

Page 6: Apache, MySQL and PHP Installation and Configuration Chapter 2 MySQL Installation and Configuration

MySQL InstallationMySQL Installation

Installing with Linux :

•Install the libraries and binaries :

Note that you will need to be logged in as superuser (root) to perform this step and the following steps in the MySQL installation.

•If this is the first time MySQL has been installed on your machine (in other words, not an upgrade), run this script to install the initial database/tables :

make install

scripts/mysql_install_db

Page 7: Apache, MySQL and PHP Installation and Configuration Chapter 2 MySQL Installation and Configuration

MySQL InstallationMySQL InstallationInstalling with Linux :

•Fix permissions on installed files, and copy over the default configuration file :

Any changes you wish to make to customize MySQL should be made in this file.•Start the MySQL daemon :

You’ll probably want to add the previous command to whatever facilities are available to automatically start the daemon at boot. This varies by OS. Here is one easy way to add this that works with most systems (but may not be the best way) :

chown –R root /usr/local/mysqlchown –R mysql /usr/local/mysql/varchgrp –R mysql /usr/local/mysqlcp support-files/my-medium.cnf /etc/my.cnf

/usr/local/mysql/bin/mysqld_safe --user=mysql &

echo ‘/usr/local/mysql/bin/mysqld_safe --user=mysql &’ >> /etc/rc.local

Page 8: Apache, MySQL and PHP Installation and Configuration Chapter 2 MySQL Installation and Configuration

Testing InstallationTesting Installation

•For Windows 95/98/Me, at the DOS prompt, change directories until you are in the MySQL server main directory (the default is c:\mysql\bin\). Then type

For Windows 2000/XP/NT, at the DOS prompt, change directories until you are in the MySQL server main directory and type.

You should see a screen that looks similar to the one shown below

c:\mysql\bin>mysqld

c:\mysql\bin>mysqld --install

Page 9: Apache, MySQL and PHP Installation and Configuration Chapter 2 MySQL Installation and Configuration

Testing InstallationTesting Installation

•To start the MySQL server, type the following :

Your screen will look like the one shown below.

•Now you should test to make sure your MySQL server is running. Although there are many possible commands to test the server, to keep things simple use the following:

c:\>NET START MySQL

C:\>c:\mysql\bin\mysql test

Page 10: Apache, MySQL and PHP Installation and Configuration Chapter 2 MySQL Installation and Configuration

Testing InstallationTesting Installation• Your screen should look something like the one shown below :

• To return to the DOS prompt, enter the following :

• To stop the server from running, type the following :

• To shut down the MySQL service, type :

mysql>exit or mysql>quit

c:\>NET STOP MySQL

C:\>c:\mysql\bin\mysqladmin -u root shutdown

Page 11: Apache, MySQL and PHP Installation and Configuration Chapter 2 MySQL Installation and Configuration

ConfigurationConfiguration

• Default installation is insecure.• No password• All rights granted• Root can log in from anywhere• Need to secure installation

Page 12: Apache, MySQL and PHP Installation and Configuration Chapter 2 MySQL Installation and Configuration

ConfigurationConfiguration

• Secure using the provided utility.

• This script does the following:• Removes anonymous user.• Disalows remote root login.• Removes Test Database.

mysql_secure_installation

Page 13: Apache, MySQL and PHP Installation and Configuration Chapter 2 MySQL Installation and Configuration

Basic AdministrationBasic Administration

Assigning User Rights

•Grant privileges to data bases:

•Grants all privileges to user mike on all databases.•These users are just stored as entries in a database, and you can edit the records directly if you want.

GRANT ALL PRIVILEGES ON *.* TO ‘user'@'localhost'WITH GRANT OPTION;GRANT ALL PRIVILEGES ON *.* TO ‘user'@'%' WITHGRANT OPTION;

Page 14: Apache, MySQL and PHP Installation and Configuration Chapter 2 MySQL Installation and Configuration

Basic AdministrationBasic Administration

Adding Users•From the mysql client :

•Creates local and remote user ‘user’.•The '@' part matches hostnames, '%' is a wildcard.•You can restrict users to only connect from a certain host.

mysql> create user ‘user'@'localhost' identifiedby 'password';mysql> create user ‘user'@'%' identified by'password';

Page 15: Apache, MySQL and PHP Installation and Configuration Chapter 2 MySQL Installation and Configuration

ReferencesReferences

References :

1.Anonymous.(n.d.). Apache HTTP Server Documentation Version 2.2. Retrieved from http://httpd.apache.org/docs/2.2/.2.Achour, M., Betz, F. (n.d.), PHP Manual. Retrieved from http://www.php.net/download-docs.php.3.Anonymous. (n.d.). MySQL Reference Manual. Retrieved from http://downloads.mysql.com/docs/. 4.Naramore, E., Gerner, J., Le Scouarnec, Y., Stolz, J., Glass, M. K. (2005). Beginning PHP5, Apache, and MySQL® Web Development. Indianapolis, IN: Wiley Publishing, Inc.