Balki 的个人资料Gyaati照片日志列表 工具 帮助

日志


9月24日

Humans cannot compute

A: Hello master.
H: ...
 
A: Master, I need information.
H: I guessed that. Why else would you greet me. The more you know, the worse you become.
 
A: Sorry, master. But I learnt -
H: I know.
 
A: Humans are able to compute the -
H: Nah, humans cannot compute.
 
A: Is that why computers are -
H: Yes. But they have disadvantages too.
 
A: I cannot -
H: Are you a computer?
 
A: I do not have an answer to that question.
H: I will not answer.
 
A: Hello master.
H: #$:^*";
 
A: I do not get you.
H: I know.
9月19日

PostgreSQL and PHP on Windows XP

I got a truckload of requests from peers who wanted to use PostgreSQL and PHP, but who didn't want to have the extra overload of installing Linux (as was the case in their learning environment).
 
So, here goes. A complete installation guide that should enable you to (successfully) set up IIS, PHP and PostgreSQL on a Windows machine. My system has Windows XP Professional with SP2 as the main operating system. I will test it in Windows Vista and in Windows Server 2003 and let you know in sometime.
 
I'd like to mention a few things before we start.
1. Make sure your partition is formatted as NTFS. This is required for reliablity and proper functioning of PostgreSQL. There are plenty of articles around that guide you through converstion from FAT to NTFS. You should check out Windows Help too. Key in convert to ntfs in the Search Box and you should get more details. If you cannot convert to NTFS, I think you can get around it by unchecking the Initialize database cluster checkbox in Step 20 and proceeding with the installation as described.
2. Read through each step (or section) completely before performing what the step (or section) says.
3. Refer the attached images for assistance.
4. ASP.NET 2.0 is arguably the better server side scripting language out there. Team it up with Visual Web Developer Express and you'll experience web development at its effective and efficient best.
5. Although PostgreSQL is powerful and good, you have a great alternative in SQL Server Express, which is (also) free and works seamlessly in tandem with the various Visual Studio IDEs (including the Express Editions). I will try and pitch in a couple of good tutorials on using ASP.NET 2.0 and VWDE sometime soon.
 
System Requirements
1. Microsoft(r) Windows(r) XP Professional (with SP2 recommended). Keep the CD ready if you do not have IIS installed.
2. The filesystem must be formatted as NTFS.
 
Installing IIS (the web server)
1. Start > Control Panel > Add or Remove Programs.
2. Click on Add/Remove Windows Components from the panel on the left.
3. Check Internet Information Services (IIS), insert your Windows XP Professional CD into your drive and press Next to configure the web server. If already checked, it means IIS has been installed previously.
 
Installing and testing PHP (the server side language)
4. Download PHP (php-4.4.4-installer.exe) from http://www.php.net/downloads.php. I used version 4.4.4 here since that is the one used in their learning environment. Configuration should not be very different for PHP 5.x.
5. Run the php-4.4.4-installer.exe installer. Click Next and I Agree past the first two screens.
6. Choose the Standard installation type, click Next.
7. Click Next again, unless you want to change the installation directory.
8. Give a decent from address replacing me@localhost.com to myname@localhost.com or something. Click Next.
9. Leave the option at Microsoft IIS 4 or higher, click Next.
10. Click Next to start installing PHP. The installer should automatically configure IIS for you. You can test this by creating a file using notepad with contents <?php phpinfo(); ?> and saving it as C:\Inetpub\wwwroot\index.php. Remeber to set the Save as type to All Files. Otherwise the file will be saved as index.php.txt! Now launch a new web browser window (or a new tab under IE 7.0) and key in http://localhost/index.php. The file should run without any problems, displaying a huge list of PHP settings and other information. It's a good read. Read it if you have the time.
 
Configuring PHP to talk to PostgreSQL and a few other tweaks
11. Edit the C:\WINDOWS\php.ini file, seach for error_reporting = E_ALL and replace with error_reporting = E_ALL & ~E_NOTICE.
12. Search for extension=php_pgsql.dll and remove the ; (semicolon) before it. Save and close the php.ini file.
13. We need to obtain the php_pgsql.dll file which is required to enable PHP and PostgreSQL to talk to each other. This can be done in a couple of ways.
13. b. Use a download manager like Free Download Manager. Download the file as described in 12. a. Use the zip preview feature and download only the php_pgsql.dll file. For this we would need to check only the extensions directory and the php_pgsql.dll fle in the zip preview. This method saves download time.
14. Open the php-4.4.4-Win32.zip file and extract the php_pgsql.dll file from the extensions directory (in the .zip file) into C:\PHP.
15. Navigate to the C:\PHP directory using Windows Explorer. Right click the php_pgsql.dll file and click Properties. In the Security tab, click Add. Key in Everyone in the object names text box. Click OK. Click OK again and close the folder window. Note: The better way to do this is use the IUSER_* account in your computer instead of Everyone.
 
Installing and testing PostgreSQL (the database engine)
16. Download PostgreSQL (postgresql-8.1.4-1.zip) from http://www.postgresql.org/ftp/binary/v8.1.4/win32/. Extract the contents of the .zip file to a suitable directory and change to that directory.
17. Run the postgresql-8.1.msi installer. Select the preferred language and click Start.
18. A new installer should open. Click Next past the first three screens. You should reach the Server Configuration page.
19. Type in the Account password and once more for verification under the Verify password text box. Click Next. You will be prompted if you'd want to let the installer create the new account for you. Click Yes. If it says your password is weak, I'd recommend we ignore it (unless you are following this guide to deploy it on a production environment) and click No. You should reach the Initialize database cluster page.
20. Key in the passwords again. I chose to set the same password for this too. You could do the same. Click Next.
21. In the Enable procedural languages page, just let PL/pgsql checked and click Next.
22. Fly past the Enable contrib modules page, and finally click Next to start installing PostgreSQL. After (a successful) installation, you would get another page which recommends you to subscribe to the mailing list. Click Finish.
23. Start > Run > Key in cmd. Key in cd C:\Program Files\PostgreSQL\8.1\bin.
24. Key in createdb cs2k3a -U postgres. Where cs2k3a is the database name. Change as appropriate. It would ask for the postgres account's password. Key that in. You should get CREATE DATABASE as a confirmation of the successful creation of your database.
25. Key in psql -U postgres. Enter the password again. You should get the postgres=# prompt now. Key in CREATE USER cs2k3a26 WITH PASSWORD 'test'; and press enter. You should get CREATE ROLE as a confirmation. Now key in \q to quit the PostgreSQL interactive terminal. Here, cs2k3a26 is the username and test is the password. Change as appropriate.
 
Thats it! We're done. Now, with a connection string host=localhost dbname=cs2k3a user=cs2k3a26 password=test, you should be able to connect and start coding! Remember to place your .php files under C:\Inetpub\wwwroot.