Linux to compile and install the PHP environment

Source: Internet
Author: User
Tags extend mkdir zts create database file permissions

I. Installation of 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, establish the target folder (note that all of the following actions are performed under root)
Mkdir/usr/local/apache2
That is to say, wait for the installed apache2 to be installed inside this folder
4, configuration
Back to the folder that was created after the original decompression
./configure--prefix=/usr/local/apache2--enable-module=shared
You cannot use php,-enable-module=shared to indicate that Apache can dynamically load a module with the following arguments added

This step, there are a lot of problems:

The first error is:

Checking for APR ... no configure:error:APR not
found.  Please read the documentation.
Workaround:
Download the latest versions of both Apr and apr-util from Apache Apr, unpack them to./srclib/apr and./srclib/apr-uti L (be sure the domain names does have version numbers; for example, the APR distribution must. Under)

Then do

./configure--WITH-INCLUDED-APR Original article address: http://stackoverflow.com/questions/9436860/ Apache-httpd-setup-and-installatio Another solution is: the installation of APR and Apr-util, installation method is: First download the two files, and then extract, into the unpacked directory, and then the APR and Apr-util respectively installed to /usr/local/folders under the APR and Apr-util folders. The exact installation method for APR is: [root@localhost 52lamp]# tar-zxvf apr-1.4.2.tar.gz//unzip-o apr-1.4.2.zip [root@localhost 52lamp]# CD apr- 1.4.2 [root@localhost apr-1.4.2]#./configure--prefix=/usr/local/apr [root@localhost apr-1.4.2]# make [root@localhost

apr-1.4.2]# make install installation apr-util is similar to the./confiure--prefix=/usr/local/apr-util--with-apr=/usr/local/apr other steps. The second error is: No acceptable C compiler found in $Path directly run yum install GCC, install GCC The third problem is: Pcre-config for libpcre the not found workaround is to download the Prce installation package, similar to the APR, installed under the/usr/local/pcre folder.
The command for installing the C + + compiler g++ under Ps:fedora is: Yum install gcc-c++. 5, compile     make     6, install     make install   7, start, reboot and stop, First switch to directory after installation/usr/local/apache2/bin    /apachectl-k start    /APACHECTl-k Restart     ./apachectl-k Stop   8, profiles (to meet the most basic configuration)      edit/usr/local/apach e2/conf/httpd.conf files           find:     addtype  application/ X-compress. Z     AddType application/x-gzip gz. tgz     Add later:     AddType application/x-httpd-php. PHP (make Apcche support PHP)     AddType application/x-httpd-php-source .php5         Find:     <ifmodule dir_module>     directoryindex
index.html     </IfModule>     add:     <ifmodule dir_module>
    directoryindex index.html index.php     </IfModule>         find:     #servername www.example.com:80     modified to:     ServerName 127.0.0.1:80 or ServerName localhost:80   &nbsp Remember to remove the front "#"      9, test     enter http://127.0.0.1 in the browser     if it works! Description of success. This is my test result: O (∩_∩) o haha ~



10, modify the default Web site Directory

The default directory is "/usr/local/apache2/htdocs", which modifies the Apache configuration file httpd.conf, such as creating 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 modifying to folder:

"You don ' t have permission to access/index.html on the this server."

Workaround:

Change file permissions; chmod 755 index.html

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

The test results are as follows:




Second, the installation of PHP
1, download
http://www.php.net/downloads.php
2, decompression
TAR-ZXVF php-5.3.16.tar.gz
3, establish the target folder
mkdir/usr/local/php
That is to say, wait for the installation of PHP to install into 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 is a tool for compiling and installing extension modules for Apache HTTP servers. Enables it to be loaded into the Apache server at run time with the LoadModule instructions provided by MOD_SO. My understanding is that the PHP module is dynamically loaded into Apache through this tool.

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

Run yum install LIBXML2, and then run yum install libxml2-devel after installation, rerun the./configure command above.

5, compile
Make
6. Test compilation
Make Test
7, installation
Make install

8. Configuration file

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 the/usr/local/php/lib/php.ini and rename it to PHP.ini

9. Restart Apache
10, testing
Create a PHP file test.php under the Apache Htdocs, which reads as follows:
<?php
Phpinfo ();
?>
And then enter http://127.0.0.1/test.php in the browser.
If PHP is associated with a configuration that succeeds if nothing is entered, the description fails, re-step or find the reason

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

The test results are shown below:



Third, the installation of MySQL

1, download
To the official website download mysql-5.1.65.tar.gz (note is the source package)
2, decompression
TAR-ZXVF mysql-5.1.65.tar.gz
3, establish the target folder
Mkdir/usr/local/mysql
That is to say, wait for the MySQL installation to be installed in this folder
4, configuration
./configure--prefix=/usr/local/mysql/

error occurred in./configure: 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, compile
Make
6, installation
Make install

7, start
    MySQL service does not start automatically, you also need to initialize the MySQL database, the operation is as follows:
    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 Linux root users are two different things, you can take a name
   /mysqld_safe--user=root &  This command is responsible for starting the MySQL service daemon, in addition to the last & must, because you want the daemon to run in the background
    here's root is just that
8, create a password for the root user
        /mysqladmin-u root password ' 123456 '
        If Root has already set the password, use the following method
       ./mysqladmin-u root password oldpass ' 123456 '           
9, test
    mysql-u root-p
    prompts for a password. With the password you just set
    123456
    If Mysql> is present, the connection is successful, the following command creates a database, builds a table, adds a record, Prepare the

for subsequent tests

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 the above is successful, you can use this test later.

Iv. combining PHP with MySQL

1, reconfigure PHP, change configuration options, just repeat the last three steps of the PHP installation configure, make, and made install, and then need to restart Apache so that the new module takes 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 the Mysql_config
3. Compile make

4. Install Make Installe

5, test write a page test.php, put in the Apache web directory, test the database created by the command above

<?php
$mysqli =new mysqli ();
$mysqli->connect (' localhost ', ' root ', ' 123456 ', ' gywtest ');
Create a query
$SQLSTR = ' SELECT * from student ';
Send 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 to line 3

Workaround:

/usr/local/php/bin/phpize here, enter run

Error:

Cannot find CONFIG.M4.
Make sure this you run './phpize ', the '.

Workaround:

The Ext folder under the PHP Source Pack folder is where the current version of the available extensions is placed, and the CD goes in to see what you need. You should see the Mysqli folder ~ ~ ~

Execute phpize in current directory

[Root@localhost 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 this script.

Workaround:

Yum Install autoconf run the above command again.

[Root@localhost mysqli]#./configure–prefix=/opt/mysqli–with-php-config=/opt/php/bin/php-config–with-mysqli=/opt /mysql/bin/mysql_config

[Root@localhost mysqli] #make

[root@localhost mysqli] #make Install

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

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

The required mysqli.so will be in this directory, then modify the php.ini file under/opt/php/etc/and join the mysqli extension by adding the following line:

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

Here or there is the error back:

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

To solve the need to extend the connection to MySQL method.

Finally, there is no solution to the problem of mysqli connection, but you can use the MySQL database, 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");
print "<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 ();

? >
~       


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.