Compile and install lamp in CentOS 6, and install PHP and centosfpm In the event module mode and FPM mode respectively.

Source: Internet
Author: User

Compile and install lamp in CentOS 6, and install PHP and centosfpm In the event module mode and FPM mode respectively.

 

Task objectives:

Compile and install LAMP

Requirement (1) install a modular PHP

Requirement (2) install a FPM PHP

 

Note that PHP requires the last installation, because the first two are supported.

So the installation order here is

1. httpd

2. MariaDB

3. PHP

 

 

1. Install the package Group

# Yum groupinstall "Development Tools" "Server Platform Development"-y

2. Resolve Dependencies

1. Install pcre

# Yum install pcre-devel-y

2. Install apr

# Tar xf apr-1.5.2.tar.bz2

# Cd apr-1.5.2

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

# Make & make install

3. Install apr-util

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

# Cd apr-util-1.5.4

#./Configure -- prefix =/usr/local/apr-util -- with-apr =/usr/local/apr

# Make & make install

Iii. Compile and install httpd 2.4

1. Compile and install

# Tar xf httpd-2.4.23.tar.bz2

# Cd httpd-2.4.23

#. /Configure -- prefix =/usr/local/apache -- sysconf =/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

# Make & make install

Parameters:

-- Prefix =/usr/local/apache: Set the installation directory to/usr/local/apache.

-- Sysconf =/etc/httpd24 service configuration file storage directory

-- Enable-so supports the DSO mechanism and enables modularity.

-- Enable-ssl supports the ssl Function

-- Enable-cgi supports CGI.

-- Enable-rewrite supports url rewriting.

-- With-zlib supports transmission Compression

-- With-pcre supports pcre Regular Expressions

-- With-apr =/usr/local/apr specifies the apr installation location

-- With-apr-util =/usr/local/apr-util/Specify the installation location of apr-util

-- Enable-modules = most enable module level: most

-- Enable-mpms-shared = all compile all supported Modes

-- With-mpm = event indicates that the mpm module is in the event mode.

2. Provide a script for the new httpd

# Cd/etc/rc. d/init. d/

# Cp httpd httpd24

# Vim httpd24

About 42 rows

Apachectl =/usr/local/apache/bin/apachectl

Httpd =$ {HTTPD-/usr/local/apache/bin/httpd}

Pidfile =$ {PIDFILE-/usr/local/apache/logs/httpd. pid}

Lockfile =$ {LOCKFILE-/var/lock/subsys/httpd24}

Save and exit

3. Add to service list

# Chkconfig -- add httpd24

4. Remove the hash Cache

# Hash-r

5. Add the new httpd to the Environment Variable

# Vim/etc/profile. d/httpd. sh

Content:

Export PATH =/usr/local/apache/bin: $ PATH

6. Repeat the modified environment variable.

#./Etc/profile. d/httpd. sh

7. Check

# Hash

8. Check the Configuration File Syntax

# Httpd-t

9. First turn off httpd of Version 2.2

# Service httpd stop

10. Start httpd of version 2.4

# Service httpd24 start

11. Check port 80

# Ss-tnl

# Ps aux | grep httpd

12. Check whether the event module (mpm_event_module (shared) is loaded ))

# Httpd-M

4. Install MariaDB

1. Unzip the installation package to/usr/local /.

# Tar xf mariadb-5.5.53-linux-x86_64.tar.gz-C/usr/local

2. Create a data storage directory

# Mkdir-pv/mydata/data

3. Create a mysql user

# Useradd-r mysql

4. Attach permissions to the data storage directory

# Chown-R mysql. mysql/mydata/data/

5. Create a soft connection to mysql

# Cd/usr/local

# Ln-sv mariadb-5.5.53-linux-x86_64/mysql

6. Update the owner group of all files

# Cd mysql/

# Chown-R root. mysql ./*

7. initialize the database

# Scripts/mysql_install_db -- datadir =/mydata/data/-- user = mysql

8. Provide configuration files

# Mkdir/etc/mysql

# Cp support-files/my-large.cnf/etc/mysql/my. cnf

9. modify the configuration file

# Vim/etc/mysql/my. cnf

Add blank lines near 42 rows

Datadir =/mydata/data

Innodb_file_per_table = on

Skip_name_resolve = on

10. Save and exit

11. Create a service

# Cp/usr/local/mysql/support-files/mysql. server/etc/rc. d/init. d/mysqld

# Chkconfig -- add mysqld

12. Start mysql

# Service mysqld start

13. Check 3306

# Ss-tnl

14. test connection to mysql

#/Usr/local/mysql/bin/mysql

15. Run the Security Initialization Script, including the root user's password creation.

#/Usr/local/mysql/bin/mysql_secure_installation

5. Compile and install php in module Mode

1. decompress the installation package

# Tar xf php-5.5.38.tar.bz2

2. Install libmcrypt-devel and bzip2-devel packages for the dependent package libxml2-devel and epel Source

# Yum install bzip2-devel libmcrypt-devel libxml2-devel-y

3. Install

# Cd php-5.5.38

. /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

Parameters:

-- Prefix =/usr/local/php default installation path

-- With-mysql =/usr/local/mysql indicates the mysql installation path. If there is a specific path, use the equal sign "=" followed by the path. If not, omit the equal sign "="

-- With-openssl use OpenSSL

-- With-mysqli =/usr/local/mysql/bin/mysql_config define the mysqli Interface

-- Enable-mbstring supports multi-byte strings

-- With-freetype-dir supports various Fonts

-- With-jpeg-dir supports processing jpeg images

-- With-png-dir supports processing images in png format

-- With-zlib supports compressed Libraries

-- With-libxml-dir =/usr supports processing xml documents

-- Enable-xml supports xml

-- Enable-sockets enables php to support sockets communication

-- With-apxs2 =/usr/local/apache/bin/apxs (critical) indicates compiling php into an Apache module

-- With-mcrypt supports encryption and decryption Libraries

-- With-config-file-path =/etc define the php configuration file (php. ini) Placement path

-- With-config-file-scan-dir =/etc/php. d search path for other configuration files

-- With-bz2 supports bz2 format Encryption

-- Enable-maintainer-zts is compiled into the zts module only when mpm is an event and worker. If it is prefork, no

# Make & make install

4. Copy the php configuration file to/etc.

# Cp php. ini-production/etc/php. ini

5. Edit the httpd configuration file

# Cd/etc/httpd24/

Back up first

# Cp httpd. conf {,. bak}

# Vim httpd. conf

Make sure there is such a line (proving that the php5 module is loaded ):

LoadModule php5_module modules/libphp5.so

Add two lines to support documents in php format

AddType application/x-httpd-php. php

AddType application/x-httpd-php-source. phps

Set Default document page

Modify DirectoryIndex index.html

For DirectoryIndex index. php index.html

6. The settings have been completed. Test the following:

6.1 restart httpd24

# Service httpd24 restart

6.2 check port 80

# Ss-tnlp

6.3 check whether php5_module is available

# Httpd-M

6.4 modify the default page to the php format for testing.

# Cd/usr/local/apache/htdocs/

# Mv index.html index. php

# Vim index. php

<? Php

$ Conn = mysql_connect ('2017. 0.0.1 ', 'root ','');

If ($ conn)

Echo "Connect OK! ";

Else

Echo "Failure .";

Mysql_close ();

?>

Enter the above database connection username and password according to your settings.

6.5 test browser access

OK.

6. install PHP again in fpm Mode

1. First clear the decompressed php Directory

# Rm-rf php-5.5.38

2. decompress the package again.

# Tar xf php-5.5.38.tar.bz2

3. Compile and install

# Cd php-5.5.38

#. /Configure -- prefix =/usr/local/php-f -- 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/php-f -- with-config-file-scan-dir = /etc/php-f.d -- with-bz2

This parameter is the biggest difference from the last php configuration.

-- Enable-fpm indicates that fpm is used for compilation.

Therefore, this parameter cannot be set below.

-- With-apxs2 =/usr/local/apache/bin/apxs (indicating to compile php into an Apache module)

In addition, you need to change the relevant path name. Do not name it the same as the php Directory you just installed. Here we will change it to php-f.

-- Prefix =/usr/local/php-f

-- With-config-file-path =/etc/php-f

-- With-config-file-scan-dir =/etc/php-f.d

# Make-j 2 & make install

4. Modify httpd Configuration

4.1 stop httpd first

# Service httpd24 stop

4.2 we need a default httpd. conf. Back up the old one and restore it to the default state.

# Cd/etc/httpd24

# Mv httpd. conf httpd. conf. mod_php

# Cp httpd. conf. bak httpd. conf

4.3 provide configuration files for php

# Mkdir/etc/php-f {,. d}

# Cd

# Cp php-5.5.38/php. ini-production/etc/php-f/php. ini

4.4 Add a service script

# Cp php-5.5.38/sapi/fpm/init. d. php-fpm/etc/rc. d/init. d/php-fpm

4.5 Add execution permission

# Chmod + x/etc/rc. d/init. d/php-fpm

# Chkconfig -- add php-fpm

4.6 modify the configuration file

# Cd/usr/local/php-f/etc

A default configuration file

# Cp php-fpm.conf.default php-fpm.conf

# Vim php-fpm.conf.

Change listening port to all

Listen = 0.0.0.0: 9000

Maximum number of processes

Pm. max_children = 50

Number of processes at startup

Pm. start_servers = 5

Minimum number of idle Processes

Pm. min_spare_servers = 2

Maximum number of idle Processes

Pm. max_spare_servers = 5

Pid path

Pid =/usr/local/php-f/var/run/php-fpm.pid

5. Start php-fpm

# Service php-fpm start

6. Check the process.

# Ps aux | grep fpm

Five idle processes are displayed.

7. Configure httpd2.4 again

1. Edit the httpd24 configuration file

# Cd/etc/httpd24

# Vim httpd. conf

Enable these two modules

LoadModule proxy_module modules/mod_proxy.so

LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

Add file type

AddType application/x-httpd-php. php

AddType application/x-httpd-php-source. phps

Find DirectoryIndex index.html

Change

DirectoryIndex index. php index.html

Uncomment this line and enable the VM configuration file

# Include/etc/httpd24/extra/httpd-vhosts.conf

2. Configure the VM

2.1 create two website folders.

# Mkdir-p/web/vhosts/{pma, wp}

2.2 edit the configuration file and add a VM

# Vim/etc/httpd24/extra/httpd-vhosts.conf

Modify the content as follows:

<VirtualHost *: 80>

ServerAdmin admin@buybybuy.com

DocumentRoot/web/vhosts/pma

ServerName www1.buybybuy.com

ErrorLog logs/pma. err

CustomLog logs/pma. access combined

DirectoryIndex index.html index. php

ProxyRequests Off

ProxyPassMatch ^/(. * \. php) $ fcgi: // 127.0.0.1: 9000/web/vhosts/pma/$1

<Directory "/web/vhosts/pma">

Options Indexes FollowSymLinks

AllowOverride All

Require all granted

</Directory>

</VirtualHost>

<VirtualHost *: 80>

ServerAdmin admin@buybybuy.com

DocumentRoot/web/vhosts/wp

ServerName www2.buybybuy.com

ErrorLog logs/wp. err

CustomLog logs/wp. access combined

DirectoryIndex index.html index. php

ProxyRequests Off

ProxyPassMatch ^/(. * \. php) $ fcgi: // 127.0.0.1: 9000/web/vhosts/wp/$1

<Directory "/web/vhosts/wp">

Options Indexes FollowSymLinks

AllowOverride All

Require all granted

</Directory>

</VirtualHost>

Explanations

ProxyRequests Off: Disable forward proxy

ProxyPassMatch. the file request ending with php is sent to the php-fpm process. php-fpm must at least know the running directory and URI: the two parameters are specified after 9000. The passing of other parameters has been encapsulated by mod_proxy_fcgi.so and does not need to be specified manually.

8. Install phpMyadmin

1. Copy all the documents and folders in the decompressed phpMyadmin folder to/web/vhosts/pma /.

# Cd

# Cp-rf/phpMyAdmin-4.4.15.8-all-languages/*/web/vhosts/pma/

2. Edit the phpMyadmin configuration file

# Cd/web/vhosts/pma

3. Back up the original configuration file and edit the new configuration file

# Cp config. sample. inc. php config. inc. php

# Vim config. inc. php

Enter a 32-bit random code.

$ Cfg ['blowfish _ secret '] = 'e2d8e1132dc737b3dc1f05970c0cc9e';/* you must fill in this for cookie auth! */

4. Test

4.1 restart httpd and php-fpm

# Service httpd24 restart

# Service php-fpm restart

4.2 browser test results

5. You can use the default mysql user root to directly log on to the test. the root account settings are already set in section 15th of section 4 above.

6. The same is true for wp installation on another VM.

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.