Three lamp implementation methods

Source: Internet
Author: User

There are three ways to install the lamp platform: rpm package, module-based compilation and installation, and FPM-based compilation and installation of PHP.

I. install PHP in the RPM package:

In centos 6.5, installing httpd, PHP, and mysq with RPM packages is the easiest way. In this case, PHP runs as an httpd module, after installing the RPM package corresponding to PhP, you can view php In the httpd configuration file directory. CONF file. The configuration file defines the library file for loading the PHP module. When the httpd starts a process to respond to the customer's request, if the client requests a PHP page file, httpd will call the PHP module to complete the processing, note that PHP is not generated in this process, and PHP is called as the HTTPd process, if the PHP program code interacts with the database, it is implemented through the PHP-mysql module. The lamp platform installed in this way is implemented based on a single host, and each module cannot be separated, by default, the httpd-2.2 version has been installed on centos 6, other needs to install PHP, as well as MySQL, installation steps:

The test environment is virtual machine, IP Address: 192.168.33.123

# Yum install-y PHP; install PHP

# Yum install-y mysql-server; install MySQL Server

# Yum install-y PHP-mysql; install the PHP driver to connect to MySQL, and connect PHP to the connector of MySQL

# Service mysqld start

# Service httpd start

After the preceding three packages are installed, add the option index of the directoryindex command to the main configuration file of httpd. PHP is a page that supports the PHP format, and then create it in the directory. test whether the web page file ending with PHP can be accessed in the browser. The httpd default site root directory/var/www/html/creates an index under this directory. PHP file, content such:

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/45/C8/wKiom1PrM4DhWXIUAAB9v4a2zXs028.jpg "Title =" 2014-08-13 09_28_37-root @ localhost _ usr_local_apache_htdocs-xshell 4.jpg" alt = "weight"/>

The following output shows that the PHP module works properly:

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/45/C8/wKiom1PrM7KT54vOAAPA4Z9E1z4603.jpg "Title =" 2014-08-13 17_44_21-phpinfo().jpg "alt =" wkiom1prm7kt54voaapa4z9e1z4603.jpg "/>

Add content to the default PHP page that was previously accessed to test whether the database can be accessed normally:

# Vim/var/www/html/index. php

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/45/C9/wKiom1PrNWPRs5okAAC4eiCXr3Q345.jpg "Title =" 2014-08-13 09_42_24-root @ localhost _ usr_local_apache_htdocs-xshell 4.jpg" alt = "weight"/>

Enter http: // 192.168.33.123/index. php In the browser

The following information indicates that PHP and MySQL cannot communicate.

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/45/CA/wKioL1PrOI3BtiLpAACX1AGnIic710.jpg "Title =" 2014-08-13 18_00_19-phpinfo().jpg "alt =" wkiol1proi3btilpaacx1agniic710.jpg "/>

The success information indicates that PHP and MySQL communicate normally.

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/45/C9/wKiom1PrN5Hz97EGAACSQcprJG0926.jpg "Title =" 2014-08-13 18_00_58-phpinfo().jpg "alt =" wkiom1prn5hz97egaacsqcprj1_926.jpg "/>

2. Install the lamp platform by manually compiling and installing PHP

The manually compiled and installed PHP module communicates with httpd through CGI protocol. PHP is a sub-process of httpd. httpd calls the PHP interpreter to execute the corresponding PHP program, httpd is also responsible for the destruction of PHP processes. The manual compilation and installation of PHP is almost identical to the RPM package provided by the system, during the running process, httpd loads the PHP module to work. However, the PHP program has a separate configuration file, which is an independent program. httpd communicates with PHP through the axps2 and httpd processes, axps2 is a hook program provided by Apache. It can communicate with other third-party modules. Therefore, you must specify the path of the axps2 program during PHP compilation so that httpd can call PHP.

Take the httpd-2.4.9, php-5.4.31, mariadb-5.5.39 version as an example, in the host 192.168.1.small, to achieve lamp platform compilation and installation:

1. Compile and install the httpd-2.4.10, httpd-2.4 and above depends on apr1.4 and above, so you need to compile and install APR and APR-util in advance, use APR version 1.5.1, apr-util version is 1.5.3. In addition, you need to install two development packages: development tools and server platform development to complete compilation smoothly:

# Yum groupinstall-y "development tools"

# Yum groupinstall-y "server platform development"

# Yum install-y PCRE; this package can implement URL re-functionality. We recommend that you install

# Yum install-y mod_ssl; Enable httpd to support the SSL Function

# Tar xf apr-1.5.1.tar.bz2

# Cd apr-1.5.1

#./Configure -- prefix =/usr/local/APR

# Make & make install

# Tar xf apr-util-1.5.3.tar.bz2

# Cd apr-util-1.5.3

#./Configure -- prefix =/usr/local/APR-util -- With-Apr =/usr/local/APR

# Make & make install

# Tar xf httpd-2.4.10.tar.bz2

# Cd httpd-2.4.10

#. /Configure -- prefix =/usr/local/Apache -- sysconfdir =/etc/httpd24 -- enable-so -- enable-SSL -- enable-CGI -- enable-Rewrite -- With-zlib -- -PCRE -- With-Apr =/usr/local/APR -- With-Apr-util =/usr/local/APR-util -- enable-modules = most -- enable-MPMs-shared = all -- With-MPM = event; the event model is used to compile httpd. If this model is used, you must specify the maintainer-ZTS option when compiling PHP, because the event model calls the libphp5-zts.so module, You need to specify this option explicitly.

# Make & make install

# Cd/etc/httpd24

# Vim httpd. conf; modify the httpd24 configuration file, add a line of pidfile "/var/run/httpd. PID", and add directoryindex index. php.

# Vim/etc/rc. d/init. d/httpd24; add a script file

# Chmod + x/etc/rc. d/init. d/httpd24

# Chkconfig -- add httpd24

# Service httpd24 start


2. Install MySql in the common binary format. The MySQL path in the common binary format must be in the/usr/local directory named MySQL, because the path and program name defined in the script used for running the program are defined in this way, you need to install MySql in this way. In addition, the MySQL data directory is defined separately in a partition. The partition format is logical volume, which facilitates future extension and backup.

Installation steps:

Create a new partition and format it as ext4. Create a logical volume on the partition and mount it to the specified directory:

# Fdisk/dev/SDA; create a new partition and the partition steps are not listed. Assume that the created partition is sda3.

# Partx-A/dev/SDA

# Kpartx-AF/dev/SDA

# Pvcreate/dev/sda3

# Vgcreate myvg/dev/sda3

# Lvcreate-L 10g-N mydata myvg

# Mke2fs-T ext4-l mydata/dev/myvg/mydata

# Mkdir-PV/mydata/Data

# Vim/etc/fstab

Add a mount entry for the logical volume/dev/myvg/mydata and mount it to the/mydata directory.

# Mount-A; mount the mydata logical volume

# Groupadd-r MySQL; add a MySQL Group

# Useradd-G mysql-r MySQL; add a MySQL user

# Chown-r mysql. MySQL/mydata/data; change the owner group of the data directory used by MySQL to MySQL

# Tar xf mariadb-5.5.36-linux-x86_64.tar.gz-C/usr/local; extract the database program to/usr/local

# Cd/usr/local

# Ln-SV mariadb-5.5.36-linux-x86_64 MySQL; Creating soft links is equivalent to changing the name to facilitate script execution of the program

# Cd MySQL

# Chown-r root. MySQL./*; change the file owner in the MySQL directory to root, and change the group to MySQL.

# Cp support-files/my-large.cnf/etc/MySQL/My. CNF; Provide configuration files for MySQL

# Vim/etc/MySQL/My. CNF; Add the data directory used by the database to the configuration file

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/45/CC/wKioL1PrTOTxz5KFAABtW-_JBJ8181.jpg "Title =" 2014-08-13 19_27_10-root @ localhost _~ -Xshell 4.jpg" alt = "wKioL1PrTOTxz5KFAABtW-_JBJ8181.jpg"/>

There is a scripts directory in the/usr/local/MySQL Directory, which contains the script file initialized by the mariadb database. After the script is run, the database can be initialized. However, when the script is run, it must be in this directory, but not in the directory where the script is located, because the script depends on executable programs in the/usr/local/MySQL/bin directory during running, otherwise, an error is reported.

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/45/CC/wKiom1PrWcyTqnlFAAB1U2jpnnI384.jpg "Title =" 2014-08-12 23_03_44-root @ localhost _ usr_local_mysql-xshell 4.jpg" alt = "regular"/>

After the database Initialization is complete, you need to provide the service startup script file for the database, in the/usr/local/MySQL/support-files/directory, copy the files in this directory to/etc/rc. d/init. d directory:

# Cp support-files/MySQL. Server/etc/rc. d/init. d/mysqld

# Chkconfig -- add mysqld

# Chkconfig -- list mysqld

# Service mysqld start

After the database is installed, the sock file required for MySQL running is generated in the/tmp directory.


Configuration after the database is installed:

Add the PATH environment variable to facilitate the use of database commands such as MySQL to connect to the database:

# Vim/etc/profile. d/MySQL. Sh

Export Path =/usr/local/MySQL/bin: $ path

# Source/etc/profile. d/MySQL. Sh

Export warehouse file:

# Vim/etc/lD. So. conf. d/MySQL. conf

/Usr/local/MySQL/lib

# Ldconfig-V

Export the header file:

# Ln-SV/usr/local/MySQL/include // usr/include/MySQL

The database installation is complete.

3. Compile and install the php-5.4.31

First, resolve the dependency:

# Yum groupinstall-y "desktop platform development"

# Yum-y install bzip2-devel libmcrypt-devel; (libmcrypt-devel in epel source)

Manual compilation and installation of PHP are almost the same as the RPM package provided by the system. During the use process, the PHP module is loaded to work. However, the PHP program has its own configuration file, these configurations are independent and are not part of httpd. When httpd interacts with PHP, you need to call the PHP module, that is, PHP sub-processes are generated to process PHP script programs by calling the PHP interpretation right. However, httpd is responsible for the creation and destruction of these PHP processes.

#. /Configure -- prefix =/usr/local/PHP -- With-mysql =/usr/local/MySQL -- With-OpenSSL -- With-mysqli =/usr/local/MySQL/bin/ mysql_config -- enable-mbstring -- With-FreeType-dir -- With-JPEG-dir -- With-PNG-dir -- With-zlib -- With-libxml-Dir =/usr -- enable-XML -- enable-sockets -- with-apxs2 =/usr/local/Apache/bin/apxs -- With-mcrypt -- With-config-file-Path =/etc -- With-config-file-Scan -Dir =/etc/PHP. D -- with-bz2 -- enable-maintainer-ZTS

Note that the -- enable-maintainer-ZTS option is in the compilation options. Before we define httpd to work under the event model during httpd compilation, PHP must use this option during compilation, because it needs to provide a libphp5-zts.so module, this option is specified during compilation.

# Make & make install

After PHP compilation and installation is complete, we mentioned previously that httpd needs to communicate with PHP Based on CGI protocol, and then calls the PHP interpreter to process the PHP script program, therefore, we need to add entries that call the PHP interpreter execution program in the httpd configuration file:

# Vim/etc/httpd24/httpd. conf

Addtype application/X-httpd-PHP. php

Addtype application/X-httpd-PHP-source. PHPs

Provide configuration files for PHP programs:

# Cp/root/php-5.4.31/PHP. ini-production/etc/PHP. ini

Now that httpd, PHP, and MySQL have been installed, create an index. php page under the root directory of the httpd site to test:

# Vim/usr/local/Apache/htdocs/index. PHP; content, for example: 650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/45/CC/wKiom1PrZE6TS4uSAAB9v4a2zXs659.jpg "Title =" 2014-08-13 09_28_37-root @ localhost _ usr_local_apache_htdocs-xshell 4.jpg" alt = "Alt"/>

Enter http: // 192.168.1.20./ index. php In the browser. The effect is as follows:

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/45/CC/wKiom1PrZJCA9bhhAAI0NqaSzxg980.jpg "Title =" 2014-08-13 09_30_14-phpinfo().jpg "alt =" wkiom1przjca9bhhaai0nqaszxg980.jpg "/>


The interaction between PHP and MySQL is normal. Then, test whether the MySQL database connection is normal. First, use the MySQL command to connect to the database and create a database and the corresponding account, for example:

Mysql> Create Database mydatabase;

Mysql> grant all on mydabase. * To 'wpuser' @ '2017. 0.0.1 'identified by 'wppass ';

Then modify index. php content 650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/45/CE/wKioL1PrafSTXO2OAAC4eiCXr3Q368.jpg "Title =" 2014-08-13 09_42_24-root @ localhost _ usr_local_apache_htdocs-xshell 4.jpg" alt = "regular"/>

Test again:

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/45/CC/wKiom1PraPmS2gQSAACNpBMIGIo572.jpg "Title =" 2014-08-13 09_57_44-phpinfo().jpg "alt =" wkiom1prapms2gqsaacnpbmigio572.jpg "/>

Iii. install and configure the lamp platform in fcgi Mode

Install and configure httpd. MySQL is configured in the same way as the previous one. In this mode, PHP works on another host, httpd communicates with PHP in socket-based mode, httpd works in reverse proxy mode, and PHP needs to be started as a service, the configuration file and service script must be available for listening on a socket. PHP working in this mode does not need to specify the location of the Apache hook program during compilation, nor does it need to specify the ZTS format to generate the corresponding library file options, however, you need to define the working mode as FPM.

1. Resolve Dependencies

# Yum groupinstall-y "X software development ";

2. Compile and install the php-5.4.31

# Tar xf php-5.4.31.tar.bz2

# Cd php-5.4.31

#. /Configure -- prefix =/usr/local/PHP -- With-mysql =/usr/local/MySQL -- With-OpenSSL -- With-mysqli =/usr/local/MySQL/bin/ mysql_config -- enable-mbstring -- With-FreeType-dir -- With-JPEG-dir -- With-PNG-dir -- With-zlib -- With-libxml-Dir =/usr -- enable-XML -- enable-sockets -- enable-FPM -- With-mcrypt -- With-config-file-Path =/etc -- With-config-file-scan-Dir =/etc/PHP. D -- with-bz2

# Make & make install

Provide a configuration file for PHP:

# Cp PHP. ini-production/etc/PHP. In

3. Configure PHP-FPM

Provide scripts for PHP-FPM and add them to the service list:

# Cp SAPI/FPM/init. d. php-FPM/etc/rc. d/init. d/PHP-FPM

# Chmod + x/etc/rc. d/init. d/PHP-FPM

# Chkconfig -- add PHP-FPM

# Chkconfig PHP-FPM on

Provide configuration files for PHP-FPM:

# Cp/usr/local/PHP/etc/php-fpm.conf.default/usr/local/PHP/etc/php-fpm.conf

Edit the configuration file of PHP-FPM:

# Vim/usr/local/PHP/etc/php-fpm.conf

Enable PID File

PID =/usr/local/PHP/var/run/php-fpm.pid

Start PHP-FPM:

# Service PHP-FPM start

By default, FPM runs on port 9000 of 127.0.0.1. You can run the following command to verify the performance:

# Netstat-tnlp | grep PHP-FPM


3. Adjust the HTTP work attribute so that httpd works in reverse proxy mode:

# Vim/etc/httpd24/httpd. conf; enable the mod_proxy-fcgi module and proxy_mod module in the loadmodule command

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/45/CE/wKioL1PrcICAW3XsAADrSV5MVkM102.jpg "Title =" 14_06_47-root @ sueking _ etc_httpd24-xshell 4.jpg" alt = "wkiol1prcicaw3xsaadrsv5mvkm102.jpg"/>

Fcgi can be used to configure virtual hosts. You can also configure fcgi in the central host segment as needed. Add the following content to the configuration file:

Proxyrequests off

Proxypassmatch ^/(. * \. php) $ fcgi: // 127.0.0.1: 9000/usr/local/Apache/htdocs/$1

Edit the Apache configuration file httpd. conf to enable Apache to recognize pages in PHP format, and add a homepage that supports PHP format in documentindex.

# Vim/etc/httpd. COF

Add content

Addtype application/X-httpd-PHP. php

Addtype application/X-httpd-PHP-source. PHPs

Directoryindex index. php index.html



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.