CentOS源码编译安装lnmp

Tue 08 October 2013
By dqw

安装编译环境

yum install gcc gcc-c++ automake autoconf libtool make

nginx

添加用户

/usr/sbin/groupadd nginx
/usr/sbin/useradd -g nginx nginx

下载源码

http://nginx.org/en/download.html

nginx编译

tar xzvf nginx-1.x.tar.gz
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx
make
make install

nginx相关依赖

PCRE

# 或者用对应源码包安装
yum install pcre-devel

zlib

# 或者用对应源码包安装
yum install zlib-devel

启动

/usr/local/nginx/sbin/nginx

服务器启动

拷贝启动脚本到/etc/init.d/nginx

http://wiki.nginx.org/RedHatNginxInitScript

配置服务自启动

chkconfig --add nginx
chkconfig nginx on

mysql

下载预编译包

http://dev.mysql.com/downloads/mysql/

安装

tar zxvf mysql-x.x.x-linux-glibc2.5-x86.tar.gz
mv mysql-x.x.x-linux-glibc2.5-x86 /usr/local/mysql

# 添加用户
/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql

# 建立data目录
mkdir -p /usr/local/mysql/data

# 设置目录权限
chown mysql:mysql /usr/local/mysql

# 安装依赖
yum install libaio

# 初始化数据库
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql

设置my.cnf

#源码包的support-files/my-default.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
server_id = 10
socket = /tmp/mysql.sock
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

启动

/usr/local/mysql/bin/mysqld_safe

自启动

cp support-files/mysql.server  /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on

php

下载源码包

http://cn2.php.net/downloads.php

php编译安装

# 安装依赖  
yum install libxml2-devel
yum install libpng-devel

# 编译
./configure --prefix=/usr/local/php --enable-fpm --with-gd --with-pdo-mysql=/usr/local/mysql/ --with-mysqli=/usr/local/mysql/bin/mysql_config --with-config-file-path=/usr/local/php/etc

php.ini

cp php.ini-development /usr/local/php/etc/php.ini

php-fpm

cp sapi/fpm/init.d.php-fpm  /etc/init.d/php-fpm

# 修改php-fpm内容
prefix=/usr/local/php
exec_prefix=/usr/local/php/bin
php_fpm_BIN=/usr/local/php/sbin//php-fpm
php_fpm_CONF=/usr/local/php/etc/php-fpm.conf
php_fpm_PID=/var/run/php-fpm.pid

chmod +x /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on

apache2

http://php.net/manual/zh/install.unix.apache2.php

添加用户

/usr/sbin/groupadd httpd
/usr/sbin/useradd -g httpd

下载源码

http://www.apache.org

apache编译

./configure --prefix=/usr/local/httpd
make
make install

apache相关依赖

apr

# 或者用对应源码包安装(源里的版本可能太低)
yum install apr-devel

apr-util

# 或者用对应源码包安装(源里的版本可能太低)
yum install apr-util-devel

编译php

./configure --prefix=/usr/local/php --with-apxs2=/usr/local/httpd/bin/apxs --with-gd --with-pdo-mysql=/usr/local/mysql/ --with-mysqli=/usr/local/mysql/bin/mysql_config --with-config-file-path=/usr/local/php/etc

修改httpd.conf

# 添加
<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>

服务器启动

# 拷贝启动脚本到/etc/init.d
chkconfig --add httpd
chkconfig httpd on

# 修改脚本内容
apachectl=/usr/local/httpd/bin/apachectl
httpd=${HTTPD-/usr/local/httpd/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/usr/local/httpd/logs/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}