CentOS LAMP environment (based on Apache module)

Source: Internet
Author: User
Tags zts

CentOS LAMP environment (based on Apache module)

Installation Package: httpd-2.4.10.tar.gz?mysql-5.40-linux2.6-x86_64.tar.gz=php-5.4.34.tar.gz

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 Environment 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.5.40-linux2.6-x86_64.tar.gz-C/usr/local

# Cd/usr/local

# Ln-sv mysql-5.5.40-linux2.6-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

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

# Vim/etc/my. cnf

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

Datadir =/data/mysql

Thread_concurrency = 4

# Service mysqld start

10. Modify the MySQL PATH 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 -- 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

# Make

# Make test

# Make install

Note:

1. To support the two MPM modules of apache worker or event, the -- enable-maintainer-zts option is used during compilation;

2. If PHP5.3 or later 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;

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

# Mv/etc/php. ini/etc/php. ini. bak

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

16. Modify httpd to support php 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

# Httpd-t; service httpd restart

Create the index.html homepage in 172.16. (note that the account and password are not configured in mysql)

# Cd/usr/local/apache/htdocs/

# Vim index. php

<? Php

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

If ($ conn)

Echo "Success ...";

Else

Echo "Failure ...";

Phpinfo ();

?>

# Browser access: http: // 192.168.101.168

18. 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-zts-20100525 /##

19. Integrate php and xcache and restart httpd

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

# Cp-r htdocs/usr/local/apache/htdocs/xcache

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

Extension = xcache. so

Xcache. count = 2

Xcache. mmap_path = "/tmp/xcache"

Cache. coredump_directory = "/tmp/phpcore /"

# Modify other parameters as needed ##

# Vim/etc/php. ini

Date. timezone = Asia/Shanghai

# Httpd-t; service httpd restart

# Browser access: http: // 192.168.101.168; search for xcache

# Browser access: http: // 192.168.101.168/xcache

20. httpd VM configuration example

# Vim/etc/httpd. conf

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

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

# Cd/etc/httpd/

# Vim extra/httpd-vhosts.conf

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

<VirtualHost *: 80>

ServerName www.test1.com

DocumentRoot "/data/www/test1.com"

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

<VirtualHost *: 80>

ServerName www.test2.com

DocumentRoot "/data/www/test2.com"

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

Options none

AllowOverride none

Require all granted

</Directory>

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

CustomLog "/var/log/httpd/test2-access_log" common

</VirtualHost>

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

# Mkdir-p/data/www/test {1, 2}. com

# Mkdir-p/var/log/httpd

# Httpd-t; service httpd restart

# Echo "test1.com">/data/www/test1.com/index.html

# Echo "test2.com">/data/www/test2.com/index.html

# Browser access: http://www.test1.com, http://www.test2.com

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

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.