I have already talked about the compatibility of PHP and its multi-platform support in the previous chapter. However, the most widely used, and inarguably the best, software combination for PHP is using Apache and MySQL on a Linux platform. In this section, I will discuss the steps that are required to configure PHP to work with Apache and MySQL in Linux.
آموزش برنامه نویسی طراحی سایت اختصاصی PHP با خرید بسته آموزش طراحی اختصاصی سایت از امکان پذیر هست. بعد از خرید بسته آموزشی همکاران ما در سایت ، درگاه پرداخت با شما تماس حاصل خواهند کرد و نسبت به کنترل آدرس پستی شما اقدام خواهند کرد تا بسته آموزش برنامه نویسی و طراحی سایت بعد از ارسال با پست پیشتاز به خدمت حضورتان برسد.
با خرید بسته آموزشی طراحی سایت میتوانید انواع سایتهای شخصی، سایت شرکتی، سایت تجاری، سایت فروشگاهی، طراحی تک صفحه ای، طراحی سایت ریسپانسیو، ویرایش و توسعه طراحی سایت انجام شده، رفع اشکالات نرم افزاری و برنامه نویسی php، کار کردن با وب سرور آپاچی و امن کردن url و مباحث بهینه سازی سایت SEO آشنا خواهید شد.
When you install Red Hat Linux, you are provided with various choices for the type of installation that you want. The Custom (everything) installation of Linux is a convenient method to install Linux, as it also installs Apache, MySQL, and PHP by default. You can straightaway get down to the business of PHP programming after using the Custom (everything) installation. However, there are a couple of things that you need to keep in mind: first, the amount of disk space required by a Custom (everything) installation is 2.4 GB; second, your computer should be running the httpd service. If the httpd service is not running, you need to enable the service by giving the ntsys command. After enabling the service, you need to start the service with the following command:
If you have not performed the Custom (everything) installation on Linux, you need to install PHP separately. You can install PHP in either of two ways:
Using Red Hat Package Manager (RPM)
Compiling PHP from source
In the following section, I will tell you about each of these installation options in detail.
Installing PHP by Using Red Hat Package Manager (RPM)
Installing PHP by using RPM is the easiest and simplest method. This method is generally recommended for users who do not have much experience in complicated installations that involve compiling.
To start installation, you need to first download the .rpm files for the latest packages from the Web site, www.rpmfind.com. Alternatively, you can find these .rpm files in the Red Hat Linux CD.
After obtaining the rpm file, all you need to do to install PHP is type the following command:
$rpm -ivh php-4.0.6-7.i386.rpm
This command installs PHP on its own. Nice!
However, installing PHP by using RPM has some disadvantages. These include the following:
RPM has precompiled binaries; it does not allow you to specify any compile options while installing PHP.
After the RPM installation of PHP, you cannot have any kind of post-installation configurations.
In the next section, I will discuss the compilation of PHP from source.
Compiling PHP from Source
As mentioned earlier, you can also configure PHP by compiling it from source as an Apache module. To do so, you need to perform the following steps:
For configuring PHP by compiling it from source as an Apache module, you require two distributions, namely:
The apache distribution, apache _1.3.x.tar.gz. You can download this distribution from www.apache.org. You use this distribution to update Apache in case it is installed using source.
The PHP distribution, php-4.x.y.tar.gz. You can download this distribution from www.php.net. You use this distribution to install PHP.
After you have downloaded these two files, you need to copy the files into a directory and then navigate to that directory. Preferably, copy these files to the directory where you had earlier copied (or downloaded) files related to installation of PHP. You might save yourself some effort if you need to search for these files later.
Uncompress these distributions by using the following commands:
$tar xvfz apache_1.3.x.tar.gz $tar xvfz php_4.x.y.tar.gz
Uncompressing these two files creates two directories, apache_1.3.x.y and php_4.x.y.
By using the command chdir apache_1.3.x.y, change to the newly created apache directory, which is apache_1.3.x.y.
(If Apache is not installed using the source distribution, you can skip this step.) Run the ./configure script and mention all the options that are used to install Apache.
$ ./configure -configuration-options-for-apache
Change to the PHP directory by using the command chdir ../php_4.x.y.
Configure PHP to be used with Apache (and the basic module MySQL) by using the following command:
$ ./configure -with-apache=../apache_1.3.x -with mySQL.
The -with-apache option tells PHP about the location of the Apache distributions. This option informs PHP that it will be a module for Apache.
If Apache is installed by using RPM, you need to execute the following command:
# ./configure -with-mysql -with-apxs
Type the following command to compile PHP distribution files:
Install the PHP compiled files by typing the following command:
$ make install.
The above command also creates a library called src/modules/ php4/libphp4.a, which is used to configure the Apache distribution module.
To execute the preceding commands, you require root user privileges.
If you have installed Apache by using RPM, you can skip steps 10, 11, and 12.
After compiling PHP distribution files, you need to compile the Apache distribution files. Change to the Apache directory again by using the following command:
Now type the following command to obtain the necessary files from the library source module. These files are used for compiling the Apache distribution:
$ ./configure -activate-module=src/modules/php4/ libphp4.a -other-apache-options
To compile the Apache distribution, type the following command:
After compiling the Apache distribution, you need to install Apache (with the PHP module). Do so by typing the following command:
$ make install
Start the new Apache server:
$ /usr/local/apache/bin/apacheect1 start
Verify that the location of the files, namely:
LoadModule php4_module libexec/libphp4.so
AddType application/x-httpd-php .php
is set to etc/httpd/config/httpd.conf.
You may already have the Apache server running on your computer. (This may be as a result of Linux installation). In this case, you need to stop the Apache server first. You can do so by giving the following command:
$ /usr/local/apache/bin/apacheect1 stop
If your computer does not support the above command, you can kill Apache by using the following command:
$ killall -9 apache
Copy the file php.ini-dist to the directory /usr/local/lib by executing the following command:
$ cp php.ini-dist /usr/local/lib/php/php.ini
After copying the php.ini-dist file to the desired location, you need to restart the httpd service. You can do so by specifying the following command:
To verify that PHP was configured properly, you may need to perform the following two steps:
In the /var/www/html directory of the root user, create a file called test.php.
In test.php, type the following code:
<? phpinfo(); ?>
Open Netscape Navigator or any other Web browser of your choice and specify the following address:
This completes the entire process of installation and configuration of PHP on Linux.