Install and configure the PHP environment in Linux (Apache2)

Source: Internet
Author: User
Tags zts

Install and configure the PHP environment in Linux (Apache2)

In the Linux environment, configure and install the PHP environment (Apache2) and refer to some other people's configuration methods for online query. The installation steps are as follows:

1. Install Apache2.2.22
1. Go to the official website to download http://httpd.apache.org/download.cgi
2. Decompress
Tar-zxvf httpd-2.2.22.tar.gz
3. Create the target folder (note that all of the following operations are performed under the root user)
Mkdir/usr/local/apache2
That is to say, wait for the installed apache2 to be installed in this folder.
4. Configuration
Return to the original decompressed folder
./Configure -- prefix =/usr/local/apache2 -- enable-module = shared
Add the following parameters. Otherwise, php cannot be used.-enable-module = shared indicates that Apache can dynamically load modules.

In this step, there are many problems:

The first error is:

Checking for APR... noconfigure: error: APR not found. Please read the documentation.
Solution:
download the latest versions of both APR and APR-Util from Apache APR, unpack them into ./srclib/apr and ./srclib/apr-util (be sure the domain names do not have version numbers; for example, the APR distribution must be under ./srclib/apr/)

Then do

./configure --with-included-apr
Original article: http://stackoverflow.com/questions/9436860/apache-httpd-setup-and-installatio
Another solution is:
Install APR and APR-util respectively. The installation method is as follows: Download the two files, decompress them, and enter the decompressed directory, then install APR and APR-util in the/usr/local/folder respectively. The specific installation method of APR is as follows:
[Root @ localhost 52 lamp] # tar-zxvf apr-1.4.2.tar.gz // unzip-o apr-1.4.2.zip
[Root @ localhost 52 lamp] # 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 and install Gcc.
The third problem is: pcre-config for libpcre not found
The solution is to download the prce installation package, which is similar to APR. install it in the/usr/local/pcre folder. PS: the command for installing c ++ compiler g ++ under Fedora is: yum install gcc-c ++.
5. Compile
Make
6. Installation
Make install
7. Start, restart, and stop. Switch to the directory/usr/local/apache2/bin after installation.
./Apachectl-k start
./Apachectl-k restart
./Apachectl-k stop
8. configuration file (for the most basic configuration)
Edit the/usr/local/apache2/conf/httpd. conf file
Find:
AddType application/x-compress. Z
AddType application/x-gzip. gz. tgz
Add:
AddType application/x-httpd-php. php (enable Apcche to 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
To:
ServerName 127.0.0.1: 80 or ServerName localhost: 80
Remember to remove the previous "#"
9. Test
Enter http: // 127.0.0.1 in the browser
If It Works appears! It indicates the operation is successful. This is my test result: O (lead _ lead) 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, you can create a/home/gyw/WebSite directory as the apache site directory.

Find the DocumentRoot line and change it to DocumentRoot "/home/gyw/WebSite"

Find <Directory> and change this line to <Directory "/home/gyw/WebSite">

Test: An error occurred while modifying to a folder:

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

Solution:

Change file permissions; chmod 755 index.html

Open the apache configuration file httpd. conf and find the following section:
<Directory/>
Options FollowSymLinks
AllowOverride None
Order deny, allow
Deny from all
Satisfy all
</Directory>

The test results are as follows:

 

Ii. install PHP
1. Download
Http://www.php.net/downloads.php
2. Decompress
Tar-zxvf php-5.3.16.tar.gz
3. Create the target folder
Mkdir/usr/local/php
That is to say, wait for the php to be installed in this folder.
4. Configuration
Return to the decompressed 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,apxsIs a tool for compiling and installing extension modules for the Apache HTTP Server.mod_soProvidedLoadModuleThe command is loaded to the Apache server at runtime. In my understanding, this tool dynamically loads the PHP module into Apache.

Error: configure: error: xml2-config not found. Please check your libxml2 installation.

Run yum install libxml2, and then run the yum install libxml2-devel to reinstall the above./configure command.

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

9. Restart apache
10. Test
Create a php file test. php under apache htdocs with the following content:
<? Php
Phpinfo ();
?>
Enter http: // 127.0.0.1/test. php In the browser
If the php configuration is successful, if nothing is entered, it indicates that the configuration fails. Repeat the preceding steps or find the cause.

If you decide to change the configuration option after installation, repeat the last three steps configure, make, and make install, and then restart Apache to make the new module take effect. Apache does not need to be re-compiled.

The test result is as follows:

Iii. Install MySql

1. Download
Download mysql-5.1.65.tar.gz from the official website (note the source code package)
2. Decompress
Tar-zxvf mysql-5.1.65.tar.gz
3. Create the target folder
Mkdir/usr/local/mysql
That is to say, wait for the mysql to be installed in this folder.
4. Configuration
./Configure -- prefix =/usr/local/mysql/

Error in./configure: error: No curses/termcap library found

Download and install the software package

Yum list | grep ncurses

Yum-y install ncurses-devel

Yum install ncurses-devel

5. Compile
Make
6. Installation
Make install

7. Start
MySQL does not start automatically. You must initialize the MySQL database as follows:
Cd/usr/local/mysql/bin
Sudo./mysql_install_db -- user = root
Note: The final root here refers to the user who can operate the database. It can be the current user or a new user. It is different from the root user on linux and can be named by yourself.
./Mysqld_safe -- user = root & this command is used to start the daemon process of the mysql service. In addition, this command is required at the end of "&" because you want the daemon to run in the background.
Here, the root is the one
8. Create a password for the root user
./Mysqladmin-u root password '123'
If the root user has set a password, use the following method:
./Mysqladmin-u root password oldpass '000000'
9. Test
Mysql-u root-p
You will be prompted to enter the password.
123456
If mysql> is displayed, the connection is successful. Run the following command to create a database, create a table, and add a record to prepare 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 each command is followed by a semicolon. If the preceding command is successful, you can use this test later.

4. Combine PHP with MySql

1. reconfigure PHP and change the configuration options. You only need to repeat the last three steps of configure, make, and make install during PHP installation, and then restart Apache to make the new module take effect, apache does not need to be re-compiled.

2. Configuration

. /Configure -- prefix =/usr/local/php -- with-apxs2 =/usr/local/apache2/bin/apxs -- with-mysqli =/usr/local/mysql/bin/mysql_config note mysql_config path
3. Compile make

4. Install make installe

5. test and write a page named test. php, which is stored in the apache web directory, and test the database created with the command above.

<? Php
$ Mysqli = new mysqli ();
$ Mysqli-> connect ('localhost', 'root', '000000', 'gywtest ');
// Create a query
$ Sqlstr = 'select * from student ';
// Send the 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

Solution:

/Usr/local/php/bin/phpize press enter to run

Error:

Cannot find config. m4.
Make sure that you run './phpize' in the top level source directory of the module

Solution:

The EXT folder in the PHP source package folder contains the available extensions of the current version. Go to the CD and see what you need? You should see the mysqli folder ~~~

Run phpize in the current directory

[Root @ localhost mysqli] #/usr/local/php/bin/phpize

Processing ing:

PHP Api Version: 20090626

Zend Modeule Api No: 20090626

Zend Extension Api No: 220090626

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

Solution:

Yum install autoconf run the preceding 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, a message is displayed, indicating the directory path of the extension, such:

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

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

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

The following error occurs:

The solution does not require extended connection to MySQL.

In the end, the problem of MySQLi connection is still not solved, but you can use the MySQL database. below is the test program

<? Php $ link = mysql_connect ('localhost', 'root', '123'); if (! $ Link) echo "F! "; Else echo" S! "; Mysql_select_db (" students ") or die (" cocould 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 <td> $ col_value </td> \ n ";
}
Print "\ t </tr> \ n ";}
Print "</table> \ n";/* release resources */mysql_free_result ($ result); mysql_close () ;?> ~

 

Experience PHP 7.0 on CentOS 7.x/Fedora 21

Install LNMP in CentOS 6.3 (PHP 5.4, MyySQL5.6)

Nginx startup failure occurs during LNMP deployment.

Ubuntu install Nginx php5-fpm MySQL (LNMP environment setup)

Detailed php hd scanning PDF + CD source code + full set of teaching videos

Configure the php lnmp development environment in CentOS 6

PHP details: click here
PHP: click here

This article permanently updates the link address:

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.