8 Tips for PHP scripts (1) Install PHP as Apache DSO

Source: Internet
Author: User
Tags final install php mysql php and php database phpinfo unpack mysql database
apache| Tricks | Scripting PHP is often used with Apache Web servers for Linux/unix platforms. When we install PHP in the Apache environment, you have three installation modes to choose from: Static module, dynamic module (DSO) and CGI.





I suggest you to install PHP as a apached DSO, this installation mode of maintenance and upgrade are quite simple. For example, suppose you originally installed only the PHP database support function. But after a few days you decided to add encryption to PHP. Simply type the make clean command, then add new configuration options, and then execute make and make install commands. In this way, the new PHP module will be installed to the appropriate location on Apache, you just restart Apache all OK, of course, the whole process without recompiling Apache.




The simple steps to install a new version of Apache and to install PHP as Apache DSO are as follows:






1. Download the latest version of the Apache server software from the Apache Software Foundation site.


2. Place the code file in the appropriate directory such as/usr/local/or/opt/.


3. Unzip the code file with the Gunzip command, and then you can get the corresponding *.tar file.


4. Type the following unpack command to place the above tar file in a apache_[version-shaped directory:





TAR-XVF Apache_[version].tar





5. Go to the/usr/local/apache_[version] directory (or the directory you specified in the steps above).


6. Type the following configuration command, using the path you have set (such as/usr/local/apache[version], and so on, pay attention to the trailing slash! Replaces the [path] parameter, and you also enable the MOD_SO parameter to allow Apache to use DSO.





./configure--prefix=[path]--enable-module=so





7. Go back to the command prompt and type make and wait for the command to complete and return to the command prompt state.


8. Type make install.





by this time, the compiler can create the final directory and return to the system's command prompt state.





Next install PHP:





1. Visit the download area of the PHP home page to select the latest version of the source code link.


2. Put the downloaded file in the appropriate directory such as/usr/local/or/opt/.


3. Unzip the code file with the Gunzip command, and then you can get the corresponding *.tar file.


4. Type the following unpack command to place the above tar file in a php-[version-shaped directory:





TAR-XVF Php-[version]





5. Into the/usr/local/php-[version] directory (or the directory you specify).





can now compile the PHP DSO, in fact, only need a necessary configuration options--with-apxs (a file under the Apache Bin directory)--however, for the more comprehensive system configuration, we also add to the MySQL database support.





./configure--with-mysql=/[path to MySQL]--with-apxs=/[path to APXS]





6. Go back to the command prompt and type the make command and wait until the command execution is complete and return to the command prompt state.


7. Type the make install command.





At this time, the compiler will create the final DSO, and put it in the Apache module directory, but also for you to modify the Apache httpd.conf configuration file, and then the system back to the command prompt state waiting for you to enter the new instructions. You can then open the Apache httpd.conf configuration file to make some corrections:





1. Find a line with serveradmin and add your own e-mail address, as follows:





ServerAdmin you@yourdomain.com





2. Find a line that starts with servername, and change the following parameters to actual values, such as:





ServerName localhost





3. Find the following paragraph:





# and for PHP 4.x, use:


#


#AddType application/x-httpd-php. PHP


#AddType application/x-httpd-php-source. Phps





modify these configuration lines to remove some of the comments that were added to AddType under PHP 4.0, and you should add some file extensions for PHP, which might look like the following:





# and for PHP 4.x, use:


#


addtype application/x-httpd-php. php. phtml


AddType application/x-httpd-php-source. Phps





Save the above configuration file, return to the superior directory, type the following command to start Apache:





./bin/apachectl Start





If there are no problems during startup, you can test the installation of Apache and PHP by creating a file called Phpinfo.php that contains the following lines of code:





;? Phpinfo ()?>





Save the file and place it under the Apache document Root (Htdocs), and then start your Web browser and type http://localhost/in the browser's address bar. phpinfo.php, the browser will display a large number of PHP and Apache system variables and variable values.





if you want to reset PHP, all you need to do is execute the make clean command, then execute the./configure command with the new configuration option, and then execute make and make install. In this way, a new module appears in the Apache module directory, and you just reboot Apache to load the new module. Many of the headaches of the past have been solved now.





Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.