PHP and MySQL Web Development - P168 pps

5 122 0
PHP and MySQL Web Development - P168 pps

Đang tải... (xem toàn văn)

Thông tin tài liệu

807 Installing Apache, PHP, and MySQL Under Windows Using InstallShield The installer comes as an executable file. Begin by stopping your Web server, and then double-click the installer to run it. The installer will ask you if you would like to use the standard or advanced setup. The standard setup will ask you very few questions: It will ask you what directory to install to, where your mail server lives, what your email address is, and the type of web server you have. The advanced setup will also ask you n If you want to create backups during the installation n Where you would like uploaded files to be placed n Where you would like session data stored n What error reporting level you would like n What file extensions you would like Apache to recognize Manual Installation Begin by unzipping the Zip file to the directory of your choice.The usual location is c:\PHP, and we will use this in the following explanation. 1. In the main directory you will see a file called php.exe, and one called php4ts.dll. These are the files you will need to run PHP as a CGI. If you would like to run it as a SAPI module you will need to look in the directory c:\PHP\sapi and copy the relevant DLL file to C:\PHP. If you are using Apache, the file is called php4apache.dll for example. The SAPI modules are faster and easier to secure; the CGI version allows you to run PHP from the command line. Again, the choice is up to you. 2. Copy the contents of c:\PHP\dlls to your Windows system directory.This will be C:\winnt\system32 on Windows NT or 2000 or C:\windows\system32 on Windows XP. 3. Move the directory c:\PHP\mibs to c:\usr\mibs. 4. Set up a php.ini configuration file. PHP comes with two prepared files: php.ini-dist and php.ini-recommended.We suggest you use php.ini-recommended. Make a copy of this file and rename it php.ini. Place your php.ini file in the ‘%SYSTEM- ROOT%’ directory.This is usually c:\winnt or c:\winnt40 on Windows NT or 2000, or c:\windows on Windows XP. 5. Edit your php.ini file.There are many settings in it, most of which can be ignored for the time being.The settings you need to change now are n Change the extension_dir directive to point to the directory where your extension DLLs reside. In the normal install this will be C:\PHP\extensions. Your php.ini will therefore contain extension_dir = c:/php/extensions 39 525x appA 1/24/03 3:38 PM Page 807 808 Appendix A Installing PHP and MySQL n Set the doc_root directive to point at the root directory that your Web serv- er serves from.This is likely to be doc_root = "c:/Program Files/Apache Group/Apache/htdocs" if you are using Apache, or doc_root = "c:/Inetpub/wwwroot" if you are using IIS. n You can also choose some extensions to run.We suggest at this stage that you just get PHP working; you can add extensions as needed. In order to add an extension, look at the list under “Windows Extensions”.You will see a lot of lines such as ;extension=php_pdf.dll In order to turn this extension on, you can simply remove the semicolon at the start of the line (and do the opposite to turn it off). Note that if you want to add more extensions later, you should restart your Web server after you have changed php.ini in order for the changes to take effect. Close and save your php.ini file. 6. If you are using NTFS, make sure the user that the Web server runs as has permis- sion to read your php.ini file. Adding PHP to your Apache Configuration You may need to edit one of Apache’s configuration files. Open up the file httpd.conf in your favorite editor.This file is typically located in the c:\Program Files\Apache Group\Apache\conf\ directory. Look for the following lines: ScriptAlias /php/ "c:/php/" AddType application/x-httpd-php .php Action application/x-httpd-php "/php/php.exe " If these lines are not there, add them at the end of the file, save it, and restart your Apache server. Adding PHP and MySQL to Microsoft IIS and PWS This section will cover how to add PHP and MySQL support to IIS with the ISAPI (php4isapi.dll) module. (You can also install it as a CGI, but we strongly recommend you use the ISAPI module as it is faster.) It assumes that you have followed the steps in either the “Using InstallShield” or “Manual Installation” sections.The main difference is that the doc_root configuration directive is likely to be “c:/Inetpub/wwwroot”. Once you have done that, you need to start the Microsoft Management Console (which may appear on your system as the Internet Services Manager). If you have NT 39 525x appA 1/24/03 3:38 PM Page 808 809 PEAR Installation this can be found in the NT4 Option Pack. If you have 2000 or XP it can be found in the Control Panel under Administrative Tools. Once this is open, you should see a tree view of services on the left side. Right-click the Web server (usually called Default Web Server) and select Properties. You will be shown the Properties dialog box.This contains quite a lot of information but we only need to change a few things. Under Home Directory click the Configuration button. Under App Mappings, select Add to add PHP. It will ask you for an executable. Supply the full path to the location of php4isapi.dll (probably c:\php\sapi\php4isapi.dll if you have followed these instructions). There is also a box labeled Extension in which you should type .php.You also need to have the Script Engine box checked. Click OK. If you want to be able to do HTTP Authentication (which we cover in this book) you should also look under ISAPI filters. Select Add.You will be asked for a filter name—type PHP—and an executable—supply the full path to the php4isapi.dll file as above. Click OK. Close the Properties dialog by clicking Apply. You should now stop (or check that it is stopped) and restart the Web server.You can do this from the Management Console/Internet Services Manager by right-clicking on the Web server and choosing Stop.You can restart in the same way by selecting Start. Let’s Test Our Work Start your Web server and test to ensure that you have PHP working. Create a test.php file and add the following lines to it: <? phpinfo(); ?> Make sure the file is in the document root directory (typically c:\Program File\Apache Group\Apache\htdocs under Apache or c:\Inetpub\wwwroot under IIS) and then pull it up on the browser, as follows http://localhost/test.php or http://your-ip-number-here/test.php If you see a page similar to that shown in Figure A.2, you know that you have PHP working. PEAR Installation PHP 4.3 is supposed to come with the PEAR package installer. At the time of writing, the Linux version installs automatically, but the Windows version did not include this. If you are using Windows or an earlier version of PHP (from 4.1 to 4.2.3) you will need to download the package installer separately.You can obtain this from http://go-pear.org 39 525x appA 1/24/03 3:38 PM Page 809 810 Appendix A Installing PHP and MySQL There is exactly one script at that site. Save it as go-pear.You need to run this script through PHP from the command line. Go to the command line and type php go-pear The go-pear script will ask you a few straightforward questions about where you would like the package installer and the standard PEAR classes installed, and will then down- load and install them for you. At this stage you should have an installed version of the PEAR package installer. You can then simply install packages by typing pear install package where package is replaced with the name of the package you wish to install. To get a list of available packages, type: pear list-all To see what you have installed currently try pear list To install the MIME mail package used in Chapter 28,“Building a Mailing List Manager,” type: pear install Mail_Mime The DB package mentioned in Chapter 10,“Accessing Your MySQL Database from the Web with PHP,” is installed automatically, but to make sure you have the newest version you can type pear list-upgrades If there is a newer version available type pear upgrade DB At the time of writing it was difficult to get the PEAR package installer working on Windows. If the above procedure does not work for you, we suggest you try download- ing PEAR packages directly rather than via the installer. To do this, go to http://pear.php.net/packages.php From here you can navigate through the various packages available. For example, in this book we use Mail_Mime. Click through to the page for this package and click Download Latest to get a copy.You will need to unzip the file you have downloaded and put it somewhere in your include_path. You should have a c:\php\pear or similar directory. If you are downloading packages manually we suggest you put the packages in the pear directory tree. PEAR has a stan- dard structure so we suggest you put things in the standard location—this is where the installer would put them. For example, the Mail_Mime package belongs in the Mail sec- tion so in this example we would place it in the c:\php\pear\Mail directory. 39 525x appA 1/24/03 3:38 PM Page 810 811 Other Configurations Other Configurations You can set up PHP and MySQL with other Web servers such as Omni, HTTPD, and Netscape Enterprise Server.These will not be covered in this appendix, but you can find information on how to set them up at the MySQL and PHP Web sites: http://www.php.net and http://www.mysql.com respectively. 39 525x appA 1/24/03 3:38 PM Page 811 . Look for the following lines: ScriptAlias /php/ "c: /php/ " AddType application/x-httpd -php .php Action application/x-httpd -php " /php/ php.exe " If these lines are not there,. Installing PHP and MySQL There is exactly one script at that site. Save it as go-pear.You need to run this script through PHP from the command line. Go to the command line and type php go-pear The go-pear. the directory c: PHP mibs to c:usrmibs. 4. Set up a php. ini configuration file. PHP comes with two prepared files: php. ini-dist and php. ini-recommended.We suggest you use php. ini-recommended.

Ngày đăng: 07/07/2014, 03:20

Mục lục

    PHP and MySQL Web Development

    Part I: Using PHP

    Chapter 1: PHP Crash Course

    Chapter 2: Storing and Retrieving Data

    Chapter 4: String Manipulation and Regular Expressions

    Chapter 5: Reusing Code and Writing Functions

    Part II: Using MySQL

    Chapter 7: Designing Your Web Database

    Chapter 8: Creating Your Web Database

    Chapter 9: Working with Your MySQL Database

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan