CentOS LAMP环境搭建(基于Apache模块)

所需安装包:httpd-2.4.10.tar.gz、mysql-5.5.40-linux2.6-x86_64.tar.gz、php-5.4.34.tar.gz

1、安装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-mods-shared=most --enable-mpms-shared=all --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util

# make

# make install

2、修改httpd配置文件

# vim /etc/httpd/httpd.conf

pidfile "/var/run/httpd.pid"

ServerName 192.168.101.168

3、添加服务启动脚本

# 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/httpd.pid

#

### BEGIN INIT INFO

# Provides: httpd

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

# Required-Stop: $local_fs $remote_fs $network

# Should-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 the

# 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 [email protected]

RETVAL=$?

;;

*)

echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|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、修改httpd PATH环境变量

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

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

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

5、安装mysql,这里使用官方的通用二进制包

# 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、创建mysql用户和组

# groupadd -r -g 306 mysql

# useradd -g 306 -r -u 306 mysql

7、初始化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、创建mysql服务启动脚本

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

# chkconfig --add mysqld

9、修改mysql配置,启动mysql

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

# vim /etc/my.cnf

# 在[mysqld]段添加以下两行

datadir = /data/mysql

thread_concurrency = 4

# service mysqld start

10、修改MySQL PATH环境变量

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

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

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

11、输出mysql的man手册至man命令的查找路径

# vim /etc/man.config

MANPATH /usr/local/mysql/man

12、输出mysql的库文件至系统库查找路径

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

/usr/local/mysql/lib

# ldconfig

13、链接mysql的头文件至系统头文件路径/usr/include

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

14、安装PHP

安装所需依赖包:

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

# 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

注意:

1. 这里为了支持apache的worker或event这两个MPM模块,编译时使用了--enable-maintainer-zts选项;

2. 如果使用PHP5.3以上版本,为了链接MySQL数据库,可以指定mysqlnd,这样在本机就不需要先安装MySQL或MySQL开发包了;

3. mysqlnd从php 5.3开始可用,可以在编译时绑定它(而不用和具体的MySQL客户端库绑定形成依赖,例如MySQL为远程服务器),但从PHP 5.4开始它就是默认设置了。

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

15、创建php配置文件

# mv /etc/php.ini /etc/php.ini.bak

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

16、修改httpd支持php,重启httpd

# vim /etc/httpd/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

17、创建index.html主页(注意这里mysql没有配置账号密码)

# cd /usr/local/apache/htdocs/

# vim index.php

<?php

$conn=mysql_connect(‘localhost‘,‘‘,‘‘);

if ($conn)

echo "Success...";

else

echo "Failure...";

phpinfo();

?>

# 浏览器访问:http://192.168.101.168

18、安装php的xcache加速器

# 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、整合php和xcache,重启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/"

## 其它参数按需修改 ##

# vim /etc/php.ini

date.timezone = Asia/Shanghai

# httpd -t;service httpd restart

# 浏览器访问:http://192.168.101.168    ;;搜索xcache

# 浏览器访问:http://192.168.101.168/xcache

20、httpd虚拟主机配置示例

# vim /etc/httpd/httpd.conf

#DocumentRoot "/usr/local/apache/htdocs"    ;; 注释此行

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

# 浏览器访问:http://www.test1.com、http://www.test2.com

21、启用status查看服务器状态

# mod_status模块可以让管理员查看服务器的执行状态,它通过一个HTML页面展示了当前服务器的统计数据,这些数据通常包括但不限于:

1. 处于工作状态的worker进程数

2. 空闲状态的worker进程数

3. 每个worker的状态,包括此worker已经响应的请求数,及由此worker发送的内容的字节数

4. 当前服务器总共发送的字节数

5. 服务器自上次启动或重启以来至当前的时长

6. 平均每秒钟响应的请求数、平均每秒钟发送的字节数、平均每个请求所请求内容的字节数

# 启用状态页面,只需要在主配置文件中添加如下内容即可:

<Location /server-status>

SetHandler server-status

Require all granted

</Location>

# 需要注意的是,这里的状态信息不应该被所有人随意访问,因此,应限制仅允许某些特定地址的客户端查看。比如使用Require ip 192.168.101.0/24来限制仅允许指定网段的主机查看此页面。

时间: 2024-09-30 20:50:47

CentOS LAMP环境搭建(基于Apache模块)的相关文章

CentOS LAMP环境搭建(基于fastcgi)

所需安装包:httpd-2.4.10.tar.gz.mysql-5.6.21-linux-glibc2.5-x86_64.tar.gz.php-5.4.34.tar.gz 1.安装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 # ./configur

[LAMP环境搭建一]Apache安装

vi /etc/sysconfig/network-scripts/ifcfg-eth0加入 ONBOOT=yes //启动时网络接口是否有效这样就可以自动连接网络了 /********************删除自带的apache:service httpd stopyum remove httpd/********************安装前准备:yum -y install gcc gcc-c++ libtool /*******************下载:apache源码包 注意是h

基于CentOS 6.8平台最新源代码包LAMP环境搭建(Apache+MySQL+PHP)

部署环境 系统:CentOS6.8 x86_64 Apache:2.4.23 MySQL:5.7.14 PHP:7.0.10 apr:1.5.2 apr-util:1.5.4 boost:1.59.0 cmake:3.6.1 pcre:8.39 软件包准备 这里CentOS6.8系统(无需图形环境)的安装过程略,使用个人电脑(Windows系统)的浏览器访问Apache官方网站 http://www.apache.org/ 点击下载页面标签 点击建议的镜像下载站点 找到apr目录 这里下载最新版

转载自php100中文网 centos下lamp 环境搭建

学习PHP脚本编程语言之前,必须先搭建并熟悉开发环境,开发环境有很多种,例如LAMP.WAMP.MAMP等.这里我介绍一下LAMP环境的搭建,即Linux.Apache.MySQL.PHP环境. 一.首先安装操作系统 操作系统:centos6.3 IP地址:192.168.146.129 网关: DNS: 操作系统安装步骤,此处不在给出截图. 备注:服务器系统采用最小化安装,安装一下GCC编译工具和一个桌面即可.如下图所示: <a href="http://www.php100.com/u

基于LAMP环境搭建Discuz

========================写在前面的话========================= 1.LAMP环境搭建请查看这篇日志:http://blog.163.com/wangke_email/blog/static/150335003201610315142268/ 2.这只是一篇简单的Discuz安装教程,深入内容以后会讲到. 3.Discu-3.2下载路径:http://download.comsenz.com/DiscuzX/3.2/Discuz_X3.2_SC_UT

LAMP环境搭建之编译安装指南(php-5.3.27.tar.gz)

测试环境:CentOS release 6.5 (Final) 软件安装:httpd-2.2.27.tar.gz   mysql-5.1.72.tar.gz   php-5.3.27.tar.gz 1.mysql安装详见:https://www.cnblogs.com/su-root/p/11210794.html 2.apache安装详见:https://www.cnblogs.com/su-root/p/11182549.html 3.PHH安装如下: 一.php安装准备 ①yum安装php

新版LAMP环境搭建

新版LAMP环境搭建 注意:先安装MySQL和Apache,后安装PHP,因为PHP配置编译的时候需要指定mysql路径和apache路径. 编译安装: httpd-2.4.12.tar.gz +  mysql-5.6.22-linux-glibc2.5-x86_64.tar.gz  +  php-5.4.39.tar.gz + xcache-2.0.0.tar.gz 实验环境:               CentOS 6.5 x86_64 编译安装Apache (1)构建MPM为静态模块 在

LAMP环境搭建教程

学习PHP脚本编程语言之前,必须先搭建并熟悉开发环境,开发环境有很多种,例如LAMP.WAMP.MAMP等.这里我介绍一下LAMP环境的搭建,即Linux.Apache.MySQL.PHP环境. 一.首先安装操作系统 操作系统:centos6.3 IP地址:192.168.146.129 网关: DNS: 操作系统安装步骤,此处不在给出截图. 备注:服务器系统采用最小化安装,安装一下GCC编译工具和一个桌面即可.如下图所示: 二.LAMP安装前的准备 1.获取软件包 httpd-2.4.2.ta

LAMP 环境搭建 C7

#LAMP环境搭建Centos 7        (1)安装开发包组 "Development Tools" "Server Platform Development"    yum groupinstall            注:关闭selinux iptables(2)安装amp    (a)yum install httpd php  php-mysql mariadb mod_ssl        (b)https://xcache.lighttpd.n