PHP is usually installed on Linux/Unix operating systems and used with the Apache server. When installing PHP with the Apache server, you have three different installation methods to choose from: static modules, dynamic shared objects (Dynamic Shared Object, DSO), and CGI program executable files.
Here I recommend that you use the dynamic shared object mode to install PHP, because this installation method provides great convenience for future maintenance and upgrades. Suppose that when you first installed PHP, you only added PHP's database-related modules. A few days later, you decide to install PHP coding function-related modules. At this time, you only need to enter the make clean command in your system command line, then enter the new PHP setting options, and then enter the make and make install commands, and then After that, the system will generate a new PHP dynamic shared object and install it in the appropriate directory location specified by the Apache server. The next thing you have to do is just reactivate the Apache server. You don't need to recompile the entire Apache server.
The following basic steps can allow you to install a new Apache server, including PHP dynamic loading module:
1. Go to http://www.apache.org/dist /Download the latest version of the Apache server source code.
2. Copy the obtained file to a meaningful directory location, such as /usr/local/ or /opt/, or other directory location you feel is appropriate.
3. Unzip the obtained file. After unzipping, you will get some *.tar files.
4. Enter the following command to unpack these *.tar files, and place the unpacked files in a directory called apache_[version]:
tar -xvf apache_ [version].tar
5. Enter the cd command to switch the working directory to /usr/local/apache_[version] (if you unzipped the *.tar file to a different directory in the previous step, then Switch to the directory you specified)
6. Enter the following command to prepare the compiler. Remember to replace the [path] part in the following command with your own directory name, such as /usr/local/ apache[version] (don’t add the last slash!). What this step does is activate mod_so so that the Apache server can use dynamic shared objects.
./configure --prefix=[path] --enable-module=so
7. Wait until the system returns to the command prompt, enter make, and then continue to wait for the system to return to the command prompt. symbol.
8. Enter the make install command.
At this time, the compilation program will generate the directories and files needed for the final use. After completion, you will return to the command prompt again.
Now you can start installing PHP:
1. Go to the PHP official website: http://www.php.net/downloads.php to download the latest version of the PHP original program code.
2. Place the obtained file in a meaningful directory location, such as /usr/local/ or /opt/, or other directory location you feel is appropriate.
3. Unzip the obtained file. After unzipping, you will get some *.tar files.
4. Enter the following command to unpack these *.tar files, and place the unpacked files in a directory called php-[version]:
tar -xvf php-[version]
5. Enter the cd command to switch the working directory to /usr/local/php-[version] (if you unzipped the *.tar file to a different directory in the previous step, then Just switch to the directory you specified). Now you can start compiling PHP dynamic shared objects. There is only one setting option that is really necessary: --with-apxs (this is a file in the bin directory under the Apache server installation location). But here I suggest adding PHP’s MySQL related modules as well.
./configure --with-mysql=/[path to mysql] --with-apxs=/[path to apxs]
6. Wait until the system returns to the command prompt and enter make command, and then continue to wait for the system to return to the command prompt and then enter the make install command.
Then the compiler will generate the PHP dynamic shared object we will use in the end, place it in the directory where Apache uses to place dynamic shared objects, and modify the Apache server configuration file httpd.conf for you. Some parts of the system will eventually return to the command prompt again.After you return to the command prompt, you must go back and modify the httpd.conf file. Some settings in it must be modified:
1. Find the ServerAdmin line and add your email address, that is Modify that line to: ServerAdmin you@yourdomain.com
2. Find the ServerName line and set the server name, for example: ServerName localhost
3. Find the following A setting:
# And for PHP 4.x, use:
#
#AddType application/x-httpd-php .php
#AddType application/x-httpd-php -source .phps
You must modify the settings here, remove the # symbol in front of the two lines of AddType (the # symbol here represents comments), and add other things you want to use with PHP programs Extension, after modification, this setting should look like (please note that .php and .phtml inside are the extensions you can use to identify PHP programs in the future):
# And for PHP 4 .x, use:
#
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
Save httpd.conf , enter the cd command to return to the previous directory, and then enter the following command to activate the Apache server:
./bin/apachectl start
If no error message appears during the activation process, next We can start testing to see if the newly installed Apache server and PHP module are really correct. Please create a file named phpinfo.php. Just enter the following line of PHP program code in it:
<? phpinfo() ?>
Save the file and then save it Place it in the file root directory of the Apache server (the directory name is htdocs). Start your browser and enter http://localhost/phpinfo.php in the address bar. If everything is installed correctly, you should see a long web page that displays the complete PHP system setting information, which means We have successfully installed the Apache server and PHP!
After the initial installation is completed, when you want to reset PHP in the future (for example, add a PHP module that was not originally installed), you only need to enter the make clean command at the system command prompt, and then Enter the new ./configure setting command, then enter the make and make install commands, and the system will generate a new PHP dynamic shared object. Next, you only need to reactivate the Apache server and let it reload the new module you just created. Just a few simple steps to solve a bunch of annoying problems!