Linux under Configuration Install PHP environment (APACHE2)

Source: Internet
Author: User
Tags zts zend

Http://www.cnblogs.com/lufangtao/archive/2012/12/30/2839679.html

Refer to other people's practices, encounter problems online check, the following is the installation steps.

First, install the Apache2.2.22
1, to the official website download http://httpd.apache.org/download.cgi
2. Decompression
TAR-ZXVF httpd-2.2.22.tar.gz
3. Set up the target folder (note that all of the following actions are performed under the root user)
Mkdir/usr/local/apache2
That is to say, wait for the installation of the apache2 to install in this folder
4. Configuration
Back to the folder created after the original decompression
./configure--prefix=/usr/local/apache2--enable-module=shared
To add a later parameter, you cannot use php,-enable-module=shared to indicate that Apache can dynamically load modules

This step, there are a lot of problems:

The first error is:

checking for APR... noconfigure: error: APR not found.  Please read the documentation.
解决方法:
Download the latest versions of both Apr and Apr-util from Apache APR, unpack them to./srclib/apr and./srclib/ap R-util (be sure the domain names does not has version numbers; for example, the APR distribution must is under./srclib/apr /)

Then do

./configure --with-included-apr
Original article Address: Http://stackoverflow.com/questions/9436860/apache-httpd-setup-and-installatio
Another workaround is:
Install Apr and apr-util respectively, install the method is: First download these two files, then unzip, into the extracted directory, and then the APR and Apr-util respectively installed into the/usr/local/folder Apr and Apr-util folder. The specific installation method for APR is:
[Email protected] 52lamp]# TAR-ZXVF apr-1.4.2.tar.gz//unzip-o apr-1.4.2.zip
[Email protected] 52lamp]# CD apr-1.4.2
[Email protected] apr-1.4.2]#/configure--PREFIX=/USR/LOCAL/APR
[[email protected] apr-1.4.2]# make
[[email protected] apr-1.4.2]# make install
Install Apr-util in./confiure--prefix=/usr/local/apr-util--WITH-APR=/USR/LOCAL/APR
The other steps are similar.

The second error is: No acceptable C compiler found in $Path
Run yum install gcc directly and install GCC
The third problem is: Pcre-config for Libpcre not found
The workaround is to download the Prce installation package, similar to APR, and install it under the/usr/local/pcre folder. The command to install the C + + compiler g++ under Ps:fedora is: Yum install gcc-c++.
5. Compiling
Make
6. Installation
Make install
7, start, restart and stop, first switch to the installation after the completion of the directory/usr/local/apache2/bin
./apachectl-k Start
./apachectl-k Restart
./apachectl-k Stop
8, configuration files (to meet the most basic configuration)
Edit/usr/local/apache2/conf/httpd.conf File
Found it:
AddType application/x-compress. Z
AddType application/x-gzip. gz. tgz
Add in the following:
AddType application/x-httpd-php. PHP (enables Apcche to support PHP)
AddType Application/x-httpd-php-source. php5
Found it:
<ifmodule dir_module>
DirectoryIndex index.html
</IfModule>
Add to:
<ifmodule dir_module>
DirectoryIndex index.html index.php
</IfModule>
Found it:
#servername www.example.com:80
Modified to:
ServerName 127.0.0.1:80 or ServerName localhost:80
Remember to remove the "#" from the front.
9. Testing
Enter http://127.0.0.1 in the browser
If there is an IT works! description is successful. This is my test result: O (∩_∩) o haha ~

10. Modify the Default Web site Directory

The default directory is "/usr/local/apache2/htdocs", modify the Apache configuration file httpd.conf, for example, create a new/home/gyw/website directory as the Apache site Directory

Find DocumentRoot This line is modified to: DocumentRoot "/home/gyw/website"

Find <Directory> this line modified to: <directory "/home/gyw/website" >

Test: Error occurred while modifying to folder:

"You don ' t has permission to access/index.html in this server."

Workaround:

Change file permissions; chmod 755 index.html

Open the Apache configuration file httpd.conf and find this section:
<directory/>
Options FollowSymLinks
AllowOverride None
Order Deny,allow
Deny from all
Satisfy All
</Directory>

The test results are as follows:

Second, install PHP
1. Download
http://www.php.net/downloads.php
2. Decompression
TAR-ZXVF php-5.3.16.tar.gz
3. Set up the target folder
mkdir/usr/local/php
That is, wait for the installed PHP to be installed in this folder
4. Configuration
Back to the original unpacked folder
./configure--prefix=/usr/local/php--with-apxs2=/usr/local/apache/bin/apxs

Note that there is a-with-apxs2=/usr/local/apache/bin/apxs option, where APXS is generated when Apache is installed apxs and is a tool for compiling and installing extensions for Apache HTTP servers, which can be used by The mod_so instructions provided are LoadModule loaded into the Apache server at run time. My understanding is that the PHP module is dynamically loaded into Apache using this tool.

Error occurred: Configure:error:xml2-config not found. Please check your LIBXML2 installation.

Run the Yum install LIBXML2, and then run the Yum install Libxml2-devel after the installation is complete, rerun the above./configure command.

5. Compiling
Make
6. Test compilation
Make Test
7. Installation
Make install

8. Configuration Files

Cp/usr/local/src/php-5.3.16/php.ini-development/usr/local/php/lib/php.ini
Copy the original php.ini-development in the source code to/usr/local/php/lib/php.ini, and rename it to PHP.ini

9. Restart Apache
10. Testing
Create a PHP file test.php under Apache Htdocs, with the following contents:
<?php
Phpinfo ();
?>
Then enter http://127.0.0.1/test.php in the browser.
If there is a related configuration of PHP, successful, if nothing is entered, the description fails, repeat the above steps or find the reason

If you decide to change the configuration options after installation, simply repeat the last three steps of configure, make, and do install, and then you will need to restart Apache for the new module to take effect. Apache does not need to be recompiled.

Test results such as:

Third, install MySQL

1. Download
Download mysql-5.1.65.tar.gz on official website (note that the source package)
2. Decompression
TAR-ZXVF mysql-5.1.65.tar.gz
3. Set up the target folder
Mkdir/usr/local/mysql
In other words, wait for the installation of MySQL to install into this folder
4. Configuration
./configure--prefix=/usr/local/mysql/

in./configure error occurred: Error:no Curses/termcap Library found

Download and install the appropriate package

Yum List|grep ncurses

Yum-y Install Ncurses-devel

Yum Install Ncurses-devel

5. Compiling
Make
6. Installation
Make install

7, startup
    MySQL service does not start automatically, you need to initialize the MySQL database first, the following actions:
    Cd/usr/local/mysql/bin
    sudo./mysql_install_db--user=root
     Note that the last root here is the user who can manipulate the database, Can be the current user, can also create a new user, and the root user on Linux is different, you can take a name
   ./mysqld_safe--user=root &  This command is responsible for starting the daemon of the MySQL service, in addition to the final & must, because you want the daemon to run in the background
    root here is just that
8, create a password for the root user
        ./mysqladmin-u root password ' 123456 '
        If Root has already set a password, use the following method
       ./mysqladmin-u root password oldpass ' 123456 '           
9, Test
    mysql-u root-p
    prompts for a password, Just use the password you just set
    123456
    If a mysql> is present, the connection is successful, the following command creates a database, builds a table, adds a record, Prepare for the subsequent test

mysql> CREATE DATABASE Gywtest;
mysql> use gywtest;

Mysql> CREATE TABLE student (ID int (4) NOT null primary key Auto_increment,stuname char (20));

mysql> INSERT into student (Stuname) VALUES (' Tom ');

Note that there is a semicolon behind each command, and if all of the above are successful, you can use this test later.

Iv. combining PHP with MySQL

1, reconfigure PHP, change the configuration options, simply repeat the PHP installation of the last three steps configure, make, and made install, and then need to restart Apache for the new module to take effect, Apache does not need to recompile.

2. Configuration

./configure--prefix=/usr/local/php--with-apxs2=/usr/local/apache2/bin/apxs--with-mysqli=/usr/local/mysql/bin/ Mysql_config Note the path of Mysql_config
3. Compile make

4. Install Make Installe

5, test write a page test.php, placed in the Apache web directory, test the above with the command to create a database

<?php
$mysqli =new mysqli ();
$mysqli->connect (' localhost ', ' root ', ' 123456 ', ' gywtest ');
Create a query
$SQLSTR = ' SELECT * from student ';
Send a query to MySQL
$result = $mysqli->query ($SQLSTR);
while ($row = $result->fetch_object ())
{
$name = $row->stuname;
Echo $name;
}
?>

Fatal error:class ' mysqli ' not found in/home/lufangtao/project/db.php on line 3

Workaround:

/usr/local/php/bin/phpize here return to run

Error:

Cannot find CONFIG.M4.
Make sure this you run './phpize ' in the top level source directory of the module

Workaround:

PHP Source Package folder under the Ext folder is the current version of the available extensions, CD in to see what you need? You should see the Mysqli folder.

Executing phpize in the current directory

[Email protected] Mysqli]#/usr/local/php/bin/phpize

Configuring for:

PHP Api version:20090626

Zend Modeule Api no:20090626

Zend Extension Api no:220090626

Cannot find autoconf. Please check your autoconf installation and the
$PHP _autoconf environment variable. Then, rerun the this script.

Workaround:

Yum Install autoconf run the above command again.

[Email protected] mysqli]#./configure–prefix=/opt/mysqli–with-php-config=/opt/php/bin/php-config–with-mysqli=/ Opt/mysql/bin/mysql_config

[[email protected] mysqli] #make

[[email protected] mysqli] #make Install

After the installation is complete, you will be prompted to expand the directory path, such as:

/opt/php/lib/php/extensions/no-debug-zts-20090626php

The required mysqli.so will be in this directory, next modify the php.ini file under/opt/php/etc/, add the mysqli extension, that is, add the following line:

Extension=/opt/php/lib/php/extensions/no-debug-zts-20090626/mysqli.so

There's still an error back there:

Reference Blog http://www.cnblogs.com/wangtao_20/archive/2011/03/07/1973621.html

Resolves a method that does not extend the connection to MySQL.

Finally, there is no solution to the mysqli connection problem, but the MySQL database is available, the following is the test program

<?php$link=mysql_connect (' localhost ', ' root ', ' 123456 '), if (! $link) echo "f!"; else echo "s!"; mysql_select_db ("Students") or Die ("Could not select Database"), $query = "select * from student;"; $result =mysql_query ($query) or Die ("Query failed");p rint "<table>\n"; while ($line = Mysql_fetch_array ($result, Mysql_assoc)) {        
print "\t<tr>\n";
foreach ($line as $col _value) {
Print "\t\t<td> $col _value</td>\n";
}
print "\t</tr>\n"; }
print "</table>\n"; /* Release Resources */mysql_free_result ($result); Mysql_close ();? >~

Linux under Configuration Install PHP environment (APACHE2)

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.