At the time of this writing, the very first release candidate of PHP5 was available, and that's the one we're using. But you may want to check the PHP site for more recent versions, and any notes about changes.
The combination of Linux, Apache, MySQL, and PHP is probably the most common production environment for running PHP Web servers. This combination of open-source software has been referred to by the acronym LAMP. If you run the same combination of software, you can benefit from the experiences of the many other people who've used this setup.
The PHP developers work very closely with the Apache and MySQL teams to ensure that advances in the three server systems are fully supported by the other components. However, at the time of this writing PHP5 is being distributed with SQLite rather than MySQL, because there is some concern about whether MySQL is still open source. This may not be a concern when you read this and begin developing, but it's worth noting.
As with other open-source software, you have the option of downloading the PHP and Apache source code (which, in both cases, is written in the C programming language) and compiling the programs yourself. If that sounds daunting (it's not actually as scary as it sounds), you can obtain precompiled versions in one of two forms: binary downloads, which are precompiled versions of the software that typically come with installation scripts to put all the required pieces into the necessary parts of your file system, and binary packages, which are available for systems that have a software package management system, such as the Red Hat Package Manager (RPM) for Linux, and are the easiest to install.
Here's a quick overview of the three methods:
The version of Red Hat we're using is actually called Fedora, because Red Hat has split off development into two parts: Fedora and the enterprise version of Red Hat Linux. Currently, the Fedora site doesn't have an RPM for PHP5, so we'll provide the instructions for getting and installing the RPM for PHP4 here, and then show how to download and compile PHP5 for Fedora later. By the time you read this, in all likelihood there will be an RPM available for PHP5 for your Linux distribution, so the RPM installation presented here should provide good guidance for installing PHP5 via the RPM method.
A number of popular Linux distributions use the Red Hat Package Manager, including Red Hat, SuSE, Mandrake, Definite, TurboLinux, Caldera, and Yellow Dog. If your system uses an alternative package management system, such as Debian's deb packages, refer to your distribution's manual for installation instructions.
The best place to get RPMs is almost always the disks from which you installed your Linux system. Red Hat 7 and SuSE 7 both include PHP4 (although it isn't installed by default)â€”by the time you read this, the same should be true of most current Linux distribution versions.
If your distribution doesn't include PHP4, or it doesn't include all the required functionality or support RPMs, then the next place to check is your Linux distribution vendor's Web site, which should have a download area or FTP site from which you can obtain the latest RPMs.
Finally, www.rpmfind.net provides a comprehensive search service for RPMs. When you download RPMs, though, make certain that they are compatible with your Linux distribution and your computer hardware. Different distributions put important files in different places, and this can lead to RPMs from different vendors not working on other systems. Most RPMs are available compiled to run on the different hardware systems that Linux supports. The following table shows the most common abbreviations used in RPM names (you need the abbreviation to search on the rpmfind site):
Refer to your distribution's manual if you want to use the graphical installation tools that come with your specific distribution. These differ widely, so they can't all be covered here. However, any RPM-based system can be controlled using the rpm command-line tool, and you'll see how to install the required components using this interface.
The RPM packages you will need are:
You can find out which of them are already installed on your system by typing the following at a command prompt, substituting in the name of each of these packages in turn:
> rpm -q zlib zlib-1.1.3-6-i386 > rpm -q libng Package libpng is not installed
As you can see, if the package is installed, it gives you a random-looking string. If it isn't installed, you get a helpful error message. The string actually tells you which version of the software you installed using the package (1.1.3 in this case), which release of the package it is (this example has the sixth public release installed), and the architecture for which the RPM was compiled (Intel 386 compatible, which is just as well, because the package is installed on a Pentium III for this book).
Note which of the packages you already have, and which versions they are (the version number is more important than the release number).
Apache is at version 1.3.29 if you want to remain at the old versions of GD, or 2.0.48 if you want to be current with the latest version of GD. Of course, if you are installing PHP5, GD is now bundled with PHP and is up to version 2.0.17
Then locate suitably up-to-date versions of all the packages that you don't have already, or have old versions for. As suggested, try your install CDs, your distributor's Web site, and www.rpmfind.net.
Once you have current versions of all the packages you need, you can install them. The command for upgrading an existing installation or installing a package for the first time is exactly the same. Navigate your command prompt to the location of the files on the CD or the directory into which you downloaded the RPMs. As root, type:
> rpm -Uh libpng-1.0.5-3-i386.rpm ##################
For each package you need to upgrade or install, just substitute the name of the package file you downloaded. The line of # signs extends across the screen as each installation progresses.
If you install the packages in the order listed previously, you should find that all the prerequisite files are installed in the necessary order.
The installation method we'll use for installing PHP5 on Red Hat Fedora running Apache is downloading the source files and compiling them. You use command-line commands in Linux, but also make use of some of the visual tools (such as Konqueror) included in your Red Hat installation. If you are running Linux visually (for example, with KDE), you get to the command prompt by going to the Red Hat button, and then choosing System Tools â‡¨ Terminal.
You must have a compiler installed (an ANSI C compiler). Sometimes such a compiler is installed as part of your Linux installation, but if you need one, a good one (and free), named gnugcc, can be found at www.gnu.org.
With your compiler installed, download the source file from www.php.net. This file is archived as a tar file and compressed with gzip, so you will need to uncompress it. There is also a .bz2 file you can download, but you need only one of these filesâ€”either the gzip or a .bz2 file.
You also could use Konquerer to copy all of the compressed file's contents directly to another folder, but doing so will make your compilation fail cryptically (meaning you'll get strange error messages that won't help you figure out what's wrong). Instead, make sure to use the following command from the terminal (see Figure 1-5) to uncompress the files:
tar -xvzf php-5.0(insert the rest of the version number here).tar.gz
Now that you've cd'd to the php-5.0.0RC1 folder, you'll see quite a few folders and files there. Open the INSTALL text file to find many of the instructions related to your installation.
Folder and directory are equivalent terms and can be used interchangeably.
For this book, PHP is installed as a Dynamic Shared Object (DSO), and that's what you'll also do, so that the entire Apache Server won't need to be recompiled.
The latest versions of Apache support DSOs, and shared objects can be used by other programs, such as PostGreSQL. Although you could compile PHP5 as a static module, that isn't recommended. If PHP is statically linked to, say, Apache or PostGreSQL, each of those programs would need to be recompiled before they would recognize PHP. The programs' configuration files can be easily changed in shared objects (DSOs) without any recompiling.
You must have Apache installed and set up for dynamic modules before compiling PHP5 as a DSO. Use the following command from the terminal to make sure Apache is ready:
As long as mod_so.c is present, you're OK to proceed.
Within your PHP5 directory (probably named something like php-5.0.0RC1.), you'll find a shell script named configure. This script accepts arguments to control the features that PHP will support. You'll need to run this script to configure compilation, not PHP5 itself (PHP configuration with php.ini will come later).
The default configure is to compile PHP5 as a CGI binary. Use the -with-apache option to compile PHP5 as a static module; use the -with-apxs option to compile PHP5 as a DSO. For this installation, use the -with_apxs option (actually -with_apxs2 because you're running Apache 2).
Here are some of the command line arguments that you may use when you compile PHP5. The configure command is ./configure (the ./ lets it run) followed by a single space and then as many of the following options as you like:
For your quick install use only -with-mysql and -with-apxs2. If you get any error messages telling you something couldn't be found, provide the full path to the folder in which the appropriate files can be found. For example, our configure command found the path to mysql. If it hadn't we would have provided the full path to mysql as part of the command to run the configure script.
There are many more command line arguments that you can use as well. For example, type in the command
and you'll see the complete range of arguments that you can use, along with their descriptions.
The quick installation in the PHP INSTALL text file recommends starting with just two commands: -with-mysql and -with-apxs. Run the configure script like this for quick installation:
./configure --with-mysql --with-apxs2
You need to use -with-apxs2 rather than -with-apxs because you're running a later version of Apache. The script actually came back and informed me of this when it ran, which was very helpful. If you read through the commands that appear in your terminal as the script runs, you'll see that it does quite a few such checks as it gets ready for the make command.
After the configure script has run, you need to enter two more commands:
make make install
Install makes a directory in /user/local/lib named php where it places a copy of PEAR (php Extension Add-on Repository) and the php.ini file.
You may use some of the other options of the configure script to compile PHP5 with enable_track_vars, with-gd, and with_pgsql. But if you'd like to use the configure options for gd (the graphics module) and pgsql (the database) you must make sure these programs are also loaded for everything to work properly, and you must provide the full path to the installations as required.
PHP5 is compiled as a module if you used the configure script with the -with-apache or --with-apxs2 options. It's compiled as a CGI executable binary file if you used the configure script without any reference to Apache or apxs. And if you compiled PHP5 as a CGI, then when you installed PHP5, it most likely put the actual binary in /usr/local/bin. Copy the CGI executable binary to your cgi-bin directory using:
cp /usr/local/bin/php /usr/local/apache/cgi-bin/php.cgi
This enables Apache users to run different PHP-enabled pages under different user-ids. However, CERT advisory CA-96.11 recommends against placing any interpreters (such as PHP5) into cgi-bin because attacks such as accessing system files and Web documents can be launched against your server. When you compile PHP5 with the -with-apache option, you will have a Server Application Programming Interface (SAPI), which provides a higher level of performance and security over the CGI method.
To install Apache, use RPMs or download and compile the source code. But Apache probably comes with your Linux distribution, and may already be properly installed. On my Red Hat Fedora installation, Apache was already installed, and all that was needed to verify this was go to the Red Hat button, choose System Settings â‡¨ Server Settings â‡¨ Services, and look for httpd.
Httpd (all lowercase) means HTTP daemon, and daemon is the name of services running in the background on Linux machines. So httpd means the HTTP daemon running in the background, for example, the Web server.
If Apache is not already installed and running, you can use these commands for installing it from the Terminal:
lynx http://httpd.apache.org/download.cgi gzip -d httpd-2_0_NN.tar.gz tar xvf httpd-2_0_NN.tar ./configure --prefix=PREFIX make make install vi PREFIX/conf/httpd.conf PREFIX/bin/apachect1 start
You must replace the NN with the minor version number, and PREFIX with the correct path in which you'd like to install Apache (the default is /usr/local/apache2).
If PHP5 is installed as a DSO (as the example installation was), you need to check the Apache configuration file (named httpd.conf) to make sure it has several entries. In the Fedora installation, you can find the httpd.conf file in the /etc/httpd/conf folder. Open any text editor and let's modify the httpd.conf file.
First, ensure that PHP is enabled on your Apache server. Look for a lot of lines that begin with the word LoadModule. Among them you should find a line like this:
If there isn't such a line, you need to add one; or if the path is wrong, you need to correct it. Find out where the PHP compile put your libphp5.so file. Open Konqueror and choose Tools â‡¨ Find file. My installation put the libphp5.so file in
You need this information to tell Apache how to run PHP scripts. In the Apache configuration file httpd.conf, add the LoadModule instruction to load PHP5. Put it after any of the other LoadModule lines, using the path you just obtained:
LoadModule php5_module /usr/lib/httpd/modules/libphp5.so
Now that Apache knows how to load PHP5, you need to activate PHP5 in Apache. There's a section farther down the file consisting of a lot of lines beginning with AddModule. If you find a ClearModulesList line in the file, you need to add the following line to the file. Although it doesn't matter where you put it, it makes sense to locate it near other AddModule lines for easy access in the future:
The AddModule line is not required unless you have a ClearModulesList line.
Finally, you tell Apache how to recognize a PHP program file by its extension. Further down the document are some directives that begin AddType. To the end of these, add the following line:
AddType application/x-httpd-php .php
This tells Apache that all files that end in .php are PHP programs. Now you're done, so save the file.
Check to see if Apache is running by going into Services once again and checking the httpd service. If it's not running, start it. Verify that it's running by opening the http://localhost test page. If everything seems to be working OK (and you're not also installing on Windows), move on to the "Testing Your Installation" section to test that PHP is working properly.
The majority of Web hosting computers runs some version of Linux, such as Debian, RedHat, FreeBSD, and so on. The Web server of choice for these machines is Apache. PHP is compatible with Linux and Apache, so you can install and configure PHP on these systems. However, if you are not in charge of the Web hosting computer (and many times you won't be) you'll probably have little control over the installation and configuration. If you find yourself in this position (for example, if you've been hired to work on an existing Web site running on someone else's server) you can simply verify the operating system, Web server software, and PHP version so you can cope with whatever you've got as you develop your PHP programs.
â€¢ MySQL is a database management system
A database is a structured collection of data. It may be anything from a simple shopping list to a picture gallery or the vast amounts of information in a corporate network. To add, access, and process data stored in a computer database, you need a database management system such as MySQL Server. Since computers are very good at handling large amounts of data, database management systems play a central role in computing, as standalone utilities, or as parts of other applications.
â€¢ MySQL databases are relational
A relational database stores data in separate tables rather than putting all the data in one big storeroom. The database structures are organized into physical files optimized for speed. The logical model, with objects such as databases, tables, views, rows, and columns, offers a flexible programming environment. You set up rules governing the relationships between different data fields, such as one-toone, one-to-many, unique, required or optional, and â€œpointersâ€ between different tables. The database enforces these rules, so that with a well-designed database, your application never sees inconsistent, duplicate, orphan, out-of-date, or missing data.
The SQL part of â€œMySQLâ€ stands for â€œStructured Query Languageâ€. SQL is the most common standardized language used to access databases. Depending on your programming environment, you might enter SQL directly (for example, to generate reports), embed SQL statements into code written in another language, or use a language-specific API that hides the SQL syntax.
SQL is defined by the ANSI/ISO SQL Standard. The SQL standard has been evolving since 1986 and several versions exist. In this manual, â€œSQL-92â€ refers to the standard released in 1992, â€œSQL:1999â€ refers to the standard released in 1999, and â€œSQL:2003â€ refers to the current version of the standard. We use the phrase â€œthe SQL standardâ€ to
mean the current version of the SQL Standard at any time.
â€¢ MySQL software is Open Source
Open Source means that it is possible for anyone to use and modify the software. Anybody can download the MySQL software from the Internet and use it without paying anything. If you wish, you may study the source code and change it to suit your needs. The MySQL software uses the GPL (GNU General Public License), http://www.fsf.org/licenses/, to define what you may and may not do with the software in different situations. If you feel uncomfortable with the GPL or need to embed MySQL code into a commercial application, you can buy a commercially licensed version from us. See the MySQL Licensing Overview for more information (http://www.mysql.com/company/legal/licensing/).
â€¢ The MySQL Database Server is very fast, reliable, scalable, and easy to use
If that is what you are looking for, you should give it a try. MySQL Server can run comfortably on a desktop or laptop, alongside your other applications, web servers, and so on, requiring little or no attention. If you dedicate an entire machine to MySQL, you can adjust the settings to take advantage of all the memory, CPU power, and I/O capacity available. MySQL can also scale up to clusters of machines, networked together.
You can find a performance comparison of MySQL Server with other database managers on our benchmark page. See The MySQL Benchmark Suite.
MySQL Server was originally developed to handle large databases much faster than existing solutions and has been successfully used in highly demanding production environments for several years. Although under constant development, MySQL Server today offers a rich and useful set of functions. Its connectivity, speed, and security make MySQL Server highly suited for accessing databases on the Internet.
â€¢ MySQL Server works in client/server or embedded systems
The MySQL Database Software is a client/server system that consists of a multi-threaded SQL server that supports different backends, several different client programs and libraries, administrative tools, and a wide range of application programming interfaces (APIs).
We also provide MySQL Server as an embedded multi-threaded library that you can link into your application to get a smaller, faster, easier-to-manage standalone product.
â€¢ A large amount of contributed MySQL software is available
MySQL Server has a practical set of features developed in close cooperation with our users. It is very likely that your favorite application or language supports the MySQL Database Server.
The official way to pronounce â€œMySQLâ€ is â€œMy Ess Que Ellâ€ (not â€œmy sequelâ€), but we do not mind if you pronounce it as â€œmy sequelâ€ or in some other localized way.
|copyright © dedserveronline.com|