Wednesday, October 6, 2010

Installing Apache, PHP,MYSQL?

Step 1:
===================================================
Install Apache http server to c:\Apache2.2.11

Run Apache and test http://localhost

we can configure http port, server root, document root...etc
in c:\Apache2.2.11\conf\httpd.conf


Step 2:
====================================================
install or unzip PHP 5 to c:\php5.2.6

create php.ini in c:\php5.2.6
make sure php5apache2_2.dll is in c:\php5.2.6


Step 3: Link Apache and PHP.
======================================================
Open httpd.conf in c:\Apache2.2.11\conf

add following three lines in LoadModules area

#Let apache where php DLL present to process php files
LoadModule php5_module "c:/php5.2.6/php5apache2_2.dll"


#Let apache know php can be handled
AddType application/x-httpd-php .php

# let Apache know path to php.ini
PHPIniDir "c:/php5.2.6"

You can test php configuration. create a php fiel phpinfo.php in htdocs of
apache server. then issue
http://localhost/phpinfo.php

phpinfo.php
------------
phpinfo();
?>


Step 4: Configure MySQL
===========================================
install MYSQL server to c:\mysql5.1
start mysql server from command prompt ( if you havent installed
mySQL as service. we can choose this option while installaiton)

cmd > mysqld (press enter)


Then log into mySQL

cmd> mysql -u root (press Enter) .you may need to enter password
using -p option (if you set root password in installaiton)

Now see list of databases
mysql> show databases;

To see list of existing users,

mysql> select user,host,password from mysql.user;

Here mysql is MYSQL server system database to keep system tables

to create new database
mysql> create database if not exists wp436;

to create new user

mysql> create user 'suresh'@'localhost' identified by 'suresh123';


Then to grant all privileges to wp436 to user suresh,

mysql>use wp436;
mysql> grant select,insert,update,delete,create,drop on wp436.* to 'suresh'
identified by 'suresh123';


Now user is ready for login;






cmd> mysql -u suresh -p (press enter.prompt for password)

now user can see list of databases having access

mysql>show databases;


Now create a table in wp436 database
user first select the database

mysql> use wp436;

mysql>create table student(sno integer(6),sname varchar(50),sfee double(8,2),primary key(sno));


Now insert data

mysql> insert into student values(100,'aaa',1000);

now commit,

mysql> commit;


Step 5: Connect PHP and MYSQL
====================================

modify php.ini to enable

extension=php_mysql.dll
extension=php_mysqli.dll

And copy the "php_mysql.dll" to c:\WINDOWS, and the "libmysql.dll" to the c:\WINDOWS\system32. You will find these dlls in the ext directory in the PHP installation directory.

we can do more changes in [MYSQL] section of php.ini

Note: irritation with beep sound provided by msql?
use cmd> net stop beep :)



Are you getting could not connect can't connect to mySQL server on localhost(10061)

Sol: Checl mysqld is running or not. if not run it
cmd>mysqld



Step 6: Sample PHP Program to test db connection:
=======================================================





call this php file using

http://localhost/dbtest.php

No comments:

Post a Comment