Heim > php教程 > php手册 > Linux下php+mysql+nginx编译搭建(一)

Linux下php+mysql+nginx编译搭建(一)

WBOY
Freigeben: 2016-06-06 19:58:28
Original
1138 Leute haben es durchsucht

之前一直都是一键搭建的web服务器,但是一键搭建的环境相对来说都是比较老的。如果要用比较新的环境,特别是正式服务器,就必须自己手动编译搭建了(以下搭建基于linux centos6.5 32位服务器)。 1、 nginx 版本:1.5 下载地址: http://nginx.org/download/

之前一直都是一键搭建的web服务器,但是一键搭建的环境相对来说都是比较老的。如果要用比较新的环境,特别是正式服务器,就必须自己手动编译搭建了(以下搭建基于linux centos6.5 32位服务器)。

1、 nginx
版本:1.5
下载地址: http://nginx.org/download/nginx-1.5.2.tar.gz

2、 mysql
版本5.5
下载地址:http://downloads.mysql.com/archives/mysql-5.0/mysql-5.5.30.tar.gz

3、 php
版本5.4
下载地址:http://am1.php.net/get/php-5.4.34.tar.gz/from/this/mirror

一:安装nginx
安装一些依赖包:

<ol><li>
<span>yum </span><span>-</span><span>y install gcc gcc</span><span>-</span><span>c</span><span>++</span><span> gcc</span><span>-</span><span>devel gcc</span><span>-</span><span>c</span><span>++-</span><span>devel ssl ssl</span><span>-</span><span>devel autoconf make aclocal libtool expat</span><span>-</span><span>devel libxml2</span><span>-</span><span>devel openssl openssl</span><span>-</span><span>devel zlib zlib</span><span>-</span><span>devel bzip2 bzip2</span><span>-</span><span>devel gd gd</span><span>-</span><span>devel libmcrypt libmcrypt</span><span>-</span><span>devel libXpm</span><span>-</span><span>devel  curl</span><span>-</span><span>devel libgd</span><span>-</span><span>devel gd</span><span>-</span><span>devel openldap</span><span>-</span><span>devel</span>
</li></ol>
Nach dem Login kopieren

进入一个目录:

<ol><li>
<span>cd </span><span>/</span><span>opt</span><span>/</span>
</li></ol>
Nach dem Login kopieren

下载并解压:

<ol>
<li>
<span>wget http</span><span>:</span><span>//nginx.org/download/nginx-1.5.2.tar.gz</span>
</li>
<li>
<span>tar </span><span>-</span><span>zxf nginx</span><span>-</span><span>1.5</span><span>.</span><span>2.tar</span><span>.</span><span>gz</span>
</li>
<li>
<span>wget http</span><span>:</span><span>//labs.frickle.com/files/ngx_cache_purge-2.1.tar.gz</span>
</li>
<li>
<span>tar </span><span>-</span><span>zxf ngx_cache_purge</span><span>-</span><span>2.1</span><span>.</span><span>tar</span><span>.</span><span>gz</span>
</li>
</ol>
Nach dem Login kopieren

进入目录并编译:

<ol>
<li>
<span>cd nginx</span><span>-</span><span>1.5</span><span>.</span><span>2</span>
</li>
<li>
<span>./</span><span>configure </span><span>--</span><span>prefix</span><span>=</span><span>/usr/</span><span>local</span><span>/</span><span>nginx </span><span>--</span><span>sbin</span><span>-</span><span>path</span><span>=</span><span>/usr/</span><span>local</span><span>/</span><span>nginx</span><span>/</span><span>sbin</span><span>/</span><span>nginx </span><span>--</span><span>conf</span><span>-</span><span>path</span><span>=</span><span>/usr/</span><span>local</span><span>/</span><span>nginx</span><span>/</span><span>conf</span><span>/</span><span>nginx</span><span>.</span><span>conf </span><span>--</span><span>error</span><span>-</span><span>log</span><span>-</span><span>path</span><span>=</span><span>/usr/</span><span>local</span><span>/</span><span>nginx</span><span>/</span><span>log</span><span>/</span><span>error</span><span>.</span><span>log </span><span>--</span><span>http</span><span>-</span><span>log</span><span>-</span><span>path</span><span>=</span><span>/usr/</span><span>local</span><span>/</span><span>nginx</span><span>/</span><span>log</span><span>/</span><span>access</span><span>.</span><span>log </span><span>--</span><span>pid</span><span>-</span><span>path</span><span>=</span><span>/usr/</span><span>local</span><span>/</span><span>nginx</span><span>/</span><span>run</span><span>/</span><span>nginx</span><span>.</span><span>pid    </span><span>--</span><span>user</span><span>=</span><span>www </span><span>--</span><span>group</span><span>=</span><span>www </span><span>--</span><span>with</span><span>-</span><span>http_ssl_module </span><span>--</span><span>with</span><span>-</span><span>http_flv_module </span><span>--</span><span>with</span><span>-</span><span>http_stub_status_module </span><span>--</span><span>with</span><span>-</span><span>http_gzip_static_module </span><span>--</span><span>http</span><span>-</span><span>client</span><span>-</span><span>body</span><span>-</span><span>temp</span><span>-</span><span>path</span><span>=</span><span>/usr/</span><span>local</span><span>/</span><span>nginx</span><span>/</span><span>tmp</span><span>/</span><span>client </span><span>--</span><span>http</span><span>-</span><span>proxy</span><span>-</span><span>temp</span><span>-</span><span>path</span><span>=</span><span>/usr/</span><span>local</span><span>/</span><span>nginx</span><span>/</span><span>tmp</span><span>/</span><span>proxy</span><span>/</span><span>--</span><span>http</span><span>-</span><span>fastcgi</span><span>-</span><span>temp</span><span>-</span><span>path</span><span>=</span><span>/usr/</span><span>local</span><span>/</span><span>nginx</span><span>/</span><span>tmp</span><span>/</span><span>fcgi</span><span>/</span><span>--</span><span>add</span><span>-</span><span>module</span><span>=../</span><span>ngx_cache_purge</span><span>-</span><span>2.1</span><span>--</span><span>with</span><span>-</span><span>pcre</span><span>=../</span><span>pcre</span><span>-</span><span>8.34</span>
</li>
<li>
<span>make  </span><span>&&</span><span> make install</span>
</li>
</ol>
Nach dem Login kopieren

这样就完成了nginx的搭建。
运行:/usr/local/nginx/sbin/nginx
报错:nginx: [emerg] getpwnam("www") failed
在nginx.conf中 把user nobody的注释去掉既可,改成www
再次运行:/usr/local/nginx/sbin/nginx
报错:nginx: [emerg] getpwnam("www") failed in /usr/local/nginx/conf/nginx.conf:1
错误的原因是没有创建www这个用户,应该在服务器系统中添加www用户组和用户www,如下命令:

<ol>
<li>
<span>groupadd </span><span>-</span><span>f www</span>
</li>
<li>
<span>useradd </span><span>-</span><span>g www www</span>
</li>
</ol>
Nach dem Login kopieren

第三次运行:/usr/local/nginx/sbin/nginx
报错:nginx: [emerg] mkdir() "/usr/local/nginx/tmp/client" failed (2: No such file or directory)
执行:mkdir -p /usr/local/nginx/tmp/client
然后localhost访问就可以看到:

Linux下php+mysql+nginx编译搭建(一)

习惯了了/etc/init.d/nginx start?觉得/usr/local/nginx/sbin/nginx 太长?
Vim /etc/init.d/nginx

<ol>
<li><span>#!/bin/bash</span></li>
<li><span>#</span></li>
<li><span># Init file for nginx server daemon</span></li>
<li><span>#</span></li>
<li><span># chkconfig: 234 99 99</span></li>
<li><span># description: nginx server daemon</span></li>
<li><span>#</span></li>
<li><span># source function library</span></li>
<li>
<span>.</span><span>/</span><span>etc</span><span>/</span><span>rc</span><span>.</span><span>d</span><span>/</span><span>init</span><span>.</span><span>d</span><span>/</span><span>functions</span>
</li>
<li><span># pull in sysconfig settings</span></li>
<li>
<span>[</span><span>-</span><span>f </span><span>/</span><span>etc</span><span>/</span><span>sysconfig</span><span>/</span><span>nginx </span><span>]</span><span>&&</span><span>.</span><span>/</span><span>etc</span><span>/</span><span>sysconfig</span><span>/</span><span>nginx</span>
</li>
<li>
<span>RETVAL</span><span>=</span><span>0</span>
</li>
<li>
<span>prog</span><span>=</span><span>"nginx"</span>
</li>
<li>
<span>PAT</span><span>=</span><span>/usr/</span><span>local</span><span>/</span><span>nginx</span>
</li>
<li>
<span>NGINXD</span><span>=</span><span>/usr/</span><span>local</span><span>/</span><span>nginx</span><span>/</span><span>sbin</span><span>/</span><span>nginx</span>
</li>
<li>
<span>PID_FILE</span><span>=</span><span>/usr/</span><span>local</span><span>/</span><span>nginx</span><span>/</span><span>nginx</span><span>.</span><span>pid</span>
</li>
<li>
<span>start</span><span>()</span>
</li>
<li><span>{</span></li>
<li>
<span>echo </span><span>-</span><span>n $</span><span>"Starting $prog: "</span>
</li>
<li>
<span>$NGINXD </span><span>2</span><span>></span><span>/dev/</span><span>null</span><span> $OPTIONS </span><span>&&</span><span> success </span><span>||</span><span> failure</span>
</li>
<li>
<span>RETVAL</span><span>=</span><span>$</span><span>?</span>
</li>
<li>
<span>[</span><span>"$RETVAL"</span><span>=</span><span>0</span><span>]</span><span>&&</span><span> touch </span><span>/</span><span>var</span><span>/</span><span>lock</span><span>/</span><span>subsys</span><span>/</span><span>nginx</span>
</li>
<li><span>echo</span></li>
<li><span>}</span></li>
<li>
<span>stop</span><span>()</span>
</li>
<li><span>{</span></li>
<li>
<span>echo </span><span>-</span><span>n $</span><span>"Shutting down $prog: "</span>
</li>
<li><span>killproc nginx</span></li>
<li>
<span>RETVAL</span><span>=</span><span>$</span><span>?</span>
</li>
<li><span>echo</span></li>
<li>
<span>[</span><span> $RETVAL </span><span>-</span><span>eq </span><span>0</span><span>]</span><span>&&</span><span> rm </span><span>-</span><span>f </span><span>/</span><span>var</span><span>/</span><span>lock</span><span>/</span><span>subsys</span><span>/</span><span>nginx</span>
</li>
<li>
<span>return</span><span> $RETVAL</span>
</li>
<li><span>}</span></li>
<li>
<span>reload</span><span>()</span>
</li>
<li><span>{</span></li>
<li>
<span>echo </span><span>-</span><span>n $</span><span>"Reloading nginx: "</span>
</li>
<li>
<span>killproc nginx </span><span>-</span><span>HUP</span>
</li>
<li>
<span>RETVAL</span><span>=</span><span>$</span><span>?</span>
</li>
<li><span>echo</span></li>
<li>
<span>return</span><span> $RETVAL</span>
</li>
<li><span>}</span></li>
<li>
<span>case</span><span>"$1"</span><span>in</span>
</li>
<li>
<span>"start"</span><span>)</span>
</li>
<li><span>start</span></li>
<li><span>;;</span></li>
<li>
<span>"stop"</span><span>)</span>
</li>
<li><span>stop</span></li>
<li><span>;;</span></li>
<li>
<span>"restart"</span><span>)</span>
</li>
<li><span>stop</span></li>
<li><span>start</span></li>
<li><span>;;</span></li>
<li>
<span>"reload"</span><span>)</span>
</li>
<li><span>reload</span></li>
<li><span>;;</span></li>
<li>
<span>"status"</span><span>)</span>
</li>
<li>
<span>status </span><span>-</span><span>p $PID_FILE nginx</span>
</li>
<li>
<span>RETVAL</span><span>=</span><span>$</span><span>?</span>
</li>
<li><span>;;</span></li>
<li><span>*)</span></li>
<li><span> </span></li>
<li>
<span>echo $</span><span>"Usage: $0 {start|stop|restart|reload|status}"</span>
</li>
<li>
<span>RETVAL</span><span>=</span><span>1</span>
</li>
<li><span>esac</span></li>
<li>
<span>exit</span><span> $RETVAL</span>
</li>
</ol>
Nach dem Login kopieren

保存,添加x权限。
如需开机启动:
chkconfig nginx on


更多请支持:http://www.webyang.net/Html/web/article_127.html

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Empfehlungen
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage