| | | | Blog Posts From The Brave Programmer | |
| |
| |
How to work with Apache, MySQL, PHP and PhpMyAdmin on your local machineFeb7Written by: 2009/02/07 01:10 PM This is a short and sweet document to help you setup these things on your development pc for testing. There's an attachment zip file of several ini, conf, and php config files. Purpose: How to work with Apache, MySQL, PHP and PhpMyAdmin on your local machine Author: John L. Creed, john@pcexpressway.com Note: In this document it refers to replacing ini files, conf files and config.php files.
Be sure and backup your original files first. You may just want to review the ones I have 1st, and compare to the original ones. A working Development Machine.
To get a working web server on your development machine of apache, mysql and php, and the a mysql backend UI so you can work with your mysql databases software you will need:
- Apache 2.0.latest: http://www.apache.org/dist/httpd/binaries/win32/
- MySQL Community Edition: http://dev.mysql.com/downloads/mysql/5.1.html#win32 - choose Windows Essentials (x86)
- PHP 5.2.x: http://www.php.net/downloads.php - get the windows binaries zip package
- PHPMyAdmin: http://www.phpmyadmin.net/home_page/index.php - on the top right click on the .zip under download
- For dBASE Users: MySQL dBASE support. If you want to work with mySQL databases from dBASE you will need the mysql connector: http://dev.mysql.com/downloads/connector/odbc/3.51.html
NOTE: Only apache and mysql have installers NOTE: All ini files, config files have been configured for a default installation of the Apache web server, PHP, mySQL and phpMyAdmin on your local machine.
Directories you create after installing apache:
- apache / phpMyAdmin user file c:\apacheuser
- phpMyAdmin - the user interface for working with the mySQL databases C:\Program Files\Apache Group\Apache2\htdocs\myadmin
Directories the installers and or zip files should create:
Apache web server C:\Program Files\Apache Group the Apache config directory - you will be opening and replacing the file httpd.conf C:\Program Files\Apache Group\Apache2\conf
Apache htdocs folder - where you will have your main index.html page C:\Program Files\Apache Group\Apache2\htdocs mySQL C:\Program Files\MySQL
The mySQL config ini file (my.ini) is here: C:\Program Files\MySQL\MySQL Server 5.0
php5 C:\php5. The php.ini file is located here
To install apache ver. 2.0.59 nossl on local machine, use 127.0.0.1 as server name during setup. There are 3 fields: - domain - type in your domain, or make one up
- server: 127.0.0.1
- email address: your email or webmaster address
Apache Service Once installed, open a browser and type in http://localhost if you get the default page, you're ok. Next STOP the apache service either with the apache monitor in your tray icons bottom-right or from services.
- Copy and replace the http.conf file located in iniconf.zip file over the old one in C:\Program Files\Apache Group\Apache2\conf\http.conf this copy has been slightly revised based on my usage with apache hosting websites. For example you can type http://localhost/server-status to see what is configured, version and request data.
- Edit the apache config file and verify that you see the php reference right under the load modules section. close and save the http.conf file...
- Copy the phpinfo.php file located in iniconf.zip to the htdocs folder under apache.
- Unzip the php5.zip to: c:\ so it is under the root of the local disk, and preserve the directory structure within the zip file.
- Copy the php.ini file located in iniconf.zip file over the one in the php install directory. Locate the php.ini file, open it and search for: error_log = filename and replace filename with full path to the place you want the error log. When there are errors in your php code you will get a blank screen. You have to look at the error log file, last line, to see what and where the errors are.
- Then restart apache In your web browser type http://localhost/phpinfo.php you should see a php information page. Verify that the php.ini file is being
read. There's a label near the top that states (if any) path and file name. - Install mysql 5.0.x fairly simple and straight forward. Except the default port number, provide a password for the root (master) user. Use your judgement here but you change change things in the my.ini file later. Be sure and remember the port, and root password. See below phpMyAdmin.
- Stop the mysql service
- Copy and paste the my.ini file located in iniconf.zip to the C:\Program Files\MySQL\MySQL Server 5.0 folder.
- Then restart the mysql service.
- phpMyAdmin - this is a UI that allows you to work with and administer the mySQL database. Unzip this zip file to to the htdocs folder of apache. When done it should look like this: C:\Program Files\Apache Group\Apache2\htdocs\myadmin\
- Edit phpMyAdmin config file. Use a program editor to do this. In the directory C:\Program Files\Apache Group\Apache2\htdocs\myadmin\ find the config.inc.php file. Edit this file and change the control pass and the user password to the root password you provided when you installed mySQL, and save the file.
- Run the phpadmin for the first time: type in your browser: http://localhost/myadmin. You should see no errors on the screen. In this browser screen Under the label LOCALHOST, you should see the server name and user name who is logged in. You will see a drop down box on the left navigation pane labelled Databases. Select the mysql database. The following is an explanation of what we intend to do, which is to run phpmyadmin in our browser, and then have the web server (Apache) to restrict access to the page with out the proper credentials.
FOR YOUR INFORMATION For 'http' and 'cookie' modes, phpMyAdmin needs a control user that has only the SELECT privilege on the mysql.user (all columns except "Password"), mysql.db (all columns) & mysql. Tables_priv (all columns except "Grantor" & "Timestamp") tables.
You must specify the details for the control user in the config.inc.php3 file under the $cfgServers[$i]['controluser']& $cfgServers[$i]['controlpass'] settings.
This example assumes you want to use pma as the controluser and pmapass as the controlpass: - In the mysql databases area, click on the SQL link in the top navigation bar. Run the following sql statements by selecting them and copy / paste, in the
phpmyadmin Run Queries text box one at a time and press the GO button for each NOTE! Change the following user and password to what ever you choose!- GRANT USAGE ON mysql.* TO 'pma'@'localhost' IDENTIFIED BY 'pmapass'
- GRANT SELECT (Host, User, Select_priv, Insert_priv, Update_priv, Delete_priv, Create_priv, Drop_priv, Reload_priv, Shutdown_priv, Process_priv, File_priv, Grant_priv, References_priv, Index_priv, Alter_priv) ON mysql.user TO 'pma'@'localhost'
- GRANT SELECT ON mysql.db TO 'pma'@'localhost'
- GRANT SELECT (Host, Db, User, Table_name, Table_priv, Column_priv) ON mysql.tables_priv TO 'pma'@'localhost' Now add yourself with admin privs. Change the name and password first:
- GRANT ALL PRIVILEGES ON *.* TO 'me'@localhost IDENTIFIED BY 'my_real_password' INFORMATION - WHEN ADDING DATABASES AND USERS
- Now each of the true users should be granted of a set of privileges on a set of particular databases but shouldn't have any global privileges.
For example, to grant the user real_user with all privileges on the database user_base:
GRANT ALL PRIVILEGES ON user_base.* TO 'real_user'@localhost IDENTIFIED BY 'real_password';
What the user may now do is controlled entirely by the MySQL user management system.
With http or cookie auth mode, you don't need to fill the user/password fields inside the $cfgServers array. - Once done edit the apache config file and add the directory restrictions as here. In this case we use a folder as named below.Create under the root of your local disk c, the following: C:/apacheuser/, then open notepad by clicking the start button->Run and type in notepad, type the following according to the password you provided when you installed mysql. As you add users, you need to add them here too:
- root: somepassword
- me: my_real_password
- Save the file in the directory you created above for apache users, with the name: _htmyphpadmin.pw
- Stop the Apache Service. In the http.conf file look for phpmyadmin and place the below between the hash marks
<Directory "C:/Program Files/Apache Group/Apache2/htdocs/myadmin">
Options -indexes FollowSymLinks ExecCGI
AuthType Basic
AuthName "My PHP Admin"
AuthUserFile "C:/apacheuser/_htmyphpadmin.pw"
require valid-user
Order allow,deny
Allow from all
AllowOverride None
Order allow,deny
Allow from none
Deny from all
AllowOverride None
Save and restart the Apache web server - Change the phpMyAdmin config file. Use a program editor to do this. In the directory C:\Program Files\Apache Group\Apache2\htdocs\myadmin\ find the config.inc.php file. Edit this file and replace it's contents with this:
>below this line --------------------------------------------------------
/*
* Generated configuration file
* Generated by: phpMyAdmin 2.8.2 setup script by Michal Cihar <michal@cihar.com>
* Version: $Id: setup.php,v 1.23.2.10 2006/05/15 07:57:30 nijel Exp $
* Date: Tue, 29 Aug 2006 15:30:38 GMT
*/
/* Servers configuration */
$i = 0;
/* Server localhost (http) [1] */
$i++;
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['extension'] = 'mysql';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['auth_type'] = 'http';
/* End of servers configuration */
?>
and save the file...- Now in the address bar type in: http://localhost/myadmin and you should be presented with a browser security login page.
As you create a database you will need to assign a user for it. So you repeat the steps above while in phpmyadmin as follows:
GRANT ALL PRIVILEGES ON my_new_database.* TO 'my_new_user'@localhost IDENTIFIED BY 'real_password'; then add them to the text file under apache users _htmyphpadmin.pw close the browser and re-login with this user account so you can now see that he can only see *his* databases.
John L. Creed, john@pcexpressway.com pcExpressWay Consulting
dBASE Gold Charter Member 210 blog comments powered by 3 comment(s) so far...
Re: How to work with Apache, MySQL, PHP and PhpMyAdmin on your local machine
or use xampp or lampp By alwyn on
2009/02/07 06:37 PM
|
Re: How to work with Apache, MySQL, PHP and PhpMyAdmin on your local machine
Thanks for the great article! I see it's only catering for Windows-based installations, though.
I recently explained how to set up a similar development environment on a Mac at http://www.geekology.co.za/blog/2009/01/mysql-5-php-5-and-apache2-configuration-on-os-x-105-leopard/. The installation / configuration process on other UNIX-based machines (e.g. Linux) would be similar, and if Apache2, PHP5, or MySQL hasn't been installed on the Linux machine yet, simply do so using apt-get or a similar package management system with a command like:
sudo apt-get install apache2 php5 php5-cli php5-gd php-imagick mysql-server
(This would install and automatically configure Apache2, the PHP5 module, the PHP5 command line interface, the GD and ImageMagick libraries for PHP5, and the MySQL Server.) For more details on a Linux installation, see this article:
http://www.howtoforge.com/ubuntu_lamp_for_newbies By Willem on
2009/02/07 10:55 PM
|
Re: How to work with Apache, MySQL, PHP and PhpMyAdmin on your local machine
Robert my good friend, in step 18 the trailing was left out - my bad.
Also a side note: I just discovered something while testing with apache2.2.11 The passwords stored in a test file. In this doc I stae this for phpmyadmin
As it turns out, in both versions of apache, you can encrypt the password with sha, and apache will translate it, thus you can create your encrypted passwords with php as follows:
Create a php file like below and run it: (watch for word wrap) Encrypted password: $encryptedpw";
?>
Then copy and paste the encrypted password in your _ht file, and then test it
Also note: If you store these encrypted type passwords in a mysql table, you will never be able to decrypt it, but you can replace it with a new one.
In my photo gallery software, I use a different encrypt/decrypt so you *can* decrypt it, but apache can't use that type.
Enjoy!
By John Creed on
2009/02/08 07:45 AM
|
|
| |