CentOS 6.5 安装 LAMP
LAMP(Linux, apache, MySQL/MariADB, PHP)是一种常见的网站服务器架构,本文将详细介绍如何在CentOS 6.5上安装和配置LAMP环境。

一、准备工作
1、操作系统版本:CentOS 6.5
2、所需软件包:
Apache: httpd2.4.9
MySQL: mysql5.5.38
PHP: php5.5.13
依赖包:openssl、apr、aprutil、pcre、zlib等

二、安装步骤
1. 更新系统并安装基本依赖包
- sudo yum update y
- sudo yum install y make gcc gccc++ zlibdevel libaio
2. 下载源码包
创建存放目录并下载各个源码包:
- mkdir p /usr/local/src/LAMP
- cd /usr/local/src/LAMP
- wget http://mirror.bit.edu.cn/apache/httpd/httpd2.4.9.tar.gz
- wget https://www.openssl.org/source/openssl1.0.1g.tar.gz
- wget http://apache.fayea.com/apachemirror//apr/apr1.5.1.tar.gz
- wget http://mirrors.cnnic.cn/apache//apr/aprutil1.5.3.tar.gz
- wget http://zlib.net/zlib1.2.8.tar.gz
- wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre8.35.tar.gz
- wget http://cdn.mysql.com/Downloads/MySQL5.5/mysql5.5.38.tar.gz
- wget http://ftp.gnu.org/pub/gnu/ncurses/ncurses5.9.tar.gz
- wget http://www.cmake.org/files/v2.8/cmake2.8.12.2.tar.gz
- wget http://www.perl.org/pub/5.0/perl5.20.0.tar.gz
3. 编译与安装OpenSSL
- tar zxvf openssl1.0.1g.tar.gz
- cd openssl1.0.1g
- ./config prefix=/usr/local/openssl
- make && make install
4. 编译与安装APR和APRUtil
- tar zxvf apr1.5.1.tar.gz
- cd apr1.5.1
- ./configure prefix=/usr/local/apr withaprutil=/usr/local/src/LAMP/aprutil1.5.3 withcrypto=openssl
- make && make install
- cd ..
- tar zxvf aprutil1.5.3.tar.gz
- cd aprutil1.5.3
- ./configure prefix=/usr/local/aprutil withapr=/usr/local/apr withcrypto=openssl
- make && make install
5. 编译与安装PCRE

- tar zxvf pcre8.35.tar.gz
- cd pcre8.35
- ./configure prefix=/usr/local/pcre
- make && make install
6. 编译与安装Zlib
- tar zxvf zlib1.2.8.tar.gz
- cd zlib1.2.8
- ./configure prefix=/usr/local/zlib
- make && make install
7. 编译与安装MySQL
- tar zxvf mysql5.5.38.tar.gz
- cd mysql5.5.38
- cmake . DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
- DDEFAULT_CHARSET=utf8 \
- DDEFAULT_COLLATION=utf8_general_ci \
- DWITH_INNODB_STORAGE_ENGINE=1 \
- DWITH_ARCHIVE_STORAGE_ENGINE=1 \
- DWITH_READLINE=system \
- DENABLED_LOCAL_INFILE=ON \
- DMYSQL_DATADIR=/usr/local/mysql/data \
- DSYSCONFDIR=/etc \
- DPIDFILE=/var/run/mysqld/mysqld.pid \
- DMYSQL_TCP_PORT=3306 \
- DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
- DEXTRA_HEAP_DIR=/usr/local/mysql \
- DOPENSSL=/usr/local/openssl \
- DAPR=/usr/local/apr \
- DAPR_UTIL=/usr/local/aprutil \
- DPLUGCRYPT_LIBS=lpthread \
- DPLUGCRYPT_CFLAGS=I/usr/local/openssl/include \
- DWITH_PERL=perl \
- DWITH_ZLIB=/usr/local/zlib
- make && make install
- cd scripts
- ./mysql_install_db user=mysql basedir=/usr/local/mysql datadir=/usr/local/mysql/data
启动MySQL并设置开机自启:
- /usr/local/mysql/bin/mysqld_safe user=mysql &
- chkconfig add mysqld
- service mysqld start
为root用户设置密码:
- /usr/local/mysql/bin/mysqladmin u root password 'yourpassword'
8. 编译与安装PHP
- tar zxvf perl5.20.0.tar.gz
- cd perl5.20.0
- ./Configure des Dprefix=/usr/local/perl U
- make && make install
- cd ..
- tar zxvf cmake2.8.12.2.tar.gz
- cd cmake2.8.12.2
- ./bootstrap prefix=/usr/local/cmake
- make && make install
- cd ..
- tar zxvf php5.5.13.tar.gz
- cd php5.5.13
- ./configure prefix=/usr/local/php \
- withconfigfilepath=/usr/local/php \
- withapxs2 enableinlineoptimization \
- disableall \
- enablemaintainerzlib \
- withzlib=bundled,/usr \
- enablembstring \
- enablembregex \
- withmhash \
- withopenssl=/usr/local \
- withpcreregex=/usr/local \
- withmysql=shared,/usr/local/mysql \
- withmysqli=shared,/usr/local/mysql \
- withpdomysql=shared,/usr/local/mysql \
- withpear=/usr/local/php \
- withcurl=bundled \
- enableftp \
- withgd \
- withjpegdir \
- withpngdir \
- withfreetypedir \
- withbz2 \
- withgettext \
- enableexif \
- witht1lib=bundled \
- enablesoap \
- enablebcmath \
- enablecalendar \
- enablezip \
- enablesockets \
- enablesysvmsg \
- enablesysvsem \
- enablesysvshm \
- enablepcntl \
- withxmlrpc \
- withiconv=bundled,/usr \
- withmcrypt=shared,/usr/local/libmcrypt \
- withcurl=bundled \
- enableftp \
- withgd \
- withjpegdir \
- withpngdir \
- withfreetypedir \
- withbz2 \
- withgettext \
- enableexif \
- witht1lib=bundled \
- enablesoap \
- enablebcmath \
- enablecalendar \
- enablezip \
- enablesockets \
- enablesysvmsg \
- enablesysvsem \
- enablesysvshm \
- enablepcntl \
- withxmlrpc \
- withiconv=bundled,/usr \
- withmcrypt=shared,/usr/local/libmcrypt \
- withcurl=bundled \
- enableftp \
- withgd \
- withjpegdir \
- withpngdir \
- withfreetypedir \
- withbz2 \
- withgettext \
- enableexif \
- witht1lib=bundled \
- enablesoap \
- enablebcmath \
- enablecalendar \
- enablezip \
- enablesockets \
- enablesysvmsg \
- enablesysvsem \
- enablesysvshm \
- enablepcntl \
- withxmlrpc \
- withiconv=bundled,/usr \
- withmcrypt=shared,/usr/local/libmcrypt \
- withcurl=bundled \
- enableftp \
- withgd \
- withjpegdir \
- withpngdir \
- withfreetypedir \
- withbz2 \
- withgettext \
- enableexif \
- witht1lib=bundled \
- enablesoap \
- enablebcmath \
- enablecalendar \
- enablezip \
- enablesockets \
- enablesysvmsg \
- enablesysvsem \
- enablesysvshm \
- enablepcntl \
- withxmlrpc \
- withiconv=bundled,/usr \
- withmcrypt=shared,/usr/local/libmcrypt \
- withcurl=bundled \
- enableftp \
- withgd \
- withjpegdir \
- withpngdir \
- withfreetypedir \
- withbz2 \
- withgettext \
- enableexif \
- witht1lib=bundled \
- enablesoap \
- enablebcmath \
- enablecalendar \
- enablezip \
- enablesockets \
- enablesysvmsg \
- enablesysvsem \
- enablesysvshm \
- enablepcntl \
- withxmlrpc \
- withiconv=bundled,/usr \
- withmcrypt=shared,/usr/local/libmcrypt \
- withcurl=bundled \
- enableftp \
- withgd \
- withjpegdir \
- withpngdir \
- withfreetypedir \
- withbz2 \
- withgettext \
- enableexif \
- witht1lib=bundled \
- enablesoap \
- enablebcmath \
- enablecalendar \
- enablezip \
- enablesockets \
- enablesysvmsg \
- enablesysvsem \
- enablesysvshm \
- enablepcntl \
- withxmlrpc \
- withiconv=bundled,/usr \
- withmcrypt=shared,/usr/local/libmcrypt \
- withcurl=bundled \
- enableftp \
- withgd \
- withjpegdir \
- withpngdir \
- withfreetypedir \
- withbz2 \
- withgettext \
- enableexif \
- witht1lib=bundled \
- enablesoap \
- enablebcmath \
- enablecalendar \
- enablezip \
- enablesockets \
- enablesysvmsg \
- enablesysvsem \
- enablesysvshm \
- enablepcntl \
- withxmlrpc \
- withiconv=bundled,/usr \
- withmcrypt=shared,/usr/local/libmcrypt \
- withcurl=bundled \
- enableftp \
- withgd \
- withjpegdir \
- withpngdir \
- withfreetypedir \
- withbz2 \
- withgettext \
- enableexif \
- witht1lib=bundled \
- enablesoap \
- enablebcmath \
- enablecalendar \
- enablezip \
- enablesockets \
- enablesysvmsg \
- enablesysvsem \
- enablesysvshm \
- enablepcntl \
- withxmlrpc \
- withiconv=bundled,/usr \
- withmcrypt=shared,/usr/local/libmcrypt \
- withcurl=bundled \
- enableftp \
- withgd \
- withjpegdir \
- withpngdir \
- withfreetypedir \
- withbz2 \
- withgettext \
- enableexif \
- witht1lib=bundled \
- enablesoap \
- enablebcmath \
- enablecalendar \
- enablezip \
- enablesockets \
- enablesysvmsg \
- enablesysvsem \
- enablesysvshm \
- enablepcntl \
- withxmlrpc \
- withiconv=bundled,/usr \
- withmcrypt=shared,/usr/local/libmcrypt \
- withcurl=bundled \
- enableftp \
- withgd \
- withjpegdir \
- withpngdir \
- withfreetypedir \
- withbz2 \
- withgettext \
- enableexif \ og witht1lib=bundled \
- make && make install