Getting started with PHP Gichu
Key points in this chapter
■ Deciding to outsource or build in-house
■ Find an appropriate ISP
■ Avoid common hosting pitfalls
■ Install PHP
■ Choose PHP development tools
In this chapter , we'll discuss the pros and cons of various web hosting options: outsourced, self-hosted, and different compromises. Next we discuss the details of installing PHP, and finally some advice on finding the right development tools. By the end of this chapter, you should be able to start working on your first script.
Comparison of Web Hosting and DIY
The first important decision you need to make is: who will control and manage the PHP-enabled Web website, you or the vendor that provides Web hosting services? Also, will a separate development installation be required; if so, who will host it? If you have already made your decision, you can skip this part and go directly to the installation part of this chapter.
Choose an ISP
As many ISP companies have begun to provide web services that support PHP, remote virtual hosting (Remote Hosting) has gradually become a mainstream choice. Here are some basic concepts to remember.
Advantages
Outsourced virtual hosting has many advantages. In theory, the ISP has the responsibility (in theory) to master many key technical and administrative details to keep the site up and running, including:
■ Hardware
■ Software upgrades
■ InterNIC Registration, IP addressing, DNS
■ Mail server (POP/IMAP and SMTP)
■ Broadband
■ Power supply
■ Backup
■ Security
If something goes wrong with the user’s website, ISP technology People's mobile phones have to be turned on in the middle of the night; users can sleep more peacefully by understanding this. Lurking crackers, power outages, failed backup tapes, all of these headaches are now left to the hosting company.
In most cases, web hosting is more cost-effective. PHP on Linux or one of the BSDs is very cheap and easily available. Currently, only a few companies provide PHP for the NT server platform, and of course some of them are very expensive. Anyway, read more and compare to find a suitable ISP service provider.
Disadvantages
Of course, ISP web hosting also has some serious disadvantages.
Fortunately, most of these shortcomings can be controlled. When using an ISP, the user is essentially a "guest" himself and must follow someone else's rules. Maybe you are a paying and welcome good guest, but it is still not as convenient and casual as being in someone else's home.
The most concerning issue is the comparison between PHP modules and CGI. PHP performs best and fastest as a module. In other words, the module is built into the web server itself, rather than being executed as a separate process. Almost everyone is willing to use a modded version whenever possible. However, many ISPs prefer to implement the CGI version because security management of it is simpler. Fortunately, more and more virtual hosting services on the market have been improved, making it easier for you to find mods.
Currently, the biggest problem with using outsourced PHP virtual hosts is that you cannot obtain other program resources. Obviously ISPs encourage you to design programs on their servers, but there are many PHP parameters that must be between some services and communication protocols. Unable to execute some unauthorized execution formats or link to libraries in your directory.
There is an unchanging rule: the more common the demand, the more likely and suitable it is to outsource the virtual host. If the demand is more special, the more likely it is that you need to set it up yourself. Of course, there's actually an unwritten rule: the larger your site is, the more money it's going to cost, and the greater the trade-off of handing it over to someone else to manage it.
The following factors can make it more difficult to find a web hosting service:
■ Generally controversial content (violence, pornography).
■ Unsolicited emails, also known as spam.
■ Content that attracts crackers (security information).
■ Potentially illegal content that could cause problems.
■ Requirements that require unusual server hardware, operating systems or software.
■ Demand for ultra-large bandwidth (especially not unpredictable bandwidth).
If you are in one of the above situations, you need to inform us in advance. If you can find a good and suitable virtual hosting service, don't hesitate anymore, seize the opportunity and use it, and then slowly find a better way to deal with it in the future.
Finally, the most important of all negatives must be mentioned: poor web hosting service can cause you a lot of frustration and worry. Indescribable is the gnashing of teeth, stomach cramps, and screams of writing when your web page is listed on Slashdot but cannot be displayed, making you appear to be public but lose all opportunities to perform.
Not to mention other common problems, such as mysteriously missing emails, missing DNS, unexplained website disconnections, missing database data (this only happened to us), lack of backup, or waiting for an hour for an electronic call. To talk to their tech support people, who never seem to come near the servers, never respond to your polite emails, and you only get some perks when you pay... (We're not In sarcasm, it's always our lawyers who say we can't mention too much).
The bottom line when choosing a virtual hosting service is: In fact, when you choose a virtual hosting service, you are putting yourself in danger. Be prepared to move out at a moment's notice, which also means not choosing a service that doesn't have a long-term contract and/or requires upfront payment, no matter how cheap or full-featured they are. On the contrary, don't be impatient when dealing with them, and if you've never outsourced web hosting before, take the time to get to know and evaluate the web hosting company (beware of lousy and lousy technical support) versus the underlying Internet traffic issues. difference between.
Details
If you decide to use virtual hosting, you need to know that there are many choices in the current market. However, novice buyers should be careful because the term [ISP] can encompass almost everything and leave you confused. The guidelines in Table 3-1 provide the scope of specialization and most suitable uses (the companies mentioned are examples only and do not constitute an endorsement or recommendation of their services).
Table 3-1 Various ISPs
Although finding a good web hosting service can sometimes be as difficult as finding a lifelong partner, here are some resources that can make the process a little easier:
http://hosts.php.net
http:/ /www.od-site.com/php
http://www.ispcheck.com
Pay more attention to user and market reviews, whether they are good or bad reviews. Ask your friends or colleagues about their experiences. Go online and look for PHP messenger communities or discussion groups. People will occasionally make suggestions and comments about their good and bad experiences.
An issue that may cause controversy when signing a contract is website traffic. Be careful with the advertising slogan "unlimited traffic/bandwidth/clicks". For bandwidth levels that have not been tested by a credible unit, there is no guarantee that it meets the requirements. So before signing a contract, you need to look at it, give it a try, and evaluate the possible results.
How to evaluate bandwidth requirements? 1GB of traffic per month is equivalent to browsing 100,000 average 10K files (including graphics, text, advertisements, etc., everything except third-party service support. It is evaluated and calculated from a user's perspective, and not from the server's perspective).
Be aware of the total disk space required in your website plan, especially for large websites or sites with a lot of graphics. If you exceed the limit, you will typically pay an additional and expensive monthly fee for the excess space. One way to solve this problem is to handle the log file carefully; delete it regularly, or download them to a cheaper storage device.
Principles of choosing to build your own hosting
With the decline in connection costs, self-built hosting has gradually become the choice for many websites. This gives you ultimate control and command, and if used with experience, can provide real security advantages. Installing your own means issues are resolved faster because you don't have to waste time on the phone with technical support, and it's also more fun because you can directly control the actual server whenever you need it. Finally, if you have any unusual, objectionable or different needs, you have to serve your website yourself whether you are willing or not.
On the other hand, self-builders need to do more preparation work, and the purpose may be higher, especially for small and medium-sized websites. Moreover, the quality of self-built hosting sites depends on your own technical capabilities. So if you don't have anyone on your team who knows a little bit about security, be careful when it comes to security. However, you can accumulate experience and learn by yourself. It is not like leaving it to others. Maybe when the engineer in charge of security in their company leaves and a security problem occurs, we can only look at what to do.
The more realistic problem is that if something goes wrong, you can only blame yourself. If you stand in front of the mirror when you wake up in the morning and say to yourself, "It's all on me! This feels so good!" then you will have the confidence you need to build your own console.
A compromise solution
Of course, outsourcing and self-hosting are actually on opposite ends of the spectrum. Beyond this, there are several "compromise" solutions that offer the best of both worlds.
Hosting means packaging your own server host and sending it to a company that provides web hosting services. The other party will hook it up to their network and monitor it for you. You are responsible for purchasing, licensing, insuring, installing, configuring, and maintaining all software and hardware, except for uninterruptible power supplies. Web hosting services provide no disruption to your equipment at all, except for the occasional reboot, which usually comes at an additional cost. If you need additional technical support, you must go to the site yourself or pay to get operators and help. If you adopt a hosting method, it is very likely that you are using a product that the other party's operators have no experience in operating.
Dedicated Server
A dedicated server is exactly what it sounds like: the hosting service will buy a server, adjust it to suit your situation (for a fee of course), and then connect it to their network. All subsequent processing is yours to use. Generally, you will receive technical support, which is more secure than using a shared server environment, and for medium to large websites, it is relatively more cost-effective.
Outsourced production, self-developed
This choice involves two complete installations: an outsourced website and a server (one or more) equivalent to self-developed. If divided according to this idea, you can Get the best of both worlds, someone has to listen to the pager in the middle of the night (always on call), but you can directly control your own server. This is a good option if you're in an area with limited connectivity options. This is also one of the best options for larger websites that require more developers.
Install PHP
If you decide to completely outsource your PHP hosting services, you can skip the rest of this chapter. However, we still recommend that you install your own software first, even if only on your own work machine, as you will have more experience and understanding of the design environment.
Preparations before you start
◆ Before installing PHP on any platform, what you need is:
◆ A server host with enough RAM for your operating system.
◆ UNIX, MAC OS X or Windows operating system installed.
◆ If this is already an official website, it needs to have an ongoing Internet dedicated line connection. If it is still in the development stage, it can be installed on the intranet, or it can be installed separately (although there is no Internet connection, other installation software is still required kit to match).
These prerequisites are beyond the scope of this book. You can find relevant detailed information from the following websites:
World of windows Networking (http://www.wown.com)
Linux Document Project (http://www.linuxdoc…)
If you plan to install on Windows PHP, you also need to meet the following conditions:
◆ A web server that supports PHP. Under PHP3, IIS/PWS was the easiest choice because there were module versions of PHP available for that form, but PHP4 offers a wider selection of modules under Windows.
◆ Installed a database that supports PHP (if you plan to use a database).
◆ If you are using Windows 95, you must have DCOM update, which can be downloaded for free from the following website: http://download.microsoft.com/msdownload/dcom/95/X86/en/dcom95.exe
◆ PHP Windows binary execution file version (can be downloaded from www.php.net/downloads.php).
◆ Decompression program (you can find it at a well-known download website, such as http://download.cnet.com to find a PC file compression program).
If you plan to install PHP on UNIX, you need to meet the following conditions:
◆ PHP source code version (http://www.php.net/downloads.php).
◆ The latest Apache source code version ( Find the highest radix number of the .tar.gz file from http://www.apache.org/dist/ which is the latest version).
◆ If you plan to use a database, you must have a database that supports PHP.
◆ All other supporting software that PHP must connect to (mail server, BCMath suite, JDK, etc.).
◆ ANSI C language compiler.
◆ GNU make (starting from PHP4, other make versions cannot be used, which is especially important for non-GPL authorized Unix such as Solais and BSD. You can download it for free from www.gnu.org/software/make).
◆ Bison and flex (make sure they are in the /usr directory and then type "find .-name bison -print" and "find .-name flex -print" to check whether these contents already exist, or let gcc do it during the make process Check. If not, you can download bison from www.gnu.ory/software/bison and flex from ftp://ftp.ee.lbl.gov).
Up to this point, you have completed the preparations required for the actual installation of PHP.
Please remember that any other servers or software libraries that PHP will connect to must be installed before creation. Databases are the most common type of scaling servers. Other examples include the BC math suite, IMAP server, mcrypt library, and Expat XML parser (unless using Apache, which already includes these components).
Now that you are ready to officially install PHP, the difference between building an Apache module and building a CGI executable is very small. In fact, the difference is only the use of the --with-apache or --with-apax flag when setting. Many users compile both the module version and the CGI version for ease of use.
In the past, many organizations provided programs that installed Apache, PHP, and sometimes MySQL together (such as PHPTriad, Nusphere MySQL, and Zend Launchpad), but unfortunately, these programs seemed to have problems in use and discussion, and Nusphere was serious. In violation of MySQL's license to use, the maintainer of PHPTriad announced that he would no longer maintain the product, and Zend Launchpad had disappeared from the website earlier.
Installation process
Due to PHP's commitment to cross-platform operability, there are too many specific installation methods to adopt. It is impossible to list them all here. We try to introduce them all as they appear to be applicable to PHP. of the most popular platforms, but writing out installation instructions for every possible operating system and web server would make this chapter too long.
Furthermore, although installing PHP on Unix has been stable for many years, the release of PHP 4.0 has made the installation on Windows a little bit different, partly because of the PHP team and partly because of the launch of Windows products, such as Windows XP With a possible update to IIS, PHP can now run on Macintosh OS X, while the installation process on it is still very unstable at the time of this writing.
In view of such rapid changes, we can only remind you that you should refer to the PHP website (http://www.php.net/docs.php)
for the clearest installation information for each download, even if you have installed it repeatedly in the past After many times, it is possible that some new changes will appear after you install it multiple times.
UNIX and Apache
The first time you create your own HTTP daemon from source code, you may be a little worried. However, this process is quite intuitive, and it is a great learning experience to compile your own web server without relying on other people's RPMs. Other people's RPMs may be versions weeks or months ago. If you want to use the new one, just wait. Others are ready. When you do everything yourself and everything works, you will definitely feel like a genius!
For those who have completed this process using previous versions of PHP, the entire process is exactly the same, it just may take a little longer than before.
Reb Hat or Mandrake Linux installations may come with RPM versions of Apache and PHP. These software packages must be removed before compiling your own new PHP. In addition, there can be RPM versions of other server manufacturers, such as MySQL or PostgreSQL, which are different from the installation of the corresponding versions of the source code. If you encounter problems, refer to the documentation of the installation source.
In the following instructions, the source code snippets are entered under the shell prompt symbol.
If you use a personal directory when installing, please remember to log in to the system as root first.
To get started, please follow the steps below:
1. If you have not done this before, first unzip and untar the original version of Apache. Unless there is a reason not to do so, extract it to a standard location such as /usr/local.
Gunzip –c apache_1.3.x.tar.gz
Tar –xvf apache_1.3.x.tar.gz
2. When initially adjusting the Apache server, if you install it in a location other than /usr/local , now you must use the following --prefix option. If you install in /usr/local, don't worry, the Apacche directory is there, it is only used during the build process.
Cd apache_1.3.x
./configure - -prefix=/usr/local/apache
3. Unzip and untar the PHP source code version. Unless there is a reason not to do so, extract them to the standard location of /usr/local. If Apache and PHP are in different directories, the ".." location below must be replaced with the full path of the software package.
cd..
gunzip –c php-4.x.tar.gz
tar –xvf php -4.x.tar
cd php -4.x
4. Set up your own compilation connection (setting PHP is a very big topic and very important. Please refer to Chapter 31 of this book for detailed information). The most common option is to build it as an Apache module and support a specific database. Java and XML support are also becoming increasingly popular. The following example shows the Apache module with MySQL and XML support, but the flags used by readers can be completely different.
./configure - -with-apache=../apache_1.3x - -with –mysql- -with-xml—enable-track-vars
5. Make and install the PHP module.
Make
Make install
6. Set up and make the Apache daemon. Don't worry libphp4.a does not exist in this location, Apache will generate it for you.
cd…/apache_1.3x
./configure-activae-module=src/modules/php4/libphp4.a
Make
7. If you already have the httpd archive, you should close it now and forget about it (in the current Apache version), it will contain the binaries and configuration files you should use.
Make install
8. Set up the php.ini file. To edit this file, refer to the options listed in Chapter 31 of this book. We strongly recommend that new users set error reporting to E_ALL (15).
cd../..php-4.x
cp php.ini-dist/usr/local/lib/php.ini
9. Tell the web server what file extension to use to identify PHP files ( .PHP is the standard extension, but you can also use .html.phtml or any other file extension you want). Please find the HTTP configuration file in /usr/local/apache/cont or other paths you set) and use a text editor to open httpd:conf and search for the word DocumentRoot (it should appear twice) and change the paths of both to The directory where you want to place the files (in our case, /home/httpd), we recommend using the home directory instead of the default /usr/local/apache/htdocs, as it is less secure. At least add... Parse to PHP: (This will require some execution efficiency, especially if you only want to use HTML files with the . html extension) and make sure Apache knows the domain alias or the IP bit read Addressing is also the appropriate thing to do now. (If you don’t know what this means, search for the ServerName in the httpd.conf file and add localhost after it. Use your domain name only after you know more about it)
AddType application/x-ttpd- php.php
AddType application/x-httpd-php.html
10. Restart the server. Every time you change the HTTP settings or php.ini file, you must stop and start the server again for it to take effect. Just using the HUP signal is not enough.
cd../bin
./apachectl start
11. Set the permissions of the file root directory to executable. PHP file permissions only need to be set to readable (644). If necessary, replace /home/httpd with the following file root directory:
Chmod 755/home/httpd/html/php
12. Open a text editor. Type "". Store it in the document root directory of the Web server and name it info.php. To launch any web browser to view this file, you must use the URL (http://www.testdomain.com/info.php), or use the HTTP path http://localhost/info.php or http://127.0. 0.1/info.php, instead of directly using the file path (/home/httpd/info.php), you should see a long information table about PHP4 installation. Congratulations on your successful installation!
Many Apache server products do not use the php.ini file because it may not expect to need different configuration files in two different places. You can move many configuration directives from php.ini to Apache's httpd. conf file, at least you should need to set the include path and error reporting level, because the default settings of these files are unsatisfactory, please refer to Chapter 37 of this book.
Mac OS Perhaps such a combination could enable a Unix machine to be used on every home computer.
In terms of usage, Mac users can choose to install it in executable format or in source code mode. In fact, your OS X machine may have Apache and PHP installed. This may be an earlier version, or Lacking some common support, however, if what you need is Apache+PHP+MySQL/PostgresSQL installed on your computer, this is the easiest way, all you need to do is edit your Apache configuration and enable your web server, so just follow the steps below (again, the following commands are what you need to enter at each step):
1. Open the Apache configuration as root using an appropriate text editor?
Sudo open – a TextEdit/etc/httpd/httpd.conf
2. Edit the file and remove the comments from the following lines:
Load Module php4_module
AddModule mod_php4.c
AddType application/x-httpd-php-php
3. You may also want to remove some annotations that tell Apache which directories to serve.
4. Restart your web server.
Sudo apachectl graceful
5. Now open a document editor and type, save the file as info.php in your website folder, open any web browser and browse the file, you must always use HTTP request method Parse the file correctly (http://www.testdomain.com/-username/info.php or http://localhost/-username/info.php or http://127.0.0.1/-username/info. php) instead of just using the file name (/home/username/info.hph), you should see some long tables recording your new PHP installation. Congratulations.
If you feel that you do not have a PHP module to use, or you want to upgrade your module to a new version, you can download it from many places on the Internet, such as Marc Liyanage in Switzerland, which is the website we use below. If you If you prefer the distribution file, replace the URL in the command:
crl –o http://www2.entropy.ch/download/libphp4.so.gz
gnzip libphp4.so.gz
sdo apxs –i –a –n libphp4.so
sdo apachectl graceful
Writing source files on OS For new PHP users, the method of translating from the source code is less recommended. If you still want to give it a try, there is a good article at Stepwise.com:
http://www.stepwise. com/Articles/Workbench/2001-10-11.01.html
In the future, the installation method on OS X may be forced to change at any time. Always check the OS X system installation page before installing a new version of PHP. :
http://www.php.net/manual/en/install.macosx.php
Windows NT/2000/XP and IIS
Installing PHP4 on a server using IIS4 or 5 on Windows is easier than on Unix Much more convenient since it has a compiled binary meta format and does not require recompilation.
Now there are two options for binary formats using Windows: the automatically installed Installshield and the compressed? method. This method is relatively simple, but has many shortcomings. It can only be used on IIS4 or more or 5 and Xitami and other web servers. It only provides a CGI execution version and cannot use the module method. It lacks the automatic setting process of extensions. It is obviously less secure, so any serious PHP installation on Windows should choose the manual installation method.
Please follow the following steps to install:
1. Use your own decompression tool to decompress the binary compressed files and place all files in the C:PHP folder.
2. Copy some from your PHP directory. Dll file to your system folder (usually C:\Winnt/System32), you must copy php4ts.dll. You may also need to copy the file required for your web server module - C:\PHPSapiphp4isapi.dll, and possibly others from dlls subfolder, but first copy the first two parts of the files above and then add the additional ones you need.
3. Copy php.ini-dist or php.ini-optimized (the latter is more recommended) to your Windows directory (C:Winnt or C:Winnt40) and rename it to php.ini. Open the file with a text editor (for example, using Notepad) and edit the file to use the configuration commands. You can refer to the options listed in Chapter 37. We strongly recommend that new users set the error reporting to E_ALL (15) on the machine they are working on at this time. The most important step at present is the doc_root command in the Paths and Directories section. Add this command to your IIS Inetpub folder ( or anywhere else you want to provide services).
4. Turn the WWW service off and on again. Go to the Start menu, Settings, Control Panel, Services, and go to the IIS Admin Service. Select it and click Close. After it is closed (the status message will tell you), select World Wide Web Publishing Service and click to turn it on, but using the Internet Services Administrator to turn it off and on again (by right-clicking the icon) does not work, as this uses PHP on Windows, so you may need to turn it back on.
5. Open a document editor (such as Notepad), enter and save the file info.php in the file root directory of your web server, open a web browser and browse the file, you must always use the HTTP request method (http://www .testdomain.com/info.php or http://localhost/info.php or http://127.0.0.1/info.php) instead of using the file name (C:inetpubwwwrootinfo.php) to execute the file correctly , you will see a long list recording your PHP4 installation information, congratulations.
Some Windows users reported that they must put the php.ini file and the php.exe executable file in the same directory to use the CGI version of PHP. In terms of security... it would be better, now PHP provides a better way to module for Windows web servers, use this method if you can.
Windows 95/98/Me and PWS
When this book was being edited and revised, Microsoft announced that it would no longer distribute the Personal Web Server (PWS) product for free, which is a simple version of Internet Information Server for desktop use.
According to consideration, this should be a positive development of the Internet. PWS was installed in the past as a way to use PHP with minimal cost and risk (or perceived) on Windows/95/98/Me machines, but these operations The system is not designed to be used as a server, and it is not expected to operate stably for a long time. Therefore, if you want to install a web server and other manufacturers' scripting engines, you must go through a considerable amount of manual adjustment of the login database (Registry) in the past, but this has resulted in Severe damage to many systems and cannot be easily removed cleanly.
In the past, you may have to wait for Microsoft's new web server platform to be quite stable before it can be used on desktop machines, but now we recommend that Windows users call Apache HTTP server a friendly and cheap working platform. What you wrote in Apache PHP programs can actually be executed on IIS (or other final names such as .NET Web Server).
Although it is possible to use folder names with spaces in Windows, we recommend not doing this for PHP-enabled directories as it will cause problems with the installation program.
Windows 95/98/We and Apache
PHP 4.0 launched the long-awaited Windows Apache module. Before this, Windows users of Apache could only use the CGI version of PHP, which was slower and unsafe. PHP 4.1 has significantly improved the performance and stability of this module, and the Apache opener has also worked hard on the Windows HTTP server to significantly improve the performance. For these reasons, there is really no better time than trying Apache, even if This is still the case on Win95/98/Mc machines.
To install PHP on Windows95/98/Me:
1. Download the Apache server from http://www.apache.org/dist/httpd/binaries/win32 and look for a current stable release with the no_src.msi extension (if available, you can also try the Exe version, However, it does not work on all systems and is not easy to install). Double-click this installation file to start the installation. C://Program Flies is a common installation location. The installation tool will also ask you whether you want to connect Apache as a service. To execute (requires more steps, but you can find it in the system slot), or use it in command line mode, DOS prompt characters, etc. We recommend not to install it as a service, because this will cause some problems. Some computers cause problems when starting up and shutting down.
2. Use your compression software to unzip PHP into a folder, C://PHP is a commonly used location.
3. Copy some .dll files from your PHP folder to your system directory (usually C://Windows). You must copy php4ts.dll. You may also need to copy the files required for your web server module - C: //PHP/Sapi/php4apache.dll into your Apche module folder. You may also need other files from the dlls subfolder, but first copy the first two parts of the files above and then add the additional files you need. .
4. Copy php.ini-dist or php.ini-optimized (the latter is more recommended) to your Windows directory (C://Winnt or C: //Winnt40) and rename it to php.ini. Open the file with a text editor (for example, using Notepad) and edit the file to use the configuration commands. You can refer to the options listed in Chapter 37. We strongly recommend that new users set error reporting to E_ALL(15) on the machine they are working on.
5. Tell your Apache server where you want to serve it and what extension you want to use to identify PHP files (.php is the standard extension, but you can also use .html'.phpml, or whatever you want desired extension), open your HTTP configuration location (C:Program FilesApache GroupApachecont or whatever location you use), and use a text editor to open httpd.conf, search for DocumentRoot (it should appear twice) and Change to the location of the folder you want to serve externally (the default is C://Program FilesApache GroupApachehtdocs), and add at least one PHP extension according to the following syntax:
LoadModule php4_module modules/php4apache.dll
AddType application /x-httpd-php.php.phpml
6. You may also need to add the following syntax:
AddModule mod_php4.c
7. Now you also need to make sure Apache knows the domain alias or the IP address it is listening to (if you If you don't know the current dmain, search for ServerName in the httpd.conf file and add localhost after it, and use your domain name after you find a domain).
8. Close and reopen the WWW service. You can execute Apache through the Start menu, Assembly, Apache HTTP Server, Control Apache HTTP Server, Stop/Start, or from the MS-DOS prompt.
9. Open a document editor (such as Notepad), enter, and save the file as info.php in the root directory of your Web server. Open a Web browser and browse the file. You must always use the HTTP request method (http:// www.testdomain.com/info.php or http://localhost/info.php or http://127.0.0.1/info.php) instead of using the file name (C:inetpubwwwrootinfo.php) to execute the program correctly file, you will see a long table recording your PHP4 installation information, congratulations.
If you are not panicked when you follow these instructions but cannot get the results you want, you can refer to Chapter 15 of this book to refer to the frequently asked questions. If it still cannot help you, please refer to the relevant webpages attached to the PH online documents. Note, there are many users who document here specific techniques they use for specific installation problems.
Other Web Servers
The PHP4 executable is supported by many other Web servers, such as Netscape Entetprise Server, Xitami, Zens and thttpd. Modules for AOLServer, NSPAI and fhttpd are already available and you can find them in the PHP Online Manual For the internal installation part, please refer to the relevant web pages.
Development Tools
When you need to use development tools, unfortunately PHP is only suitable for original designers who originally designed other programming languages and those who are already quite proficient in HTML syntax. You may be using other services or file systems. It is necessary to write a complex program of up to 2,000 lines, and only output the string 1 to the front-end browser. On the other hand, the main function of many people using PHP is to add commonly used headers and footers to a static HTML web page. For these diverse use cases, a good PHP development environment may be commonplace for designers. And it feels friendly enough, but lightweight and powerful original tools are hard to find.
People who enter PHP development from static web designers may have to go through some work adjustments. It is impossible to have a development tool that allows you to just use sprites and drag icons and have built-in graphics processing to complete your work. If the above The development method is very important to you. You can use WYSIWYG software to do web page layout and later add PHP functions through a document editor. Of course, the disadvantage of this method is that the program code generated by the machine for you is not easy to read. , and some are very lengthy.
Pay special attention when you want to use Microsoft FrontPage as your PHP editor, because there seem to be many users who have problems. At least you need to enable ASP format tags (using the options in the php.ini file, or a pair of tags that are more painful to use with JavaScript.
Experienced programmers may need less external learning and can use PHP as As with any other server-side programming language for generating HTML for browsers and other purposes, most of these programmers prefer simple text editors. Usually such software will provide you with some useful tools, such as syntax color highlighting, Brackets are matched in pairs, or tags are automatically closed. Most of these functions are just to help you make unintentional mistakes, but they will not really help you write programs
.Now the most exciting tool for working with PHP has emerged. It's called Zend Studio, which at the time of writing is in its second edition. This product combines a powerful debugging tool (although still not a WYSIWYG tool) with an editing environment. , this smart product can help you significantly save time checking for correct PHP function syntax duplication, allowing you to quickly eliminate errors. Since development time is money, the small cost of this product will make you more productive. You can really find that the symbols of this IDE know the syntax of PHP. Zend Studio is the first development tool that is not just redesigned to achieve some purposes. Figure 3-1 is an illustration of the Zend Studio user interface.
As you can see in Figure 3-1:
Zend Studio allows you to execute PHP programs and preview the HTML output in the window. You don’t need to use a browser to view the original view. Code, and this method is not a standard result or a luxurious display, but the debugging tool can provide tools to provide you with powerful assistance. You can check the program code line by line or jump into or out of function inspection, and set break points. , stack trace processing, trace all global and private variables of the file or check the contents of a specific number. In this easy-to-use GUI interface, you will be reminded of the potential dangers of using undeclared variables, syntax color highlighting and procedures The indented layout can be easily and freely adjusted, new users can avoid the inconvenience of using emacs or vi, and the automatic completion of the program can save you from repeatedly consulting PHP online instructions (such as whether it is strreplace or str_replace, and the parameter order content Why wait), you can also use the program auto-complete function when using your HTML, especially when you must memorize the allowed attributes of each tag. You can even register your own defined functions or auto-complete lists. , making it easier to use without having to refer to the function definition repeatedly, which is very convenient if you are used to passing a series of parameters to functions. As you work with larger, more complex, and function-intensive libraries, you'll find that this IDE can help you more.
Remember that your development server does not have to use the same operating system as the server you serve, this is the greatest value of cross-platform development, especially if you use a Unix server (even for The Blues Brothers), we all have two Various document editors: emacs and vi, and even Macintosh and Windows have more user-friendly document tools. Unix, on the other hand, makes it easy for you to support client operating systems on multiple machines. Many developers have designed certain features of these tools to their best advantage. Emacs, vi and Zend Studio are all editors that can run on many major platforms, so if your development team uses the above standard tools, people can Use these tools with many operating system preferences.
Table 3-2 shows some of the editors from major operating systems used by most programmers.
If you are developing between multiple operating systems, remember that line breaks and some characters are incompatible between Windows and Unix. Line breaks in Unix format will display a black color symbol on Notepad, while Windows The line break format looks like the ∧M character in Unix editors. Your PHP program may still function normally, but you may go crazy when using files edited on different platforms. There are many reasons for this, and there are good ideas to solve it. The best solution to this type of line breaking problem is to use a version control system such as CVS.
In addition to these well-known choices, Keith Edmunds maintains a detailed list of text editors suitable for PHP, many of which are free or require only a small fee.
http://phpeditors.dancinghippo.com/
Take a deep breath. After all the installation and settings, you should now be able to write your first PHP program.
Table 3-2 Common PHP editors on different platforms
Summary
Before we can use PHP, we need to decide whether to build the host ourselves, outsource it, or adopt a compromise solution , such as hosting. Among the most important factors in this decision-making process are the cost of the site, its size and traffic, special hardware or software requirements, the type of content and expectations for control. External web hosting services are the best choice for small websites with no special needs.
If you decide to build or maintain your own development server, detailed installation guidelines and instructions for most common platforms are provided earlier in this chapter. Although PHP4 supports many different types of web servers, at the time of writing this book there is no official documentation describing the details of their installation.
Finally, readers may wonder which development tools are best for PHP. Before there was an integrated development environment (IDE) specifically for PHP, most PHP developers used their favorite text editor to write programs. It is possible to add PHP functionality to a so-called WYSIWYG editor, but it will look messy.
The above is the content of Chapter 3 of the PHP Learning Guide. For more related content, please pay attention to the PHP Chinese website (m.sbmmt.com)!