1. Trang chủ
  2. » Công Nghệ Thông Tin

Phát triển web với PHP và MySQL - p 83 ppsx

10 210 0

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

THÔNG TIN TÀI LIỆU

FIGURE A.4 The Services Control Manager allows you to configure the services running on your machine. To test whether or not MySQL is working, you can execute the following commands: C:\mysql\bin\mysqlshow C:\mysql\bin\mysqlshow -u root mysql C:\mysql\bin\mysqladmin version status proc C:\mysql\bin\mysqladmin -u root shutdown These commands all work the same with the various Windows operating systems. MySQL will create two databases, the mysql and test databases. The mysql database will be used for storing the permissions and access to the server. The test database is not required, but gives you a safe place to execute commands to see if things are configured correctly. If you need more information, please refer to the MySQL Web site, http://www.MySQL.com. We are now ready to install Apache under Windows. Let’s begin! Installing Apache Under Windows Apache 1.3 and later is designed to run on Windows NT 4.0 and Windows 2000. The installer will only work with the x86 family of processors, such as Intel’s. However, Apache can also run on Windows 95 and 98, but these have not been tested. In all cases TCP/IP networking must be installed. Make sure you use the Winsock 2 library if you decide to install it under either Win95 or Win98. It is recommended that you download the version of Apache for Windows with the .exe exten- sion if you are a beginner and don’t want to compile the source code. This single file contains the Apache server ready to be installed. Run the file you downloaded, apache_1_3_x_win32.exe by double-clicking on it. The installation process should look familiar to you. As shown in Figure A.5, it looks similar to many other Windows installers. Installing PHP 4 and MySQL A PPENDIX A A INSTALLING PHP 4 AND MYSQL 795 38 7842 app a 3/6/01 3:40 PM Page 795 FIGURE A.5 The Apache installer is easy to use. The install program will prompt you for the following: • The directory to install Apache. (The default is C:\Program Files\Apache Group\Apache.) • The start menu name. (The default is Apache Web Server.) • The installation type. The Typical option installs everything except source code. The Minimum option does not install the manuals or source code. Choose Custom if you want the source code. After installing Apache, you might need to edit the configuration files that live in the conf directory. We will look at editing the configuration file httpd.conf when we install PHP. Running Apache for Windows Essentially there are two ways you can run Apache: • From a console window • As a Windows service The service option is generally used with Window NT and Windows 2000. Use this option if you want Apache to start automatically when your machine boots, and to keep it running after you log off. The console option is intended primarily for Windows 95 and Windows 98 users. However, a server was introduced with version 1.3.13 that enables Win 95 and Win 98 users to run Apache as a service. This server is considered highly experimental by its developers. We will install Apache as a service only after we have successfully tested it from the console window. Therefore, we’ll first cover how to start Apache from the console and then cover the service method. Appendixes P ART VI 796 38 7842 app a 3/6/01 3:40 PM Page 796 Running Apache in a Console Window To run Apache from the console window, select the Start Apache as console App option from the Start menu. This will open a console window and start Apache inside it. This window will remain active and open until you stop the Apache server. To stop it, you could either run the Shutdown Apache as Console App option from the Start menu or open another command window and type the following (for version 1.3.3 and earlier): C:\Program Files\Apache Group\Apache> apache -k shutdown Unlike MySQL, Apache doesn’t start as a background process, so you can also stop it by pressing Control-C or Control-Break in the Apache console window or closing the console window. (Again, this only works for versions older than 1.3.3.) Running Apache as a Service Before you can start Apache as a service, you must install it as a service. Keep in mind that multiple Apache services can be installed on one machine with different names and configura- tions. To install the default Apache service (named Apache), run the Install Apache as Service (NT only) option from the Start menu. Open the Services window (in the Control Panel), select Apache, and then click Start. Apache will now be running, hidden in the background. You can later stop Apache by clicking Stop. As an alternative to using the Services window, you can start and stop the Apache service from the command line with NET START apache NET STOP apache Note that this is similar to the MySQL server for NT and Windows 2000. Apache, unlike other NT and Win2000 applications, logs any error to its own error.log file found within the Apache server root folder. It does not provide details through the standard Event Log. As mentioned previously, multiple instances of Apache can be installed and run as services. To signal an installed Apache service to start, restart, or shut down, you will need to provide its service name as follows: apache -n “service name” -k start apache -n “service name” -k restart apache -n “service name” -k shutdown For the default Apache service, the -n Apache option is still required because the -k commands without the -n option are directed at Apache running in a console window. The quotes are only required if the service name contains spaces. Installing PHP 4 and MySQL A PPENDIX A A INSTALLING PHP 4 AND MYSQL 797 38 7842 app a 3/6/01 3:40 PM Page 797 Apache will be listening to port 80 (unless you changed the Port, Listen, or BindAddress direc- tives in the configuration files) after it starts. To connect to the server and access the default page, launch a browser and enter this URL: http://localhost/ This should respond with a welcome page similar to that shown in Figure A.1, and a link to the Apache manual. If nothing happens or you get an error, look in the error.log file in the logs directory. If your host isn’t connected to the Internet, you might have to use this URL: http://127.0.0.1/ This is the IP address that means localhost. If you have changed the port number from 80, you will need to append :port_number on the end of the URL. Note that Apache CANNOT share the same port with another TCP/IP application. Differences Between Apache for Windows and UNIX Here are the main differences between Apache for Windows and Apache for UNIX: • Apache for Windows is multithreaded, but it does not use a separate process for each request, as with UNIX. Instead there are usually only two Apache processes running: a parent process and a child, which handles the requests. Within the child, a separate thread handles each request. So, process management directives are different. • The directives that accept filenames as arguments now must use Windows filenames instead of UNIX ones. However, because Apache uses UNIX-style names internally, you must use forward slashes, not backslashes. Drive letters can be used; if omitted, the drive with the Apache executable will be assumed. • Apache for Windows has the capability to load modules at runtime, without recompiling the server. If Apache is compiled normally, it will install a number of optional modules in the \modules directory. To activate these, or other modules, the new LoadModule directive must be used. For example, to active the status module, use the following (in addition to the status-activating directives in access.conf): LoadModule status_module modules/mod_status.so See the online manual for details at http://httpd.apache.org/docs/mod/mod_so.html#loadmodule • Apache for Windows version 1.3 series is implemented in synchronous calls. This poses an enormous problem for CGI authors, who won’t see unbuffered results sent immedi- ately to the browser. This is not the behavior described for CGI in Apache, but it is a Appendixes P ART VI 798 38 7842 app a 3/6/01 3:40 PM Page 798 side-effect of the Windows port. Apache 2.0 is making progress to implement the expected asynchronous behavior, and we hope to discover that the NT/2000 implementa- tion enables CGIs to behave as documented. If you need to enable Apache with SSL in Windows, you will need to compile the Apache source code. Refer to the Apache.org, OpenSSL.org, and ModSSl.org sites for more informa- tion on how to do this, or look at the UNIX installation for reference. It’s not difficult, but will require more work. Installing PHP for Windows Okay, now we are ready to install PHP for Windows. Make sure you stop Apache before you start the PHP installation process. The process is extremely simple if you understand that, unlike PHP 3, PHP 4 is divided into several components, which require that several DLLs be used. That is, you can’t run PHP in its CGI mode as a standalone executable. You must ensure that the DLLs in the distribution exist in a directory (any directory) that is in the Windows path. The easiest way to do this is to copy these DLLs to your SYSTEM (Windows 9x) or SYSTEM32 (Windows NT) directory, which is under your Windows directory. The DLLs that need to be copied are MSVCRT.DLL (it might already be there) and PHP4TS.DLL. We have provided the outline here as a “cookbook” installation guide. You should have no problem installing and setting up PHP in your Windows machine, if you follow it. 1. Start by copying the php.ini-dist to your ‘%WINDOWS%’ directory and rename it to ‘php.ini’. The ‘%WINDOWS%’ variable usually points to C:\WINDOWS for Windows 9x and C:\WINNT for NT servers. 2. Edit the php.ini file and change the extension_dir setting to point to the directory con- taining the DLL modules for the extensions. Set the doc_root to point to the Web servers document root, that is, the outside visible root directory of the server. 3. Uncomment out in the php.ini file the modules you would like to load when PHP starts. Uncomment the extension=php_*.dll lines to load the modules. Note that some mod- ules require additional libraries installed on the system for the module to work correctly. Also note, that MySQL support is now built in to PHP 4; it doesn’t require loading via this method. Now all you need to do is edit the httpd.conf file in the Apache conf directory to configure Apache to work with the PHP CGI binary. Add the following directives to the config file. • ScriptAlias /php/ “c:/path-to-your-php-dir/” • AddType application/x-httpd-php .php • AddType application/x-httpd-php .phtml • Action application/x-httpd-php “/php/php.exe “ Installing PHP 4 and MySQL A PPENDIX A A INSTALLING PHP 4 AND MYSQL 799 38 7842 app a 3/6/01 3:40 PM Page 799 Note that with the AddType directive, you can specify how Apache should handle the various file extensions. In the case previously mentioned, we specify that Apache treats any file con- taining .php and .phtml as a PHP-interpreted file. You could, for example, treat regular .htm and .html files as PHP scripts by adding the following directive: • AddType application/x-httpd-php .html • AddType application/x-httpd-php .htm You will find more information about other directives that you can set in the configuration file at the Apache Web site, http://www.apache.org. Let’s Test Our Work Start Apache 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 of Apache 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 Apache and PHP working together. Remember to test for MySQL working with them. Do this by writing a simple PHP script to connect to the server and insert/extract some data on the database. 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. It assumes that you have read and installed MySQL as described in the previous section. The first thing you need to do is to install the DLLs as mentioned in the previous section—that is, install the MSVCRT.DLL and PHP4TS.DLL to the Windows directory. Also make sure that you know what to put into the test.php file as described previously. Installation Notes for Microsoft IIS Here are the “cookbook” procedures for the installation of PHP in Microsoft Internet Information Server: 1. Copy either the php.ini-dist or the php.ini-optimized file into your Windows direc- tory, and rename it to ‘php.ini’. Change the defaults by modifying any of the directives inside it. Appendixes P ART VI 800 38 7842 app a 3/6/01 3:40 PM Page 800 2. Start the Microsoft Management Console (it might appear as the Internet Services Manager, either in your Windows NT 4.0 Option Pack branch or in the Control Panel, Administrative Tools under Windows 2000). 3. Right-click the Web server node and select Properties. Under ISAPI Filters, add a new ISAPI filter. This dialog box is shown in Figure A.6. Use PHP as the filter name, and supply a path to the php4isapi.dll that is included in the PHP 4 distribution. Installing PHP 4 and MySQL A PPENDIX A A INSTALLING PHP 4 AND MYSQL 801 FIGURE A.6 Adding the PHP interpreter as an ISAPI filter. 4. Under Home Directory, click the Configuration button and add a new entry to the Application Mappings. Use the path to the php4isapi.dll as the executable, supply .php as the extension, leave Method exclusions blank, and check the Script engine check box. 5. Stop IIS completely by typing ‘net stop iisadmin’ on a command prompt. 6. Now start IIS again by typing ‘net start w3svc’ on a command prompt. 7. Put the test.php file under your Web server’s document root. The test.php file will contain the following line: <?php phpinfo(); ?> If it works, you should see something similar to Figure A.2. Installation Notes for Microsoft PWS 1. Install the php.ini file and the DLLs as mentioned previously. 38 7842 app a 3/6/01 3:40 PM Page 801 2. Edit the enclosed PWS-php4.reg file to reflect the location of your php4isapi.dll. Forward slashes should be escaped, for example: [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\w3svc\parameters\ Script Map] “.php”=”C:\\Program Files\\PHP\\php4isapi.dll” 3. In the PWS Manager, right-click a given directory you want to add PHP support to, and select Properties. Check the Execute check box, and confirm. That’s it! At this point, PWS should have built-in PHP support. 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.MySQL.com and http://www.php.net respectively. Appendixes P ART VI 802 38 7842 app a 3/6/01 3:40 PM Page 802 APPENDIX B Web Resources 39 7842 App B 3/6/01 3:38 PM Page 803 Appendixes P ART VI 804 This appendix lists some of the many resources available on the Web, which can be used to find tutorials, articles, news, and sample PHP code. These are just some of the many out there. Obviously there are far more than we could possibly list in one appendix. And many more that are popping up daily as the usage of and familiarity with PHP and MySQL continues to increase among Web developers. Some of these resources will be in different languages like German or French or something other than your native language. We suggest using a translator like http://www. systransoft.com to browse the Web resource in your native language. PHP Resources PHP.Net—http://www.php.net—The original site for PHP. Go here to download all the sources of PHP and for a copy of the manual. ZEND.Com—http://www.zend.com—The source for the ZEND engine that powers PHP 4.0. A portal site that contains forums, and a database of sample classes and code that you can use. A must see. PHPWizard.net—http://www.phpwizard.net—The source of many cool PHP applications like phpMyAdmin; an excellent front end GUI for Managing MySQL Servers. You can also find tutorials on PHP at this site. PHPBuilder.com—http://www.phpbuilder.com—The portal for PHP tutorials. At this site, you will find tutorials on just about anything you can think of. Site also has a forum and mes- sage board for people to post questions. DevShed.com—http://www.devshed.com—Portal type site offers excellent tutorials on PHP, MySQL, Perl, and other development languages. A must see for newbies. PX-PHP Code Exchange—http://px.sklar.com—A great place to start. Here you will find many sample scripts and useful functions. The site is organized for finding things easily. The PHP4 Resource—http://www.php-resource.de—A very nice source for tutorials, arti- cles, and scripts. The only “problem” is that the site is in German. We recommend using a translator service site to view it. This is how we view it. WeberDev.com—http://www.WeberDev.com—Formerly known as Berber’s PHP sample page, this site grew significantly from nothing to a place for tutorials and sample codes. The site tar- gets PHP and MySQL users, and covers security and general databases, as well as NT. The only issue is that it requires you to subscribe. But it’s well worth it, considering the informa- tion it provides. 39 7842 App B 3/6/01 3:38 PM Page 804 . the PHP CGI binary. Add the following directives to the config file. • ScriptAlias /php/ “c:/path-to-your -php- dir/” • AddType application/x-httpd -php .php • AddType application/x-httpd -php .phtml •. .phtml • Action application/x-httpd -php “ /php/ php.exe “ Installing PHP 4 and MySQL A PPENDIX A A INSTALLING PHP 4 AND MYSQL 799 38 7842 app a 3/6/01 3:40 PM Page 799 Note that with the AddType directive,. could, for example, treat regular .htm and .html files as PHP scripts by adding the following directive: • AddType application/x-httpd -php .html • AddType application/x-httpd -php .htm You will

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

Xem thêm: Phát triển web với PHP và MySQL - p 83 ppsx

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

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

TÀI LIỆU LIÊN QUAN