Two Methods for installing and configuring the php environment in Linux

Source: Internet
Author: User

There are many ways to install the php environment in linux. Common apt-get and make methods are used to install and configure the php environment. Let's take a look at these two instances.

1. Get the Installation File: http://www.php.net/downloads.php php-5.3.8.tar.gz

Get the support files required to install php: http://download.csdn.net/download/netlong339/1351852 libxml2-2.6.32.tar.gz

2. Install libxml2

The Code is as follows: Copy code

1 tar zxvf libxml2-2.6.32.tar.gz
2 cd libxml2-2.6.32
3./configure -- prefix =/usr/local/libxml2
4 make
5 make install

After the installation is successful, five directories, bin, include, lib, man, and share, will be generated under the/usr/local/libxml2/directory. When you install the PHP5 source code package later, the "-- with-libxml-dir =/usr/local/libxml2" option will be added to the configure command, it is used to specify the location where libxml2 library files are installed.

3. Install php5 (libxml2 should be installed before php5 is installed)

 

The Code is as follows: Copy code
# Tar zvxf php-5.3.8.tar.gz
# Cd php-5.3.8
#./Configure
-- Prefix =/usr/local/php
-- With-mysql =/usr/local/mysql
-- With-apxs =/usr/local/apache2/bin/apxs
-- With-libxml-dir =/usr/local/libxml2
# We recommend that you execute make and make install separately.
# Make install


4. reconfigure apache2 to support php

■ Configure httpd. conf allows apache to support PHP: (Note: The default php installation path is in/etc/php5/php. ini (add addtype here), the following httpd. conf is a blank file. ,)

The Code is as follows: Copy code

# Vi/usr/local/apache/conf/httpd. conf

Find AddType application/x-gzip. gz. tgz and add the following content under it:

AddType application/x-httpd-php. php (there is a space before)

AddType application/x-httpd-php-source. phps (there is a space before)

■ Then the configuration file of CPOPY PHP

The Code is as follows: Copy code
Cp php-5.3.8/php. ini. dist/usr/local/php/lib/php. ini

(If php. ini. dist is not available, rename any of php. ini-development php. ini-production to php. ini. dist .)

Modify the php. ini file register_globals = On

■ Restart apache

The Code is as follows: Copy code
Service apache restart

5. Test whether php is successfully installed.

Write a php test page info. php and put it in apache2/htdocs.

The Code is as follows: Copy code

<? Php

Phpinfo ();

?>;

Enter the server address/info. php In the browser

If the php information is displayed normally, it indicates that Apche + Mysql + PHP is successfully installed!


Another method:

1. install Apache

Next, we will first introduce how to install Apache. The installation command is as follows:

The Code is as follows: Copy code

$ Sudo apt-get install apache2

Run Apache and the command is as follows:

The Code is as follows: Copy code

$ Sudo/etc/init. d/apache2 restart

During installation, Apache creates a directory:/var/www, which is the root directory for storing documents on the server. You only need to enter http: // localhost/or the IP address of the machine in the address bar of the browser to access all documents placed in this directory.

Ii. install PHP

PHP is a popular server-side scripting language. It is generally used in combination with MySQL or Postgres to manage Web content, blogs, and forums. The following describes the installation method. In fact, the installation is very simple. The command is as follows:

The Code is as follows: Copy code

$ Sudo apt-get install libapache2-mod-php5

Restart Apache to load the modules installed above:

The Code is as follows: Copy code

$ Sudo/etc/init. d/apache2 restart

To verify that the PHP module is correctly loaded, we can create a PHP file and try to access the file through the Web server. In addition, we know that PHP has a built-in phpinfo function that provides detailed information about its environment. Therefore, we can also use the following command to check the working status of PHP:

The Code is as follows: Copy code

Sudo sh-c "echo''>/var/www/info. php"

Then, enter http: // localhost/info. php in the address bar of the browser, and press Enter. Then, you will be able to see a face and provide the PHP installation details. Note that if the browser prompts you to download the file instead of displaying the page during this process, Apache does not properly load the PHP module. To solve the problem, add the following command in the/etc/apache2/apache2.conf or/etc/apache2/mod-enabled/php5.conf file:

The Code is as follows: Copy code

AddType application/x-httpd-php. php. phtml. php3

After adding the preceding command line, to ensure that Apache re-reads the configuration file and closes it, we can use the following command to close it and then start it:

The Code is as follows: Copy code

$ Sudo/etc/init. d/apache2 stop

$ Sudo/etc/init. d/apache2 start

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.