Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
253 lines (176 sloc) 12.9 KB
<!DOCTYPE html>
<html lang="zh">
<head>
<title>CentOS使用yum安装lamp</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/centosshi-yong-yuman-zhuang-lamp.html" rel="bookmark"
title="Permalink to CentOS使用yum安装lamp">CentOS使用yum安装lamp</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>LAMP</h2>
<div class="highlight"><pre>yum install httpd php php-mysql php-pecl-memcache php-gd php-mbstring php-mcrypt php-cli php-common php-pdo php-pear mysql-server
</pre></div>
<h2>LNMP</h2>
<div class="highlight"><pre># Nginx源的版本比较新,或者用EPEL源里的也可以但版本比较老
rpm -Uvh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
</pre></div>
<h3>安装软件包</h3>
<div class="highlight"><pre>yum install nginx php-fpm php-mysql php-pecl-memcache php-gd php-mbstring php-mcrypt php-cli php-common php-pdo php-pear mysql-server
</pre></div>
<h3>Nginx配置范例</h3>
<div class="highlight"><pre><span class="err">#</span><span class="o">/</span><span class="nt">etc</span><span class="o">/</span><span class="nt">nginx</span><span class="o">/</span><span class="nt">conf</span><span class="nc">.d</span><span class="o">/</span><span class="nt">default</span><span class="nc">.conf</span>
<span class="err">#</span>
<span class="err">#</span> <span class="nt">The</span> <span class="nt">default</span> <span class="nt">server</span>
<span class="err">#</span>
<span class="nt">server</span> <span class="p">{</span>
<span class="n">listen</span> <span class="m">80</span> <span class="n">default_server</span><span class="p">;</span>
<span class="n">server_name</span> <span class="n">_</span><span class="p">;</span>
<span class="m">#charse</span><span class="n">t</span> <span class="n">koi8</span><span class="o">-</span><span class="n">r</span><span class="p">;</span>
<span class="m">#access</span><span class="n">_log</span> <span class="n">logs</span><span class="o">/</span><span class="n">host</span><span class="o">.</span><span class="n">access</span><span class="o">.</span><span class="n">log</span> <span class="n">main</span><span class="p">;</span>
<span class="n">location</span> <span class="o">/</span> <span class="err">{</span>
<span class="n">root</span> <span class="o">/</span><span class="n">usr</span><span class="o">/</span><span class="n">share</span><span class="o">/</span><span class="n">nginx</span><span class="o">/</span><span class="n">html</span><span class="p">;</span>
<span class="n">index</span> <span class="n">index</span><span class="o">.</span><span class="n">html</span> <span class="n">index</span><span class="o">.</span><span class="n">htm</span><span class="p">;</span>
<span class="p">}</span>
<span class="nt">error_page</span> <span class="nt">404</span> <span class="o">/</span><span class="nt">404</span><span class="nc">.html</span><span class="o">;</span>
<span class="nt">location</span> <span class="o">=</span> <span class="o">/</span><span class="nt">404</span><span class="nc">.html</span> <span class="p">{</span>
<span class="n">root</span> <span class="o">/</span><span class="n">usr</span><span class="o">/</span><span class="n">share</span><span class="o">/</span><span class="n">nginx</span><span class="o">/</span><span class="n">html</span><span class="p">;</span>
<span class="p">}</span>
<span class="err">#</span> <span class="nt">redirect</span> <span class="nt">server</span> <span class="nt">error</span> <span class="nt">pages</span> <span class="nt">to</span> <span class="nt">the</span> <span class="nt">static</span> <span class="nt">page</span> <span class="o">/</span><span class="nt">50x</span><span class="nc">.html</span>
<span class="err">#</span>
<span class="nt">error_page</span> <span class="nt">500</span> <span class="nt">502</span> <span class="nt">503</span> <span class="nt">504</span> <span class="o">/</span><span class="nt">50x</span><span class="nc">.html</span><span class="o">;</span>
<span class="nt">location</span> <span class="o">=</span> <span class="o">/</span><span class="nt">50x</span><span class="nc">.html</span> <span class="p">{</span>
<span class="n">root</span> <span class="o">/</span><span class="n">usr</span><span class="o">/</span><span class="n">share</span><span class="o">/</span><span class="n">nginx</span><span class="o">/</span><span class="n">html</span><span class="p">;</span>
<span class="p">}</span>
<span class="err">#</span> <span class="nt">proxy</span> <span class="nt">the</span> <span class="nt">PHP</span> <span class="nt">scripts</span> <span class="nt">to</span> <span class="nt">Apache</span> <span class="nt">listening</span> <span class="nt">on</span> <span class="nt">127</span><span class="nc">.0.0.1</span><span class="nd">:80</span>
<span class="err">#</span>
<span class="nf">#location</span> <span class="o">~</span> <span class="err">\</span><span class="nc">.php</span><span class="o">$</span> <span class="p">{</span>
<span class="err">#</span> <span class="n">proxy_pass</span> <span class="n">http</span><span class="o">://</span><span class="m">127</span><span class="o">.</span><span class="m">0</span><span class="o">.</span><span class="m">0</span><span class="o">.</span><span class="m">1</span><span class="p">;</span>
<span class="err">#</span><span class="p">}</span>
<span class="err">#</span> <span class="nt">pass</span> <span class="nt">the</span> <span class="nt">PHP</span> <span class="nt">scripts</span> <span class="nt">to</span> <span class="nt">FastCGI</span> <span class="nt">server</span> <span class="nt">listening</span> <span class="nt">on</span> <span class="nt">127</span><span class="nc">.0.0.1</span><span class="nd">:9000</span>
<span class="err">#</span>
<span class="nt">location</span> <span class="o">~</span> <span class="err">\</span><span class="nc">.php</span><span class="o">$</span> <span class="p">{</span>
<span class="m">#root</span> <span class="n">html</span><span class="p">;</span>
<span class="n">fastcgi_pass</span> <span class="m">127</span><span class="o">.</span><span class="m">0</span><span class="o">.</span><span class="m">0</span><span class="o">.</span><span class="m">1</span><span class="o">:</span><span class="m">9000</span><span class="p">;</span>
<span class="n">fastcgi_index</span> <span class="n">index</span><span class="o">.</span><span class="n">php</span><span class="p">;</span>
<span class="err">#</span> <span class="err">这行也要修改为实际路径</span>
<span class="n">fastcgi_param</span> <span class="n">SCRIPT_FILENAME</span> <span class="o">/</span><span class="n">usr</span><span class="o">/</span><span class="n">share</span><span class="o">/</span><span class="n">nginx</span><span class="o">/</span><span class="n">html</span><span class="err">$</span><span class="n">fastcgi_script_name</span><span class="p">;</span>
<span class="n">include</span> <span class="n">fastcgi_params</span><span class="p">;</span>
<span class="p">}</span>
<span class="err">#</span> <span class="nt">deny</span> <span class="nt">access</span> <span class="nt">to</span> <span class="nc">.htaccess</span> <span class="nt">files</span><span class="o">,</span> <span class="nt">if</span> <span class="nt">Apache</span><span class="s1">&#39;s document root</span>
<span class="s1"> # concurs with nginx&#39;</span><span class="nt">s</span> <span class="nt">one</span>
<span class="err">#</span>
<span class="nf">#location</span> <span class="o">~</span> <span class="o">/</span><span class="err">\</span><span class="nc">.ht</span> <span class="p">{</span>
<span class="err">#</span> <span class="n">deny</span> <span class="n">all</span><span class="p">;</span>
<span class="err">#</span><span class="p">}</span>
<span class="err">}</span>
</pre></div>
<h3>手动启动服务</h3>
<div class="highlight"><pre>/etc/init.d/nginx start
/etc/init.d/php-fpm start
/etc/init.d/mysqld start
</pre></div>
<h3>开机自启动</h3>
<div class="highlight"><pre>chkconfig nginx on
chkconfig php-fpm on
chkconfig mysqld on
</pre></div>
<h2>开放端口</h2>
<div class="highlight"><pre>/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
/etc/rc.d/init.d/iptables save
</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>