CentOS LAMP environment (based on fastcgi)

Source: Internet
Author: User

CentOS LAMP environment (based on fastcgi)

Required installation package: Installation

1. Install httpd

# Yum install pcre-devel

# Tar xf apr-1.5.1.tar.gz

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

# Make

# Make install

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

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

# Make

# Make install

# Tar xf httpd-2.4.10.tar.gz

# Cd httpd-2.4.10

#. /Configure -- prefix =/usr/local/apache -- sysconfdir =/etc/httpd -- enable-so -- enable-rewrite -- enable-ssl -- enable-cgi -- enable-cgid -- enable -modules = most -- enable-mod-shared = most -- enable-mpms-shared = all -- with-apr =/usr/local/apr -- with-apr-util =/usr /local/apr-util

# Make

# Make install

2. Modify the httpd configuration file

# Vim/etc/httpd. conf

Pidfile "/var/run/httpd. pid"

ServerName 192.168.101.168

3. Add a Service Startup Script

# Vim/etc/init. d/httpd

------------

#! /Bin/bash

#

# Httpd Startup script for the Apache HTTP Server

#

# Chkconfig:-85 15

# Description: The Apache HTTP Server is an efficient and extensible \

# Server implementing the current HTTP standards.

# Processname: httpd

# Config:/etc/httpd/conf/httpd. conf

# Config:/etc/sysconfig/httpd

# Pidfile:/var/run/httpd. pid

#

### BEGIN INIT INFO

# Provides: httpd

# Required-Start: $ local_fs $ remote_fs $ network $ named

# Required-Stop: $ local_fs $ remote_fs $ network

# Shocould-Start: distcache

# Short-Description: start and stop Apache HTTP Server

# Description: The Apache HTTP Server is an extensible server

# Implementing the current HTTP standards.

### END INIT INFO

# Source function library.

./Etc/rc. d/init. d/functions

If [-f/etc/sysconfig/httpd]; then

./Etc/sysconfig/httpd

Fi

# Start httpd in the C locale by default.

HTTPD_LANG =$ {HTTPD_LANG-"C "}

# This will prevent initlog from swallowing up a pass-phrase prompt if

# Mod_ssl needs a pass-phrase from the user.

INITLOG_ARGS = ""

# Set HTTPD =/usr/sbin/httpd. worker in/etc/sysconfig/httpd to use a server

# With the thread-based "worker" MPM; be warned that some modules may not

# Work correctly with a thread-based MPM; notably PHP will refuse to start.

# Path to the apachectl script, server binary, and short-form for messages.

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

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

Prog = httpd

Pidfile =$ {PIDFILE-/var/run/httpd. pid}

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

RETVAL = 0

STOP_TIMEOUT =$ {STOP_TIMEOUT-10}

# The semantics of these two functions differ from the way apachectl does

# Things -- attempting to start while running is a failure, and shutdown

# When not running is also a failure. So we just do it the way init scripts

# Are expected to behave here.

Start (){

Echo-n $ "Starting $ prog :"

LANG = $ HTTPD_LANG daemon -- pidfile =$ {pidfile} $ httpd $ OPTIONS

RETVAL =$?

Echo

[$ RETVAL = 0] & touch $ {lockfile}

Return $ RETVAL

}

# When stopping httpd, a delay (of default 10 second) is required

# Before SIGKILLing the httpd parent; this gives enough time for

# Httpd parent to SIGKILL any errant children.

Stop (){

Echo-n $ "Stopping $ prog :"

Killproc-p $ {pidfile}-d $ {STOP_TIMEOUT} $ httpd

RETVAL =$?

Echo

[$ RETVAL = 0] & rm-f $ {lockfile }$ {pidfile}

}

Reload (){

Echo-n $ "Reloading $ prog :"

If! LANG = $ HTTPD_LANG $ httpd $ OPTIONS-t> &/dev/null; then

RETVAL = 6

Echo $ "not reloading due to configuration syntax error"

Failure $ "not reloading $ httpd due to configuration syntax error"

Else

# Force LSB behaviour from killproc

LSB = 1 killproc-p $ {pidfile} $ httpd-HUP

RETVAL =$?

If [$ RETVAL-eq 7]; then

Failure $ "httpd shutdown"

Fi

Fi

Echo

}

# See how we were called.

Case "$1" in

Start)

Start

;;

Stop)

Stop

;;

Status)

Status-p $ {pidfile} $ httpd

RETVAL =$?

;;

Restart)

Stop

Start

;;

Condrestart | try-restart)

If status-p $ {pidfile} $ httpd> &/dev/null; then

Stop

Start

Fi

;;

Force-reload | reload)

Reload

;;

Graceful | help | configtest | fullstatus)

$ Apachectl $ @

RETVAL =$?

;;

*)

Echo $ "Usage: $ prog {start | stop | restart | condrestart | try-restart | force-reload | status | fullstatus | graceful | help | configtest }"

RETVAL = 2

Esac

Exit $ RETVAL

------------

# Chmod + x/etc/init. d/httpd

# Chkconfig -- add httpd

# Chkconfig -- level 35 httpd on

4. Modify the httpd PATH variable

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

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

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

5. Install mysql. The official Binary Package is used here.

# Tar xf mysql-5.6.21-linux-glibc2.5-x86_64.tar.gz-C/usr/local

# Cd/usr/local/

# Ln-sv mysql-5.6.21-linux-glibc2.5-x86_64 mysql

6. Create mysql users and groups

# Groupadd-r-g 306 mysql

# Useradd-g 306-r-u 306 mysql

7. initialize mysql

# Cd/usr/local/mysql

# Chown-R mysql: mysql/usr/local/mysql /*

# Mkdir-p/data/mysql

# Chown-R mysql: mysql/data/mysql

# Chmod-R 750/data/mysql

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

# Chown-R root/usr/local/mysql /*

8. Create a mysql Service Startup Script

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

# Chkconfig -- add mysqld

9. Modify mysql configuration and start mysql

# Mv/etc/my. cnf/etc/my. cnf. bak

# Cp support-files/my-default.cnf/etc/my. cnf

# Vim/etc/my. cnf

# Add the following two lines in the [mysqld] segment:

Datadir =/data/mysql

Thread_concurrency = 4

[Client]

Socket =/tmp/mysql. sock

# Service mysqld start

10. Modify the MySQLPATH environment variable

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

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

# Source/etc/profile. d/mysql. sh

11. output the mysql man manual to the man command search path.

# Vim/etc/man. config

MANPATH/usr/local/mysql/man

12. output the mysql database file to the system database search path.

# Vim/etc/ld. so. conf. d/mysql. conf

#/Usr/local/mysql/lib

# Ldconfig

13. link the mysql header file to the system header file path/usr/include

# Ln-sv/usr/local/mysql/include/usr/include/mysql

14. install PHP

Install the required dependency package:

Mhash-0.9.9.9-3.el6.x86_64.rpm

Mhash-devel-0.9.9.9-3.el6.x86_64.rpm

Libmcrypt-2.5.8-9.3.x86_64.rpm

Libmcrypt-devel-2.5.8-9.3.x86_64.rpm

# Rpm-ivh mhash-0.9.9.9-3.el6.x86_64.rpmmhash-devel-0.9.9.9-3.el6.x86_64.rpmlibmcrypt-2.5.8-9.3.x86_64.rpmlibmcrypt-devel-2.5.8-9.3.x86_64.rpm

# Tar xf php-5.4.34.tar.gz

# Cd php-5.4.34

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

# Make install

Note:

1. If PHP5.3 or a later version is used, you can specify mysqlnd to connect to the MySQL database, so that you do not need to install MySQL or MySQL development kit on the local machine;

2. mysqlnd is available from php 5.3 and can be bound at compilation (instead of binding to a specific MySQL client library to form a dependency, for example, MySQL is a remote server ), but it is set by default since PHP 5.4.

#./Configure -- with-mysql = mysqlnd -- with-pdo-mysql = mysqlnd -- with-mysqli = mysqlnd

15. Create a php configuration file

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

16. Add a Service Startup Script

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

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

# Chkconfig -- add php-fpm

17. Configure php-fpm and start php-fpm

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

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

Pm. max_children = 100 # maximum child process

Pm. start_servers = 5 # Number of initialization Start Processes

Pm. min_spare_servers = 5 # minimum idle Process

Pm. max_spare_servers = 10 # maximum idle Process

# Service php-fpm start

# Netstat-tunlp # Listen to port 9000

18. Modify httpd to support php, enable httpd-related modules, and restart httpd.

# Vim/etc/httpd. conf

DirectoryIndex index. php index.html

AddType application/x-httpd-php. php

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

LoadModule proxy_module modules/mod_proxy.so

LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

# Httpd-t; service httpd restart

19. httpd VM Configuration

# Vim/etc/httpd. conf

# DocumentRoot "/usr/local/apache/htdocs"; comment this line

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

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

------------

<VirtualHost *: 80>

ServerName www.test1.com

DocumentRoot "/data/www/test1.com"

ProxyRequests off

ProxyPassMatch ^/(. * \. php) $ fcgi: // 127.0.0.1: 9000/data/www/test1.com/#1

<Directory "/data/www/test1.com">

Options none

AllowOverride none

Require all granted

</Directory>

ErrorLog "/var/log/httpd/test1-error_log"

CustomLog "/var/log/httpd/test1-access_log" combined

</VirtualHost>

------------

# Mkdir-p/data/www/test1.com

# Mkdir-p/var/log/httpd

# Httpd-t; service httpd restart

Create test page index.html and index. php In 2018.dita

# Echo "

# Echo"

<? Php

$ Conn = mysql_connect ('localhost ','','');

If ($ conn)

Echo "Success ...";

Else

Echo "Failure ...";

Phpinfo ();

?> ">/Data/www/test1.com/index.php

# Browser access: http://www.test1.com, http://www.test1.com/index.html

21. Install the php xcache accelerator

# Tar xf xcache-3.2.0.tar.gz

# Cd xcache-3.2.0

#/Usr/local/php/bin/phpize

#./Configure -- enable-xcache -- with-php-config =/usr/local/php/bin/php-config

# Make

# Make test

# Make install

#/Usr/local/php/lib/php/extensions/no-debug-non-zts-20100525 /##

22. Integrate php and xcache and restart php-fpm

# Cp xcache. ini/etc/php. d/

# Cp-r htdocs/data/www/test1.com/xcache

# Vim/etc/php. d/xcache. ini

Extension = xcache. so

Xcache. count = 2

Xcache. mmap_path = "/tmp/xcache"

Xcache. coredump_directory = "/tmp/phpcore /"

# Modify other parameters as needed ##

# Vim/etc/php. ini

Date. timezone = Asia/Shanghai

# Service php-fpm restart

# Browser access: http://www.test1.com; Search xcache

# Browser access: http://www.test1.com/xcache

23. Enable status to view Server status

# The mod_status module allows the Administrator to view the execution status of the server. It displays the statistics of the current server through an HTML page, which usually includes but is not limited:

1. Number of worker processes in the working state

2. Number of idle worker Processes

3. The status of each worker, including the number of requests that the worker has responded to and the number of bytes of the content sent by the worker.

4. Total number of bytes sent by the current server

5. The current duration of the server since it was last started or restarted

6. Average number of requests per second, average number of bytes sent per second, and average number of bytes requested by each request

# On the Enable status page, you only need to add the following content to the main configuration file:

<Location/server-status>

SetHandler server-status

Require all granted

</Location>

# Note that the status information here should not be randomly accessed by all users. Therefore, you should restrict access to clients with specific addresses only. For example, you can use Require ip 192.168.101.0/24 to restrict only hosts with specified network segments to view this page.

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.