52AV手機A片王|52AV.ONE

 找回密碼
 立即註冊
快捷導航
  • 我愛av論壇BBS
  • 手機A片
  • 自拍偷拍外流區
  • 貼圖區
  • 52av裸聊室
  • 中文-中國主播
Yahoo!奇摩搜尋
熱搜: av4u論壇
Google搜尋
熱搜: av4u論壇
     
查看: 4254|回復: 0

[nginx|php-fpm] CentOS原始碼安裝搭建LNMP(包括nginx,mysql,php,svn)

[複製鏈接]
發表於 2015-10-31 15:13:09 | 顯示全部樓層 |閱讀模式
參考自 : http://blog.csdn.net/yanzi1225627/article/details/491236593 r, d& B% J0 M8 {# n2 b
) O9 ~' i' l/ ?2 {- N  g/ x! Y

目标:搭建LNMP(Linux + Nginx + MySQL + PHP +SVN),其中svn是用来代替ftp,方便开发中调试同步代码

相关目录:所有软件都安装到/www/目录下,在www目录下新建web文件夹作为网站的根路径,www目录下新建wwwsvn作为svn的仓库地址。/www/software用来放nginx,mysql,php的安装包和源码。nginx运行分组和账户www:www

一,安装前的准备

yum -y install ntp make openssl openssl-devel pcre pcre-devel libpng libpng-devel libjpeg-6b libjpeg-devel-6b freetype freetype-devel gd gd-devel zlib zlib-devel gcc gcc-c++ libXpm libXpm-devel ncurses ncurses-devel libmcrypt libmcrypt-devel libxml2 libxml2-devel imake autoconf automake screen sysstat compat-libstdc++-33 curl curl-devel cmake% f5 }& X- X* `

直接将所有待安装的依赖安装完。

然后下载nginx ,mysql, php的源代码:

可用 google search engine 搜尋最新版本

将这三份tar.gz文件通过scp命令弄到服务器上/www/software目录下。

二,安装nginx

解压缩文件,然后进到nginx-1.8.0里,输入命令:

./configure --user=www --group=www --prefix=/www/nginx5 T/ j  r5 J6 K! `3 e. V8 g

然后make,make install就安装完毕了。

安装完后第一件事,创建www的用户和分组,否则会遇到http://blog.itblood.com/nginx-emerg-getpwnam-www-failed.html 的错误。

执行:

/usr/sbin/groupadd -f www$ w0 Z( J5 b. B0 s$ {0 ^$ }
/usr/sbin/useradd M
-s /sbin/nologin -g www www   //-M 不建立使用者目錄

nginx命令在/www/nginx/sbin/下,拷贝到/etc/init.d/一份,接下来设置开机启动。

chmod 755 /etc/init.d/nginx. p, O, Z3 e, X& X; b
* d' `  ?! w( r/ W" p  h. o
chkconfig --add nginx% Z* X. S) a, Q4 W1 V8 L( P
3 F; {9 Q6 ?* q% t! V4 V3 U
chkconfig nginx on9 j( K# P' m& T  T  y6 z' \9 Y/ e

然后

cd /etc/rc.d/init.d/ 目录下新建nginx,内容如下:

#!/bin/bash
* f2 L: T$ Q8 D# nginx Startup script for the Nginx HTTP Server
0 W( l3 `" A) t0 n# it is v.0.0.2 version.6 A( b! H2 F; T# B1 `/ K  W9 P
# chkconfig: - 85 15
6 {+ N2 y* t* i. H( _4 e# description: Nginx is a high-performance web and proxy server.
9 y: h/ W" Q& L" W# It has a lot of features, but it's not for everyone.
8 A, d& O  S$ }6 y8 u. K$ B# processname: nginx! ]' M* \+ H$ R
# pidfile: /var/run/nginx.pid
) ~& w+ g3 h- U( I2 \# config: /usr/local/nginx/conf/nginx.conf: c" S  R# V$ C( ~* ], l/ f5 Y
nginxd=/www/nginx/sbin/nginx
4 D  B6 f2 v' I8 F% g, v2 Mnginx_config=/www/nginx/conf/nginx.conf/ `7 K% J9 a/ U3 }
nginx_pid=/www/nginx/logs/nginx.pid1 X# A8 C, C: F3 v
RETVAL=0
/ y% I' d3 [7 t1 ~2 Jprog="nginx"
5 {5 V; ~& e" h+ o- s( \# Source function library.
1 V5 ]' C6 c- \" Q% |. /etc/rc.d/init.d/functions  c' q7 O5 x( z% o7 ~; s' ?  M) b
# Source networking configuration.2 i& X& E3 Y; D2 Q' Y& D: J
. /etc/sysconfig/network( A9 v8 s9 T8 U% K4 O$ y3 p' v0 i
# Check that networking is up.
! A& p% K8 ^7 \; F[ ${NETWORKING} = "no" ] && exit 0
: ]0 H) C" o+ L/ }. _3 _[ -x $nginxd ] || exit 0& t, [( U) s$ |
# Start nginx daemons functions.  u# i" v5 Y% O- T- Y* Y
start() {
" Z$ \+ j9 n; n& _( b/ S2 Bif [ -e $nginx_pid ];then
0 n; w  p- U% m& A  techo "nginx already running...."
# }' J, x+ c( T' n" b2 Texit 1% T( S) Z* U, Q. ?
fi3 D4 R( ~) }5 T. O* V
echo -n $"Starting $prog: "
7 |- N- p! y& p$ G% r7 O# x5 m% A" |daemon $nginxd -c ${nginx_config}) o$ F* Y( d; f" A3 c* F" @
RETVAL=$?+ R" s* u9 ?  }
echo
) @# |+ a6 p# O) F6 R  @1 P" A9 H[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx/ p- l! R9 @! E. R5 O
return $RETVAL+ F, \, v5 N* w+ g6 c  Z
}- |% E2 f/ f4 r; D. C
# Stop nginx daemons functions.
1 y! M1 C8 d: Zstop() {
6 m7 M( U3 B# a7 o7 A% y1 ?echo -n $"Stopping $prog: "
# |- F2 a3 R" Y. t- Jkillproc $nginxd
0 D, A% v6 f: @: f$ c% X! pRETVAL=$?
; m% W. c2 d+ a/ H2 Xecho
4 f) l& ?. k% v[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /www/nginx/logs/nginx.pid
: R9 K; M2 d, c3 A: P6 [: ?}& f. D& ?  F  `3 l
reload() {3 x' i- r: h7 _( F6 L8 z; w
echo -n $"Reloading $prog: "
$ ]. k7 q5 s) X#kill -HUP `cat ${nginx_pid}`2 n7 \- ^! m; Z9 r) p0 {5 f
killproc $nginxd -HUP' o* W( `+ p4 t* o; D- S
RETVAL=$?0 r0 Y" B1 u9 h! [- Z1 k1 V9 L
echo
) k, x6 K( V* I}
1 [" q" S! t9 \  Y9 D& h5 r7 m9 s# See how we were called.& s! o7 k* n) l
case "$1" in
- C, R2 }% M$ {" _( Q( cstart)) T0 B& S  R/ O5 `9 \
start
7 b" @. t0 Z" R6 [) M8 W. M;;
  {3 A1 N, y+ h# h1 T; e7 Qstop)
, \; y1 J; Y/ H9 {2 D9 t+ q0 Vstop( k7 {  J0 G8 }! l
;;
5 Z, c# Q2 U5 ]; o- r: Vreload)5 D! v+ ~7 N! j! C; S
reload
" n0 m8 U( M# w- c;;3 h5 c$ _, G( [5 H
restart)2 J. g; J- p% m: \/ b+ v- `) w; @
stop
" y( G7 D% G0 j7 O1 |start* q, s% D/ T" Z# {3 s/ d: G+ R
;;& x, ~: \+ p% m) a( ~/ c  {; h
status)6 o2 R; [! `" \: }
status $prog2 Z0 R% h; D0 y2 }! o
RETVAL=$?
+ A* ^# M9 `* _;;
8 r& H" f* j: o*); E. ^; o  i; N
echo $"Usage: $prog {start|stop|restart|reload|status|help}"# A% D8 K. ?9 n, _7 }6 @0 D/ l
exit 1/ @! V5 g, e$ j9 \' n: s  k, F
esac
4 O8 I# u8 s5 `exit $RETVAL1 [, b' ~  v# ?
" B; a  Q4 R. ~

注意:如果nginx的安装路径不是在/www/nginx下,则适当修改就好。

% c6 P+ D3 j+ b1 Q: Z: n
chmod 775 /etc/rc.d/init.d/nginx #赋予执行权限chkconfig nginx on #设置开机启动/etc/rc.d/init.d/nginx restart 或 service nginx restart至此nginx安装就ok了,但遗留两个问题:
" @& x+ D6 I4 b$ N

1,是更改默认web根目录在/www/web的问题

2,是与php的整合,默认nginx是不认php得

对于1,nginx默认web根目录在 nginx安装路径下的html文件夹,我们把他改到/www/web目录下。

进到/www/nginx/conf目录下,vim nginx.conf,将

0 Q6 E# c' A- H: x+ u1 D$ C0 y
       location / {/ g1 {7 Y1 `( Y8 f8 R
            root   html;
! K7 I) z! \7 \6 U+ `3 J7 _            index  index.php index.html index.htm;
; t; i' x/ x( l3 ?: f        }
9 Y% k+ G) @% y# ]修改为:
8 w2 P. @! j+ Z3 _) Q  M! u- J' u3 @9 L, K2 [3 ^

        location / {

            root   /www/web;

            index  index.html index.php;

        }

注意,增加了对index.php的识别。

3 G  U+ t) h! B$ ?5 ^4 W- H
location ~ \.php$ {
9 P. K6 A. k+ X4 k            root           html;3 L2 N0 ?8 Q% U' I0 R# n4 s. W
            fastcgi_pass   127.0.0.1:9000;9 y* [. ?" r# P: A( C/ B
            fastcgi_index  index.php;
, v% W" \9 ^/ ~0 \: r" G. E+ }8 i' q            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;; m  i$ E+ I, y" `
            include        fastcgi_params;
7 A! h  A, [# F3 E# \        }
4 o) e# H/ `! p8 S/ d5 i修改为:; }* x8 S: U* r/ D, Y0 f  t

) U, ~4 W& w! d8 G) U) J

        location ~ \.php$ {

            root           /www/web;

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;

            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

            #include        fastcgi_params;

            include fastcgi.conf;

       }

然后就ok了。

第二个问题跟php的整合,待安装完毕php后再整。

三,安装MySQL

解压缩并进到源码目录,执行:

8 [. a' ^  A+ U; I$ q

#cmake -DCMAKE_INSTALL_PREFIX=/www/mysql

之后make make install安装。安装完毕后需要做以下几个事:

1,检查/etc/下是否存在my.conf, 如果有的话通过mv命令改名为

my.cnf.backup

ps:此步骤非常重要!!!

2,创建mysql用户和分组

#/usr/sbin/groupadd mysql
" k9 {1 n1 w7 j6 {6 s1 s: L' i5 I! C' J0 N' Q) o* p8 ?
#/usr/sbin/useradd -g mysql mysql 增加mysql用户和分组。) J7 J6 U9 f( j! _

执行

cat /etc/passwd 查看用户列表
/ o7 l6 g* y7 b! U( ^2 Jcat /etc/group  查看用户组列表

chown -R mysql:mysql /www/mysql修改mysql安装目录的权限。* g( t1 B& v! _* P$ d+ d. ~0 R, f

3,进到/www/mysql,创建系统自带的数据库。

scripts/mysql_install_db --basedir=/www/mysql --datadir=/www/mysql/data --user=mysql
$ Z7 L* ^$ z0 e* W& \- h; x8 q

4,添加服务,启动MySQL

cp support-files/mysql.server /etc/init.d/mysql8 Y: z4 |6 ?% z) ^3 s: i
chkconfig mysql on  X  s& s& h0 S, r2 w! R7 w# {+ |
service mysql start  --启动MySQL
( I& Q  g7 U2 i# t* `/ c" G; P

5,设置root密码

为了让任何地方都能用mysql/bin下的命令,vim /etc/prifile

添加:

PATH=/www/mysql/bin: $PATH* c$ \2 U, c# w
export PATH
; @4 [' L8 m+ I

保存后source /etc/profile

执行:

! F! @; O% P1 [4 z' e! Z& m* O
mysql -uroot  mysql> SET PASSWORD = PASSWORD('root');
) I4 T/ \! G7 S* \2 A

- H# I% S4 g0 s, X

设置root用户的密码为root。

6,为了支持远程访问数据库,执行;

! M- m# k: L; }9 ]1 _! m9 T

mysql> grant all on *.* to xroot@"%" identified by "xroot”;

mysql> flush privileges; //更新权限

这样就创建了一个用户名为xroot,密码为xroot的用户,可以远程访问数据库。

四,安装php(php-fpm)

解压并进入源码:

+ B. a; I# P* @. }+ s, t  s/ x

#./configure --prefix=/www/php --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-openssl --with-libxml-dir --with-zlib --enable-mbstring --with-mysql=/www/mysql --with-mysqli=/www/mysql/bin/mysql_config --enable-mysqlnd --with-pdo-mysql=/www/mysql --with-gd --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --with-curl

然后make make install。接着需要做以下事:

1,整合nginx,启动php

进到cd /www/php/etc/ 目录下,拷贝php-fpm.conf.default 为php-fpm.conf。执行/www/php/sbin/php-fpm start 启动php-fpm。

2,配置php.ini

将安装源码里的/www/software/php-5.6.14/php.ini-production 拷贝到php的安装目录的lib文件夹下。

3,如果需要安装curl扩展的话(上面的configure已经带了),进到源码ext/curl目录下,保证电脑上已经安装了curl和curl-devel,然后:

a,/www/php/bin/phpize 以下,为了方便可以把这个目录加到/etc/profile里:

! A" @) P' Q2 O

PATH=/www/php/bin:/www/mysql/bin: $PATH

export PATH

b,./configure --with-curl --with-php-config=/www/php/bin/php-config

之后make make install,curl.so会生成在

/www/php/lib/php/extensions/no-debug-non-zts-20131226目录下,然后编辑php.ini找到extension_dir和extension修改即可。

使用 yum 比較方便:

以下是針對 centOS 6.x/x86_64:

yum install php php-mysql php-fpm php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel

以下是針對 centOS 5.x/i386:

rpm -ivh http://mirror.yandex.ru/epel/5/i386/epel-release-5-4.noarch.rpm; U. h' b. }. l# ~& ]) y2 z) B
& Q' r+ ^" n* G$ N  a
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-5.rpm
) V* \0 d! m% WCreate /etc/yum.repos.d/php-fpm.repo file and add:3 V% W, B" |9 I  }0 O" F" C; u/ n
  1. [nginx]" F+ p$ A' ]5 h" b- E
  2. name=nginx repo
    & Q9 }2 ~1 Q9 b, R6 e7 `  I
  3. baseurl=http://nginx.org/packages/centos/$releasever/$basearch/) V5 Y; B# B( X$ A. q8 w" w4 L3 N
  4. gpgcheck=08 H; F4 ?' [2 x0 I7 k
  5. enabled=1
複製代碼
1 f# q7 z/ n+ o' [' t9 [
yum --enablerepo=remi,remi-test install php-fpm3 }* E5 {; d5 S
! ^" J) g+ }4 S  s  [
! i0 B( @5 v6 y
五,安装svn配置post-commit

此步作用是代替ftp,方便开发人员开发并同步代码。可以直接通过yum安装即可。

# rpm -qa subversion  //检查是否自带了低版本的svn3 n. I' b) H0 B( x. }: ]# ^

#yum remove subversion //卸载低版本的svn: u% f# Q' T* L. e9 E

# yum install httpd httpd-devel subversion mod_dav_svn mod_auth_mysql   //安装svn
2 M/ p% r, R+ G$ Y4 W

通过# svnserve --version验证是否安装成功。接下来就是创建仓库并与web目录同步。

1,mkdir -p /www/wwwsvn  此文件夹就是svn仓库. svnadmin create /www/wwwsvn 创建仓库,执行上述命令后,可以发现里面有conf, db,format,hooks, locks, README.txt等文件,说明一个SVN库已经建立。(ps:此处可以先通过svnserve -d -r /www/svndata 建立svn版本库目录,然后svnadmin在svndata目录下新建仓库)

2,配置用户和密码

在wwwsvn下进到conf文件夹,里面有三个文件:authz  passwd  svnserve.conf均要编辑。

#vim passwd //设置用户和密码

[users]
  Z8 ]3 y  b' ?# ?+ X! b# harry = harryssecret
. u0 k4 i1 k/ Y+ q9 w3 @# sally = sallyssecret
5 O( E7 o9 {5 f7 q% dwangning=wangning- S' b& P8 }( M, p; e  o; r
yanzi=yanzi- }2 Z$ K) R5 b; s

#vim authz  //设置权限


! ?  L+ ]% R6 e3 t) d! i

[/]

wangning = rw

yanzi = rw

# &joe = r

# * =

#vim svnserve.conf

anon-access = none6 Y# N- ~. l' ?  ~! w/ t. V
auth-access = write
0 V* o9 r+ Q, v( |9 r### The password-db option controls the location of the password
& u" W9 W4 ?, m: _### database file.  Unless you specify a path starting with a /,: A$ R# l7 k4 m2 I7 d7 m2 F
### the file's location is relative to the directory containing' W8 @& |1 [' q2 `
### this configuration file.3 `7 q' B4 P  W, W
### If SASL is enabled (see below), this file will NOT be used.
; r! G+ i3 s* W9 d1 y* j### Uncomment the line below to use the default password file.
7 S7 X! B0 U6 i2 l1 Cpassword-db = passwd
6 G# ]& j& T- B2 k0 ^$ T" x### The authz-db option controls the location of the authorization
) ]' ?. z9 B- r% A" Y! D, ]### rules for path-based access control.  Unless you specify a path
5 e! b2 V! W. y" y7 R5 D. R5 W& A### starting with a /, the file's location is relative to the the
* J6 w) c% p. _$ S### directory containing this file.  If you don't specify an7 Z' \1 Z# K; H0 ~; |
### authz-db, no path-based access control is done.
3 p9 X" b3 b/ n% {3 y# O) p### Uncomment the line below to use the default authorization file.
' }1 g& D1 {, {4 B9 u3 Hauthz-db = authz
( \' F; @' C. h### This option specifies the authentication realm of the repository.
9 U! D% f. e$ g; b# f& S' G5 H1 M### If two repositories have the same authentication realm, they should' j( W' ]- L& k, z, H  C  V9 k
### have the same password database, and vice versa.  The default realm1 s  Y0 e/ ~% Z
### is repository's uuid.2 _1 `, V& u; t. Q
realm = My First Repository) h3 r  l6 [% m8 ]  r  z( \

注意:上面这些有效行前面不能有空格。

3,启动及停止svn

#svnserve -d -r /www/wwwwvn   //启动svn
: m5 B8 r' @0 f, f- V: Y

#killall svnserve    //停止
8 h, @: M- C6 S( ~6 w+ r* O

待启动svn后,可以在外面测试了。

svn checkout svn://192.1.15.222 --username xxx% A( @) ^1 F) M, b

4,配置post-commit

经过上述配置后,svn的仓库地址是/www/wwwsvn, 但是web的根目录是/www/web,两者不是一个目录,无法svn push上来就看到作用。

a,首先在server的终端里,#svn co svn://192.1.15.222 /www/web

记得将/www/web目录权限修改为www:www。

chown -R www:www /www/web
# i; Y" `9 E% C

b, # cd /www/wwwsvn/hooks/,然后cp post-commit.tmpl post-commit  

vim post-commit,在里面输入:

- ]9 K. t: H2 I9 X! e  B

export LANG=zh_CN.UTF-8

svn up --username yanzi --password yanzi /www/web/

chown -R www:www /www/web/

然后就一切ok了,在外面svn commit看看web目录里有么有对应文件吧!

ps:

1,svn up后面的名字和密码是之前设的svn用户。

2,上面up就是update的意思,按git的意思来理解,就是有个仓库A,然后新建了个B去跟踪A,每次A有提交的时候,让B也pull一下过来。在svn里是update。

3 , 裝完nginx php-fpm 須將 SElinux 安全政策關閉,否則網頁會出現 "Access denied" :
! `! q3 j1 A+ F* x- }; |' {+ |

#system-config-securitylevel

選擇DISABLE後按OK,必須重開機

% _7 `1 A# n  ]' ?( ^
執行setenforce 0就可以暫時關閉功能,執行setenforce 1就可以暫時打開功能

vi /etc/sysconfig/selinux

SELINUX=enforcing 改成--> SELINUX=disabled


+ k) B' G+ u1 \2 u& L4 j+ L8 L# Rvi /var/log/audit/audit.log (或 tail -f /var/log/audit/audit.log) 查看 SElinux 有何問題
, b6 M! U; a  m8 L; M3 R
回復

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 立即註冊

本版積分規則

本區塊內容依據『電腦網路內容分級處理辦法』為限制級網站,限定年滿18歲以上或達當地國家法定年齡人士方可進入,且願接受本站各項條款,未滿18歲 謝絕進入瀏覽。為防範未滿18歲之未成年網友瀏覽網路上限制級內容的圖文資訊,建議您可進行網路內容分級組織ICRA分級服務的安裝與設定。 (為還給愛護 本站的網友一個純淨的論壇環境,本站設有管理員)

QQ|小黑屋|手機板|52AV手機A片王

GMT+8, 2026-4-30 20:54 , Processed in 0.011782 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

連絡站長.廣告招商

[email protected] | Telegram:@asa00061     since 2015-01

快速回復 返回頂部 返回列表