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

在Amazon EC2主机上部署LAMP环境

152次阅读
没有评论

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

LAMP 环境:httpd 2.4.6 + MySQL-5.6.13 + php-5.4.22
系统环境:Amazon Linux (64-bit) (类似于 RHEL6.4_x86_64)

一、编译安装 httpd-2.4.6
1、安装 httpd 所依赖的软件包
$ sudo yum groupinstall Development Libraries Development tools
$ sudo mkdir /usr/src/lamp

<1> 编译安装 apr
$ cd /usr/src/lamp
$ sudo wget http://down1.chinaunix.net/distfiles/apr-1.4.6.tar.bz2
$ sudo tar xf apr-1.4.6.tar.bz2
$ cd apr-1.4.6
$ sudo ./configure –prefix=/usr/local/apr
$ sudo make
$ sudo make install

<2> 编译安装 apr-util

$ cd /usr/src/lamp
$ sudo wget http://apache.spinellicreations.com//apr/apr-util-1.5.2.tar.bz2
$ sudo tar xf apr-util-1.5.2.tar.bz2
$ cd apr-util-1.5.2
$ sudo ./configure –prefix=/usr/local/apr-util –with-apr=/usr/local/apr
$ sudo make
$ sudo make install

<3> Yum 安装 pcre-devel
$ sudo yum -y install pcre-devel

2、编译安装 httpd-2.4.6

$ cd /usr/src/lamp
$ sudo wget http://mirror.cc.columbia.edu/pub/software/apache//httpd/httpd-2.4.6.tar.bz2
$ sudo tar xf httpd-2.4.6.tar.bz2
$ cd httpd-2.4.6
$ sudo ./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=all –enable-mpms-shared=all –with-mpm=event
$ sudo make
$ sudo make install

如编译出现以下错误:

checking for OpenSSL version >= 0.9.7… FAILED
configure: WARNING: OpenSSL version is too old

则需要安装最新的 openssl 和 openssl-devel 的 rpm 包,如默认已安装最新的 openssl 仍编译出错,查看 openssl-devel 是否未装,安装即解决问题
$ sudo yum install openssl-devel.x86_64

3、编辑 httpd 的主配置文件,添加 Pid 文件的路径

$ sudo vim /etc/httpd/httpd.conf
PidFile  “/var/run/httpd.pid”

4、为 httpd 提供 sysv 服务脚本

1 $ sudo vim /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

为此脚本添加执行权限:
$ sudo chmod +x /etc/rc.d/init.d/httpd

添加至服务列表:

$ sudo chkconfig –add httpd

5、修改 PATH 环境变量

$ sudo vim /etc/profile.d/httpd.sh
export PATH=$PATH:/usr/local/apache/bin

6、启动 httpd 服务并测试

$ sudo service httpd start

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

推荐阅读

Ubuntu 下搭建属于自己的 wiki 与论坛 (图) http://www.linuxidc.com/Linux/2008-02/11085.htm

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

Ubuntu 下安装 LAMP 及 phpMyAdmin http://www.linuxidc.com/Linux/2012-09/71192.htm

Ubuntu 12.04 下 LAMP 安装配置 http://www.linuxidc.com/Linux/2012-05/61079.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

二、安装 MySQL-5.6.13(通用二进制)
1、新建 mysql 用户

$ sudo groupadd -r mysql
$ sudo useradd -g mysql -r -s /sbin/nologin -M -d /mydata/data mysql
$ sudo chown -R mysql:mysql /mydata/data
$ sudo mkdir /mydata/data -p
$ sudo chown -R mysql:mysql /mydata/data

2、安装并初始化 mysql-5.6.13

$ cd /usr/src/lamp
$ sudo wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.13-linux-glibc2.5-x86_64.tar.gz
$ sudo tar xf mysql-5.6.13-linux-glibc2.5-x86_64.tar.gz -C /usr/local
$ cd /usr/local/
$ sudo ln -sv mysql-5.6.13-linux-glibc2.5-x86_64 mysql
$ cd mysql

$ sudo chown -R mysql:mysql .
$ sudo scripts/mysql_install_db –user=mysql –datadir=/mydata/data
$ sudo chown -R root .

3、为 mysql 提供主配置文件并编辑

$ cd /usr/local/mysql
$ sudo cp support-files/my-default.cnf /etc/my.cnf

$ sudo vim /etc/my.cnf
datadir=/mydata/data
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
thread_concurrency = 2
innodb_file_per_table = 1

4、为 mysql 提供 sysv 服务脚本

$ cd /usr/local/mysql
$ sudo cp support-files/mysql.server /etc/rc.d/init.d/mysqld

添加执行权限:

$ sudo chmod +x /etc/rc.d/init.d/mysqld

添加至服务列表:

$ sudo chkconfig –add mysqld
$ sudo chkconfig mysqld on

5、编辑 man 配置文件,添加 mysql 的 man 文件路径

$ sudo vim /etc/man.config
MANPATH  /usr/local/mysql/man

6、将 mysql 的头文件输出至系统

$ sudo ln -sv /usr/local/mysql/include /usr/include/mysql

7、将 mysql 的库文件输出至系统库并重新载入

$ sudo echo ‘/usr/local/mysql/lib’ > /etc/ld.so.conf.d/mysql.conf
$ sudo ldconfig

8、修改 PATH 环境变量

$ sudo vim /etc/profile.d/mysqld.sh
export PATH=$PATH:/usr/local/mysql/bin

9、启动 mysql 服务并测试

$ sudo service mysqld start

LAMP 环境:httpd 2.4.6 + MySQL-5.6.13 + php-5.4.22
系统环境:Amazon Linux (64-bit) (类似于 RHEL6.4_x86_64)

一、编译安装 httpd-2.4.6
1、安装 httpd 所依赖的软件包
$ sudo yum groupinstall Development Libraries Development tools
$ sudo mkdir /usr/src/lamp

<1> 编译安装 apr
$ cd /usr/src/lamp
$ sudo wget http://down1.chinaunix.net/distfiles/apr-1.4.6.tar.bz2
$ sudo tar xf apr-1.4.6.tar.bz2
$ cd apr-1.4.6
$ sudo ./configure –prefix=/usr/local/apr
$ sudo make
$ sudo make install

<2> 编译安装 apr-util

$ cd /usr/src/lamp
$ sudo wget http://apache.spinellicreations.com//apr/apr-util-1.5.2.tar.bz2
$ sudo tar xf apr-util-1.5.2.tar.bz2
$ cd apr-util-1.5.2
$ sudo ./configure –prefix=/usr/local/apr-util –with-apr=/usr/local/apr
$ sudo make
$ sudo make install

<3> Yum 安装 pcre-devel
$ sudo yum -y install pcre-devel

2、编译安装 httpd-2.4.6

$ cd /usr/src/lamp
$ sudo wget http://mirror.cc.columbia.edu/pub/software/apache//httpd/httpd-2.4.6.tar.bz2
$ sudo tar xf httpd-2.4.6.tar.bz2
$ cd httpd-2.4.6
$ sudo ./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=all –enable-mpms-shared=all –with-mpm=event
$ sudo make
$ sudo make install

如编译出现以下错误:

checking for OpenSSL version >= 0.9.7… FAILED
configure: WARNING: OpenSSL version is too old

则需要安装最新的 openssl 和 openssl-devel 的 rpm 包,如默认已安装最新的 openssl 仍编译出错,查看 openssl-devel 是否未装,安装即解决问题
$ sudo yum install openssl-devel.x86_64

3、编辑 httpd 的主配置文件,添加 Pid 文件的路径

$ sudo vim /etc/httpd/httpd.conf
PidFile  “/var/run/httpd.pid”

4、为 httpd 提供 sysv 服务脚本

1 $ sudo vim /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

为此脚本添加执行权限:
$ sudo chmod +x /etc/rc.d/init.d/httpd

添加至服务列表:

$ sudo chkconfig –add httpd

5、修改 PATH 环境变量

$ sudo vim /etc/profile.d/httpd.sh
export PATH=$PATH:/usr/local/apache/bin

6、启动 httpd 服务并测试

$ sudo service httpd start

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

推荐阅读

Ubuntu 下搭建属于自己的 wiki 与论坛 (图) http://www.linuxidc.com/Linux/2008-02/11085.htm

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

Ubuntu 下安装 LAMP 及 phpMyAdmin http://www.linuxidc.com/Linux/2012-09/71192.htm

Ubuntu 12.04 下 LAMP 安装配置 http://www.linuxidc.com/Linux/2012-05/61079.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

三、编译安装 php-5.4.22
1、安装 PHP 所依赖的软件包
<1> RPM 安装 mcrypt
$ cd /usr/src/lamp
$ sudo wget ftp://ftp.muug.mb.ca/mirror/Fedora/epel/beta/6/x86_64/libmcrypt-2.5.8-9.el6.x86_64.rpm
$ sudo wget http://www.gymglish.com/opensource/rpms/CentOS6-rpms/libmcrypt-devel-2.5.8-9.el6.x86_64.rpm
$ sudo rpm -ivh lib*

<2> Yum 安装 libxml 和 bzip2 的 devel 包
$ sudo yum install libxml2-devel.x86_64
$ sudo yum install bzip2-devel.x86_64

2、编译安装 php-5.4.22

$ cd /usr/src/lamp
$ sudo wget http://au1.php.net/distributions/php-5.4.22.tar.bz2
$ sudo tar xf php-5.4.22.tar.bz2
$ cd php-5.4.22
$ sudo ./configure –prefix=/usr/local/php –with-MySQL=mysqlnd –with-openssl –with-pdo-mysql=mysqlnd –with-mysqli=mysqlnd –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
$ sudo make
$ sudo make install

为 php 提供配置文件:

$ sudo cp php.ini-production /etc/php.ini

3、编辑 httpd 配置文件,使其支持 php 及默认主页

$ sudo vim /etc/httpd/httpd.conf

# 添加以下内容:
AddType application/x-httpd-php  .php
AddType application/x-httpd-php-source  .phps
# 修改以下内容:
DirectoryIndex  index.php  index.html

4、编辑 httpd 配置文件,新建虚拟主机

$ sudo vim /etc/httpd/httpd.conf
Include /etc/httpd/extra/vhosts.conf

1234567891011 $ sudo vim /etc/httpd/extra/vhosts.conf
<VirtualHost *:80>
  DocumentRoot “/mydata/web”
  ServerName cominggo.com
  ServerAlias www.cominggo.com
  <Directory “/mydata/web”>
    Options none
    AllowOverride none
    Require all granted
  </Directory>
</VirtualHost>

5、重启 httpd 服务并测试

$ sudo servcie httpd configtest
$ sudo service httpd restart

四、安装 PHP 加速器 XCache(可选)
1、编译安装 xcache-3.0.4

$ cd /usr/src/lamp
$ sudo wget http://xcache.lighttpd.net/pub/Releases/3.0.4/xcache-3.0.4.tar.gz
$ sudo tar xf xcache-3.0.4.tar.gz
$ cd xcache-3.0.4
$ /usr/local/php/bin/phpize
$ sudo /usr/local/php/bin/phpize
$ sudo ./configure –enable-xcache –with-php-config=/usr/local/php/bin/php-config
$ sudo make
$ sudo make install
# 安装结果如下:
Installing shared extensions:    /usr/local/php/lib/php/extensions/no-debug-zts-20100525/

2、编辑 xcache 配置文件,整合 PHP 和 XCache

$ sudo mkdir /etc/php.d
$ sudo cp xcache.ini /etc/php.d/

$ sudo vim /etc/php.d/xcache.ini
# 修改以下内容:
extension = /usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so

注:xcache 自 3.0 版本开始不再支持使用 zend_extension 加载 xcache

3、重启 httpd 服务并测试

$ sudo service httpd restart

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