Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
365 lines (249 sloc) 10.6 KB
<!DOCTYPE html>
<html lang="zh">
<head>
<title>CentOS源码编译安装lnmp</title>
<meta charset="utf-8" />
<link href="http://dqw.github.io/feeds/all.atom.xml" type="application/atom+xml" rel="alternate" title="DQW's Blog Full Atom Feed" />
<!-- Mobile viewport optimized: j.mp/bplateviewport -->
<meta name="viewport" content="width=device-width,initial-scale=1, maximum-scale=1">
<link rel="stylesheet" type="text/css" href="http://dqw.github.io/theme/gumby.css" />
<link rel="stylesheet" type="text/css" href="http://dqw.github.io/theme/style.css" />
<link rel="stylesheet" type="text/css" href="http://dqw.github.io/theme/pygment.css" />
<script src="http://dqw.github.io/theme/js/libs/modernizr-2.6.2.min.js"></script>
</head>
<body id="index" class="home">
<div class="container">
<div class="row">
<header id="banner" class="body">
<h1><a href="http://dqw.github.io">DQW's Blog <strong>用适合的技术解决实际的问题</strong></a></h1>
</header><!-- /#banner -->
<div id="navigation" class="navbar row">
<a href="#" gumby-trigger="#navigation &gt; ul" class="toggle"><i class="icon-menu"></i></a>
<ul class="columns">
<li><a href="http://dqw.github.io">Home</a></li>
<li><a href="http://dqw.github.io/pages/about.html">About</a></li>
</ul>
</div>
<section id="content" class="body">
<div class="row">
<div class="eleven columns">
<header>
<h2 class="entry-title">
<a href="http://dqw.github.io/centosyuan-ma-bian-yi-an-zhuang-lnmp.html" rel="bookmark"
title="Permalink to CentOS源码编译安装lnmp">CentOS源码编译安装lnmp</a></h2>
</header>
<footer class="post-info">
<abbr class="published" title="2013-10-08T22:47:00+08:00">
Tue 08 October 2013
</abbr>
<address class="vcard author">
By <a class="url fn" href="http://dqw.github.io/author/dqw.html">dqw</a>
</address>
</footer><!-- /.post-info -->
<div class="entry-content">
<h2>安装编译环境</h2>
<div class="highlight"><pre>yum install gcc gcc-c++ automake autoconf libtool make
</pre></div>
<h2>nginx</h2>
<h3>添加用户</h3>
<div class="highlight"><pre>/usr/sbin/groupadd nginx
/usr/sbin/useradd -g nginx nginx
</pre></div>
<h3>下载源码</h3>
<div class="highlight"><pre>http://nginx.org/en/download.html
</pre></div>
<h3>nginx编译</h3>
<div class="highlight"><pre>tar xzvf nginx-1.x.tar.gz
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx
make
make install
</pre></div>
<h3>nginx相关依赖</h3>
<h4>PCRE</h4>
<div class="highlight"><pre># 或者用对应源码包安装
yum install pcre-devel
</pre></div>
<h4>zlib</h4>
<div class="highlight"><pre># 或者用对应源码包安装
yum install zlib-devel
</pre></div>
<h3>启动</h3>
<div class="highlight"><pre>/usr/local/nginx/sbin/nginx
</pre></div>
<h3>服务器启动</h3>
<h4>拷贝启动脚本到/etc/init.d/nginx</h4>
<div class="highlight"><pre>http://wiki.nginx.org/RedHatNginxInitScript
</pre></div>
<h4>配置服务自启动</h4>
<div class="highlight"><pre>chkconfig --add nginx
chkconfig nginx on
</pre></div>
<h2>mysql</h2>
<h3>下载预编译包</h3>
<div class="highlight"><pre>http://dev.mysql.com/downloads/mysql/
</pre></div>
<h3>安装</h3>
<div class="highlight"><pre>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
</pre></div>
<h3>设置my.cnf</h3>
<div class="highlight"><pre>#源码包的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
</pre></div>
<h3>启动</h3>
<div class="highlight"><pre>/usr/local/mysql/bin/mysqld_safe
</pre></div>
<h3>自启动</h3>
<div class="highlight"><pre>cp support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
</pre></div>
<h2>php</h2>
<h3>下载源码包</h3>
<div class="highlight"><pre>http://cn2.php.net/downloads.php
</pre></div>
<h3>php编译安装</h3>
<div class="highlight"><pre># 安装依赖
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
</pre></div>
<h3>php.ini</h3>
<div class="highlight"><pre>cp php.ini-development /usr/local/php/etc/php.ini
</pre></div>
<h3>php-fpm</h3>
<div class="highlight"><pre>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
</pre></div>
<h2>apache2</h2>
<div class="highlight"><pre>http://php.net/manual/zh/install.unix.apache2.php
</pre></div>
<h3>添加用户</h3>
<div class="highlight"><pre>/usr/sbin/groupadd httpd
/usr/sbin/useradd -g httpd
</pre></div>
<h3>下载源码</h3>
<div class="highlight"><pre>http://www.apache.org
</pre></div>
<h3>apache编译</h3>
<div class="highlight"><pre>./configure --prefix=/usr/local/httpd
make
make install
</pre></div>
<h3>apache相关依赖</h3>
<h4>apr</h4>
<div class="highlight"><pre># 或者用对应源码包安装(源里的版本可能太低)
yum install apr-devel
</pre></div>
<h4>apr-util</h4>
<div class="highlight"><pre># 或者用对应源码包安装(源里的版本可能太低)
yum install apr-util-devel
</pre></div>
<h3>编译php</h3>
<div class="highlight"><pre>./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
</pre></div>
<h3>修改httpd.conf</h3>
<div class="highlight"><pre># 添加
<span class="nt">&lt;FilesMatch</span> <span class="err">\.php$</span><span class="nt">&gt;</span>
SetHandler application/x-httpd-php
<span class="nt">&lt;/FilesMatch&gt;</span>
</pre></div>
<h3>服务器启动</h3>
<div class="highlight"><pre># 拷贝启动脚本到/etc/init.d
chkconfig --add httpd
chkconfig httpd on
# 修改脚本内容
apachectl=/usr/local/httpd/bin/apachectl
httpd=<span class="cp">${</span><span class="n">HTTPD</span><span class="o">-/</span><span class="n">usr</span><span class="o">/</span><span class="n">local</span><span class="o">/</span><span class="n">httpd</span><span class="o">/</span><span class="nb">bin</span><span class="o">/</span><span class="n">httpd</span><span class="cp">}</span>
prog=httpd
pidfile=<span class="cp">${</span><span class="n">PIDFILE</span><span class="o">-/</span><span class="n">usr</span><span class="o">/</span><span class="n">local</span><span class="o">/</span><span class="n">httpd</span><span class="o">/</span><span class="n">logs</span><span class="o">/</span><span class="n">httpd</span><span class="o">.</span><span class="n">pid</span><span class="cp">}</span>
lockfile=<span class="cp">${</span><span class="n">LOCKFILE</span><span class="o">-/</span><span class="n">var</span><span class="o">/</span><span class="n">lock</span><span class="o">/</span><span class="n">subsys</span><span class="o">/</span><span class="n">httpd</span><span class="cp">}</span>
</pre></div>
</div><!-- /.entry-content -->
</div><!-- /.eleven.columns -->
<div class="three columns">
<h4>Pages</h4>
<ul>
<li><a href="http://dqw.github.io/pages/about.html">About</a></li>
</ul>
<h4>Categories</h4>
<ul>
<li><a href="http://dqw.github.io/category/apache.html">apache</a></li>
<li><a href="http://dqw.github.io/category/centos.html">centos</a></li>
<li><a href="http://dqw.github.io/category/dokuwiki.html">dokuwiki</a></li>
<li><a href="http://dqw.github.io/category/javascript.html">javascript</a></li>
<li><a href="http://dqw.github.io/category/linux.html">Linux</a></li>
<li><a href="http://dqw.github.io/category/macos.html">macos</a></li>
<li><a href="http://dqw.github.io/category/mysql.html">mysql</a></li>
<li><a href="http://dqw.github.io/category/other.html">other</a></li>
<li><a href="http://dqw.github.io/category/pelican.html">pelican</a></li>
<li><a href="http://dqw.github.io/category/php.html">php</a></li>
<li><a href="http://dqw.github.io/category/xie-yi.html">协议</a></li>
</ul>
<h4>Tags</h4>
<ul>
</ul>
<nav class="widget">
<h4>LINKS</h4>
<ul>
<li><a href="feeds/all.atom.xml" target="_blank">RSS</a></li>
<li><a href="https://github.com/dqw" target="_blank">github</a></li>
<li><a href="http://www.douban.com/people/47947350/" target="_blank">douban</a></li>
<li><a href="http://dqw3721.blog.51cto.com/" target="_blank">以前51cto上的Blog</a></li>
<li><a href="http://dqw3721.cnblogs.com/" target="_blank">以前cnblogs上的Blog</a></li>
<li><a href="http://www.dqw.me/sitemap.xml" target="_blank">sitemap</a></li>
</ul>
</nav>
</div> </div><!-- /.row -->
</section>
</div><!-- /.row -->
</div><!-- /.container -->
<div class="container.nopad bg">
<footer id="credits" class="row">
<div class="seven columns left-center">
<address id="about" class="vcard body">
Proudly powered by <a href="http://getpelican.com/">Pelican</a>,
which takes great advantage of <a href="http://python.org">Python</a>.
<br />
Based on the <a target="_blank" href="http://gumbyframework.com">Gumby Framework</a>
</address>
</div>
<div class="seven columns">
<div class="row">
<ul class="socbtns">
</ul>
</div>
</div>
</footer>
</div>
<script src="http://dqw.github.io/theme/js/libs/jquery-1.9.1.min.js"></script>
<script src="http://dqw.github.io/theme/js/libs/gumby.min.js"></script>
<script src="http://dqw.github.io/theme/js/plugins.js"></script>
</body>
</html>