阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

CentOS 6.5安装配置LAMP

125次阅读
没有评论

共计 11580 个字符,预计需要花费 29 分钟才能阅读完成。

本文主要介绍了 LAMP 的安装。

Linux+Apache+MySQL/MariaDB+Perl/PHP/Python 一组常用来搭建动态网站或者服务器的开源软件,本身都是各自独立的程序,但是因为常被放在一起使用,拥有了越来越高的兼容度,共同组成了一个强大的 Web 应用程序平台

本文所用环境和安装包为 CentOS6.5+httpd 2.4.6+mysql-5.5.33+php-5.4.19+xcache-3.0.3。

Ubuntu 13.04 安装 LAMP\Vsftpd\Webmin\phpMyAdmin 服务及设置 http://www.linuxidc.com/Linux/2013-06/86250.htm

CentOS 5.9 下编译安装 LAMP(Apache 2.2.44+MySQL 5.6.10+PHP 5.4.12) http://www.linuxidc.com/Linux/2013-03/80333p3.htm

RedHat 5.4 下 Web 服务器架构之源码构建 LAMP 环境及应用 PHPWind http://www.linuxidc.com/Linux/2012-10/72484p2.htm

LAMP 源码环境搭建 WEB 服务器 Linux+Apache+MySQL+PHP http://www.linuxidc.com/Linux/2013-05/84882.htm

基于 Ubuntu 的 LAMP 优化加固 http://www.linuxidc.com/Linux/2014-07/104092.htm

一、编译安装 apache

1、解决依赖关系

httpd-2.4.6 需要较新版本的 apr 和 apr-util,因此需要事先对其进行升级。升级方式有两种,一种是通过源代码编译安装,一种是直接升级 rpm 包。这里选择使用编译源代码的方式进行。

(1) 编译安装 apr

# tar xf apr-1.4.6.tar.bz2

# cd apr-1.4.6

# ./configure –prefix=/usr/local/apr

# make && make install

(2) 编译安装 apr-util

# tar xf apr-util-1.5.2.tar.bz2

# cd apr-util-1.5.2

# ./configure –prefix=/usr/local/apr-util –with-apr=/usr/local/apr

# make && make install

(3) httpd-2.4.6 编译过程也要依赖于 pcre-devel 软件包,需要事先安装。此软件包系统光盘自带,因此,找到并安装即可。

参考命令:

#yum install -y pcre-devel

2、编译安装 httpd-2.4.6

首先下载 httpd-2.4.6 到本地

# tar xf httpd-2.4.6.tar.bz2

# cd httpd-2.4.6

# ./configure –prefix=/usr/local/apache –sysconfdir=/etc/httpd –enable-so –enable-ssl –enable-cgi –enable-rewrite –with-zlib –with-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

3、修改 httpd 的主配置文件,设置其 Pid 文件的路径

编辑 /etc/httpd/httpd.conf,添加如下行即可:

PidFile  “/var/run/httpd.pid”

4、提供 SysV 服务脚本 /etc/rc.d/init.d/httpd,内容如下:

#!/bin/bash

#

# httpd        Startup script for the Apache HTTP Server

#

# chkconfig: – 85 15

# description: Apache is a World Wide Web server.  It is used to serve \

#        HTML files and CGI.

# processname: httpd

# config: /etc/httpd/conf/httpd.conf

# config: /etc/sysconfig/httpd

# pidfile: /var/run/httpd.pid

 

# 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

 

start() {

        echo -n $”Starting $prog: “

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

        RETVAL=$?

        echo

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

        return $RETVAL

}

 

stop() {

  echo -n $”Stopping $prog: “

  killproc -p ${pidfile} -d 10 $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=$?

        echo $”not reloading due to configuration syntax error”

        failure $”not reloading $httpd due to configuration syntax error”

    else

        killproc -p ${pidfile} $httpd -HUP

        RETVAL=$?

    fi

    echo

}

 

# See how we were called.

case “$1” in

  start)

  start

  ;;

  stop)

  stop

  ;;

  status)

        status -p ${pidfile} $httpd

  RETVAL=$?

  ;;

  restart)

  stop

  start

  ;;

  condrestart)

  if [-f ${pidfile} ] ; then

    stop

    start

  fi

  ;;

  reload)

        reload

  ;;

  graceful|help|configtest|fullstatus)

  $apachectl $@

  RETVAL=$?

  ;;

  *)

  echo $”Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}”

  exit 1

esac

 

exit $RETVAL

而后为此脚本赋予执行权限:

# chmod +x /etc/rc.d/init.d/httpd

加入服务列表:

# chkconfig –add httpd

接下来就可以启动服务进行测试了。

#service httpd start

打开浏览器访问 ip 地址即可看到:

CentOS 6.5 安装配置 LAMP

更多详情见请继续阅读下一页的精彩内容 :http://www.linuxidc.com/Linux/2014-07/104373p2.htm

二、安装 MySQL-5.5.33

1、准备数据存放的文件系统

新建一个逻辑卷,并将其挂载至特定目录即可。这里不再给出过程。

这里假设其逻辑卷的挂载目录为 /mydata,而后需要创建 /mydata/data 目录做为 mysql 数据的存放目录。

2、新建用户以安全方式运行进程:

# groupadd -r mysql

# useradd -g mysql -r -s /sbin/nologin -M -d /mydata/data mysql

# chown -R mysql:mysql /mydata/data

3、安装并初始化 mysql-5.5.33

首先下载平台对应的 mysql 版本至本地,这里是 64 位平台,因此,选择的为 mysql-5.5.33-linux2.6-x86_64.tar.gz。

# tar xf mysql-5.5.33-linux2.6-x86_64.tar.gz -C /usr/local

# cd /usr/local/

# ln -sv mysql-5.5.33-linux2.6-x86_64  mysql

# cd mysql

# chown -R mysql:mysql  .

# scripts/mysql_install_db –user=mysql –datadir=/mydata/data

# chown -R root  .

4、为 mysql 提供主配置文件:

# cd /usr/local/mysql

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

并修改此文件中 thread_concurrency 的值为你的 CPU 个数乘以 2,比如这里使用如下行:

thread_concurrency = 4

另外还需要添加如下行指定 mysql 数据文件的存放位置:

datadir = /mydata/data

5、为 mysql 提供 sysv 服务脚本:

# cd /usr/local/mysql

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

# chmod +x /etc/rc.d/init.d/mysqld

添加至服务列表:

# chkconfig –add mysqld

# chkconfig mysqld on

6. 在 /etc/profile.d 下创建 mysql.sh,并修改内容:

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

CentOS 6.5 安装配置 LAMP

为了使用 mysql 的安装符合系统使用规范,并将其开发组件导出给系统使用,这里还需要进行如下步骤:

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

编辑 /etc/man.config,添加如下行即可:

 MANPATH /usr/local/mysql/man

8、输出 mysql 的头文件至系统头文件路径 /usr/include:

这可以通过简单的创建链接实现:

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

9、输出 mysql 的库文件给系统库查找路径:

# echo ‘/usr/local/mysql/lib’ > /etc/ld.so.conf.d/mysql.conf

而后让系统重新载入系统库:

# ldconfig

三、编译安装 php-5.4.19

1、解决依赖关系:

# yum install libxml2

# yum install libxml2-devel -y

2、编译安装 php-5.4.19

首先下载源码包至本地目录。

# tar xf php-5.4.19.tar.bz2

# cd php-5.4.19

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

说明:

1、这里为了支持 apache 的 worker 或 event 这两个 MPM,编译时使用了 –enable-maintainer-zts 选项。

2、如果使用 PHP5.3 以上版本,为了链接 MySQL 数据库,可以指定 mysqlnd,这样在本机就不需要先安装 MySQL 或 MySQL 开发包了。mysqlnd 从 php 5.3 开始可用,可以编译时绑定到它(而不用和具体的 MySQL 客户端库绑定形成依赖),但从 PHP 5.4 开始它就是默认设置了。命令为:

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

接着开始安装:

# make

# make test

# make intall

为 php 提供配置文件:

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

3、编辑 apache 配置文件 httpd.conf,以 apache 支持 php

# vim /etc/httpd/httpd.conf

 1、添加如下二行

  AddType application/x-httpd-php  .php

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

 2、定位至 DirectoryIndex index.html

  修改为:

    DirectoryIndex  index.php  index.html

而后重新启动 httpd,或让其重新载入配置文件即可测试 php 是否已经可以正常使用。

4. 测试,在 /usr/local/apache/htdocs 下创建 index.php 文件,内容如下:

<?php

    phpinfo();

 ?>

从浏览器打开测试页如下:

CentOS 6.5 安装配置 LAMP

本文主要介绍了 LAMP 的安装。

Linux+Apache+MySQL/MariaDB+Perl/PHP/Python 一组常用来搭建动态网站或者服务器的开源软件,本身都是各自独立的程序,但是因为常被放在一起使用,拥有了越来越高的兼容度,共同组成了一个强大的 Web 应用程序平台

本文所用环境和安装包为 CentOS6.5+httpd 2.4.6+mysql-5.5.33+php-5.4.19+xcache-3.0.3。

Ubuntu 13.04 安装 LAMP\Vsftpd\Webmin\phpMyAdmin 服务及设置 http://www.linuxidc.com/Linux/2013-06/86250.htm

CentOS 5.9 下编译安装 LAMP(Apache 2.2.44+MySQL 5.6.10+PHP 5.4.12) http://www.linuxidc.com/Linux/2013-03/80333p3.htm

RedHat 5.4 下 Web 服务器架构之源码构建 LAMP 环境及应用 PHPWind http://www.linuxidc.com/Linux/2012-10/72484p2.htm

LAMP 源码环境搭建 WEB 服务器 Linux+Apache+MySQL+PHP http://www.linuxidc.com/Linux/2013-05/84882.htm

基于 Ubuntu 的 LAMP 优化加固 http://www.linuxidc.com/Linux/2014-07/104092.htm

一、编译安装 apache

1、解决依赖关系

httpd-2.4.6 需要较新版本的 apr 和 apr-util,因此需要事先对其进行升级。升级方式有两种,一种是通过源代码编译安装,一种是直接升级 rpm 包。这里选择使用编译源代码的方式进行。

(1) 编译安装 apr

# tar xf apr-1.4.6.tar.bz2

# cd apr-1.4.6

# ./configure –prefix=/usr/local/apr

# make && make install

(2) 编译安装 apr-util

# tar xf apr-util-1.5.2.tar.bz2

# cd apr-util-1.5.2

# ./configure –prefix=/usr/local/apr-util –with-apr=/usr/local/apr

# make && make install

(3) httpd-2.4.6 编译过程也要依赖于 pcre-devel 软件包,需要事先安装。此软件包系统光盘自带,因此,找到并安装即可。

参考命令:

#yum install -y pcre-devel

2、编译安装 httpd-2.4.6

首先下载 httpd-2.4.6 到本地

# tar xf httpd-2.4.6.tar.bz2

# cd httpd-2.4.6

# ./configure –prefix=/usr/local/apache –sysconfdir=/etc/httpd –enable-so –enable-ssl –enable-cgi –enable-rewrite –with-zlib –with-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

3、修改 httpd 的主配置文件,设置其 Pid 文件的路径

编辑 /etc/httpd/httpd.conf,添加如下行即可:

PidFile  “/var/run/httpd.pid”

4、提供 SysV 服务脚本 /etc/rc.d/init.d/httpd,内容如下:

#!/bin/bash

#

# httpd        Startup script for the Apache HTTP Server

#

# chkconfig: – 85 15

# description: Apache is a World Wide Web server.  It is used to serve \

#        HTML files and CGI.

# processname: httpd

# config: /etc/httpd/conf/httpd.conf

# config: /etc/sysconfig/httpd

# pidfile: /var/run/httpd.pid

 

# 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

 

start() {

        echo -n $”Starting $prog: “

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

        RETVAL=$?

        echo

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

        return $RETVAL

}

 

stop() {

  echo -n $”Stopping $prog: “

  killproc -p ${pidfile} -d 10 $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=$?

        echo $”not reloading due to configuration syntax error”

        failure $”not reloading $httpd due to configuration syntax error”

    else

        killproc -p ${pidfile} $httpd -HUP

        RETVAL=$?

    fi

    echo

}

 

# See how we were called.

case “$1” in

  start)

  start

  ;;

  stop)

  stop

  ;;

  status)

        status -p ${pidfile} $httpd

  RETVAL=$?

  ;;

  restart)

  stop

  start

  ;;

  condrestart)

  if [-f ${pidfile} ] ; then

    stop

    start

  fi

  ;;

  reload)

        reload

  ;;

  graceful|help|configtest|fullstatus)

  $apachectl $@

  RETVAL=$?

  ;;

  *)

  echo $”Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}”

  exit 1

esac

 

exit $RETVAL

而后为此脚本赋予执行权限:

# chmod +x /etc/rc.d/init.d/httpd

加入服务列表:

# chkconfig –add httpd

接下来就可以启动服务进行测试了。

#service httpd start

打开浏览器访问 ip 地址即可看到:

CentOS 6.5 安装配置 LAMP

更多详情见请继续阅读下一页的精彩内容 :http://www.linuxidc.com/Linux/2014-07/104373p2.htm

四、安装 xcache,为 php 加速:

1、安装

# tar xf xcache-3.0.3.tar.gz

# cd xcache-3.0.3

# /usr/local/php/bin/phpize

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

# make && make install

安装结束时,会出现类似如下行:

Installing shared extensions:    /usr/local/php/lib/php/extensions/no-debug-zts-20100525/

2、编辑 php.ini,整合 php 和 xcache:

首先将 xcache 提供的样例配置导入 php.ini

# mkdir /etc/php.d

# cp xcache.ini /etc/php.d

说明:xcache.ini 文件在 xcache 的源码目录中。

接下来编辑 /etc/php.d/xcache.ini,找到 extension 开头的行,修改为如下行:

extension = /usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so

3. 测试,此时刷新之前的测试页,可以在其中找到 xcache 选项

CentOS 6.5 安装配置 LAMP

附: 配置 fpm 方式的 php

1、编译安装 php-5.4.19

# tar xf php-5.4.19.tar.bz2

# cd php-5.4.19

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

为 php 提供配置文件:

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

2、配置 php-fpm

为 php-fpm 提供 Sysv init 脚本,并将其添加至服务列表:

# 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

为 php-fpm 提供配置文件:

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

编辑 php-fpm 的配置文件:

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

配置 fpm 的相关选项为你所需要的值,并启用 pid 文件(如下最后一行):

pm.max_children = 50

pm.start_servers = 5

pm.min_spare_servers = 2

pm.max_spare_servers = 8

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

接下来就可以启动 php-fpm 了:

# service php-fpm start

可以使用如下命令来验正(如果此命令输出有中几个 php-fpm 进程就说明启动成功了):

# ps aux | grep php-fpm

效果如下:

CentOS 6.5 安装配置 LAMP

更多 CentOS 相关信息见 CentOS 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=14

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-20发表,共计11580字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中