Linux system Installation configuration PHP Environment (APACHE2) tutorial Detailed

Source: Internet
Author: User
Tags configuration php extend mkdir zts create database file permissions zend
In the Linux environment to configure the installation of PHP environment (APACHE2), refer to some other people's configuration methods, encountered problems on the Internet to check. The following is the installation step:

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.
解决方法:

The code is as follows Copy Code
Download the latest versions of both Apr and apr-util from Apache Apr, unpack them to./srclib/apr and./srclib/apr-util (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 workaround is:
respectively installed APR and Apr-util, installation method is: First download the two files, and then extract, into the decompression directory, and then the APR and Apr-util installed to the/usr/local/folder Apr and Apr-util folder. 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
Install Apr-util in./confiure--prefix=/usr/local/apr-util--WITH-APR=/USR/LOCAL/APR
Other steps are similar.

The second error is: No acceptable C compiler found in $Path
Run yum install gcc directly, install GCC
The third question is: Pcre-config for Libpcre not found
The solution is to download the Prce installation package, similar to the APR, and install it 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, 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 file (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
To add later:
AddType application/x-httpd-php. PHP (make Apcche 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 "#" in front.
9, testing
Enter http://127.0.0.1 in the browser
If the IT works! appears to be successful. 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 created when Apache is installed apxs and is a tool for compiling and installing extension modules for Apache HTTP servers so that they 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 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/

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, compile
Make
6, installation
Make install

7, start
The MySQL service does not start automatically, and the MySQL database needs to be initialized first, 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, either the current user or the new user, which is different from the root user on Linux and can be named by itself.
./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
The root here is that one.
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, testing
Mysql-u root-p
You will be prompted to enter your password, using 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, prepares the test for a later

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

There will still be an error:

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.