centos7快速搭建subversion+nginx+php-fpm+mysql

Posted 河狸员

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos7快速搭建subversion+nginx+php-fpm+mysql相关的知识,希望对你有一定的参考价值。

注:#可为注释,这里大部分情况下是linux执行命令的输入!




1、安装svn1.9

#vim /etc/yum.repos.d/wandisco-svn.repo

内容:

[WandiscoSVN]

name=Wandisco SVN Repo

baseurl=http://opensource.wandisco.com/centos/$releasever/svn-1.9/RPMS/$basearch/

enabled=1

gpgcheck=0

#yum clean all

#yum install subversion

创建代码库

#mkdir -p /data/svn

#svnadmin create /data/svn/web

进到 /data/svn/web/conf,修改对应的文件的内容,进行项目权限配置

对/data/svn/web/hooks目录,进行源代码同步到网站的操作

#cp post-commit.tmpl post-commit

主要内容:

export LANG="zh_CN.UTF-8"

REPOS="$1"

REV="$2"

#TXN_NAME="$3"

SVN=/usr/bin/svn

WEB=/var/www/html/my_project

LOG=/var/log/web-svn/auto_svn.log

SVNLOOK=/usr/bin/svnlook

AUTHOR=$($SVNLOOK author -r $REV "$REPOS")

CHANGEDDIRS=$($SVNLOOK dirs-changed $REPOS)

MESSAGE=$($SVNLOOK log -r $REV "$REPOS")

$SVN update $WEB --username myname --password mypassword --non-interactive

#......................

if [ $? == 0 ]

then

echo  "AUTHOR:${AUTHOR},REV:${REV}" >> $LOG

echo  "MESSAGE:$MESSAGE" >> $LOG

echo  "CHANGEDDIRS ${CHANGEDDIRS}" >> $LOG

echo `date` >> $LOG

echo "##############################" >> $LOG

fi

重启svn服务器

#mkdir /var/log/web-svn

#/usr/bin/svnserve -d -r /data/svn

创建网站目录

#mkdir -p  /var/www/html/my_project

初始化网站

#/usr/bin/svn co svn://xxx.xxx.xxx.xx/my_project   /var/www/html/my_project  --username myname --password mypassword --non-interactive


2、安装mysql5.6


centos6:

#yum list installed | grep mysql

#yum -y remove mysql-libs.x86_64

#wget http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm

#rpm -ivh mysql-community-release-el6-5.noarch.rpm

#yum repolist all | grep mysql

#yum install mysql-community-server -y

#chkconfig --list | grep mysqld

#chkconfig mysqld on

#service mysqld start

#mysql -uroot -p 

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '你设置的密码' WITH GRANT OPTION;

mysql> flush privileges;

设置utf-8编码

[mysqld]

character-set-server=utf8 

collation-server=utf8_general_ci 

sql_mode='NO_ENGINE_SUBSTITUTION'

[mysql]

default-character-set = utf8

[mysql.server]

default-character-set = utf8

[mysqld_safe]

default-character-set = utf8

[client]

default-character-set = utf8

# service mysqld restart


centos7:

#rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm

#yum repolist enabled | grep "mysql.*-community.*"

#yum -y install mysql-community-server

#systemctl enable mysqld

#systemctl start mysqld


初始化密码

#mysql_secure_installation

#mysql -uroot -p

在里面进行账号和数据库的创建和更新


3、安装nginx1.12.2

#groupadd www

#useradd -g www -s /sbin/nologin www

#wget http://nginx.org/download/nginx-1.12.2.tar.gz

#tar -zxvf nginx-1.12.2.tar.gz

#yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel

#cd nginx-1.12.2

#./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-config-file-scan-dir=/usr/local/php/etc  --with-pdo-mysql=/usr/bin/mysql --with-openssl --with-pcre-regex --with-kerberos --with-libdir=lib --with-libxml-dir --with-mysqli=shared,mysqlnd --with-pdo-mysql=shared,mysqlnd --with-pdo-sqlite --with-gd --with-iconv --with-zlib --with-xmlrpc --with-xsl --with-pear --with-gettext --with-curl --with-png-dir --with-jpeg-dir --with-freetype-dir --with-fpm-user=nginx --with-fpm-group=nginx --enable-mysqlnd --enable-zip --enable-inline-optimization --enable-shared --enable-libxml --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-mbregex --enable-mbstring --enable-ftp --enable-gd-native-ttf --enable-pcntl --enable-sockets --enable-soap --enable-session --enable-opcache --enable-fpm --enable-maintainer-zts --enable-fileinfo

#make && make install

创建个centos7 的服务

#vim /usr/lib/systemd/system/nginx.service

内容:

[Unit]

Description=The NGINX HTTP and reverse proxy server

After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]

Type=forking

#PIDFile=/usr/local/nginx/nginx.pid

ExecStartPre=/usr/local/nginx/sbin/nginx -t

ExecStart=/usr/local/nginx/sbin/nginx

ExecReload=/usr/local/nginx/sbin/nginx -s reload

ExecStop=/usr/local/nginx/sbin/nginx -s stop

PrivateTmp=true

[Install]

WantedBy=multi-user.target

#systemctl enable nginx.service

#systemctl start nginx.service

#systemctl status nginx.service

#mkdir /var/log/nginx

#chown -R www:www  /var/log/nginx

#chown -R www:www  /usr/local/nginx

#ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx

#nginx -t

#mkdir /usr/local/nginx/conf/vhost

修改 /usr/local/nginx/conf/nginx.conf里面增加一个放网站配置的目录

#vim  /usr/local/nginx/conf/nginx.conf

在底部花括号上面增加语句(底部有nginx.conf配置代码):

include vhost/*.conf;

然后在vhost目录下面创建一个项目的配置文件如:project.conf

内容:

#####################################################

server {

listen       80; #监听80端口,接收http请求

server_name  xxx.xxx.xxx.xxx;

#  server_name  wwww.yourdomain.com;

index  index.php index.html index.htm default.html default.htm default.php;

root /var/www/html/my_project; # 准备存放代码工程的路径

location / {

try_files $uri $uri/ /index.php?$query_string;

index index.php index.html index.htm;

}

location ~ ^(.*)\/\.svn\/

{

return 404;

}

location ~ [^/]\.php(/|$)

{

#  fastcgi_pass   127.0.0.1:9000;

fastcgi_pass    unix:/dev/shm/php-fpm.sock;

fastcgi_index  index.php;

fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

include        fastcgi_params;

}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|woff2|woff|ttf)$

{

expires      30d;

}

location ~ .*\.(js|css)?$

{

expires      12h;

}

}

#####################################################

4、安装php-fpm 7.1

#yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel pcre-devel curl-devel libxslt-devel gcc openssl openssl-devel libmcrypt-devel libicu-devel glibc-headers gcc-c++ git autoconf gcc bison

#wget https://github.com/php/php-src/archive/php-7.1.11.tar.gz

#tar -zxvf php-7.1.11.tar.gz

#cd php-src-php-7.1.11/

#./buildconf --force

#./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-config-file-scan-dir=/usr/local/php/etc --with-openssl --with-pcre-regex --with-kerberos --with-libdir=lib --with-libxml-dir --with-mysqli=shared,mysqlnd --with-pdo-mysql=shared,mysqlnd --with-pdo-sqlite --with-gd --with-iconv --with-zlib --with-xmlrpc --with-xsl --with-pear --with-gettext --with-curl --with-png-dir --with-jpeg-dir --with-freetype-dir --with-fpm-user=nginx --with-fpm-group=nginx --enable-mysqlnd --enable-zip --enable-inline-optimization --enable-shared --enable-libxml --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-mbregex --enable-mbstring --enable-ftp --enable-gd-native-ttf --enable-pcntl --enable-sockets --enable-soap --enable-session --enable-opcache --enable-fpm --enable-maintainer-zts --enable-fileinfo

#make && make install

#cp php.ini-production /usr/local/php/etc/php.ini

修改里面的时候

#vim /usr/local/php/etc/php.ini

找到timezone,修改成:date.timezone = Asia/Shanghai

增加pdo_mysql扩展支持

#vim /usr/local/php/etc/pdo_mysql.ini

增加内容:

extension = pdo_mysql.so


#cp /usr/local/php/sbin/php-fpm /etc/init.d/php-fpm

#chmod a+x /etc/init.d/php-fpm

#ln -s /usr/local/php/bin/php /usr/sbin/php

#ln -s /usr/local/php/bin/phpize /usr/sbin/phpize

#ln -s /usr/local/php/bin/pear /usr/sbin/pear

#ln -s /usr/local/php/bin/pecl /usr/sbin/pecl

#ln -s /usr/local/php/sbin/php-fpm /usr/sbin/php-fpm

#cp /usr/local/php/etc/php-fpm.conf.default  /usr/local/php/etc/php-fpm.conf

#cp /usr/local/php/etc/php-fpm.d/www.conf.default  /usr/local/php/etc/php-fpm.d/www.conf

Nginx 中 fastcgi_pass 监听端口 unix socket,所以php-fpm配置成listen:/dev/shm/php-cgi.sock

路径/dev/shm是个tmpfs,速度比磁盘快得多

#vim /usr/local/php/etc/php-fpm.d/www.conf

找到listen = 127.0.0.1:9000

注释掉这行,然后在下面加多一行:

listen = /dev/shm/php-fpm.sock

修改里面的执行用户为:www

user = www

group = www

#touch /dev/shm/php-fpm.sock

#chown www:www /dev/shm/php-fpm.sock

设置开机启动

#vim /lib/systemd/system/php-fpm.service

输入以下内容

[Unit]

Description=php-fpm

After=network.target

[Service]

Type=forking

ExecStart=/usr/local/php/sbin/php-fpm

PrivateTmp=true

[Install]

WantedBy=multi-user.target

#systemctl enable php-fpm.service

#systemctl start php-fpm.service

#systemctl status php-fpm.service

##systemctl restart nginx.service




nginx.conf:

#################################################################

user www;

worker_processes  2;

error_log  /var/log/nginx/error.log;

#error_log  logs/error.log  notice;

#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {

worker_connections  1024;

}

http {

include       mime.types;

default_type  application/octet-stream;

log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

'$status $body_bytes_sent "$http_referer" '

'"$http_user_agent" "$http_x_forwarded_for"';

access_log  /var/log/nginx/access.log;

sendfile        on;
#tcp_nopush     on;
keepalive_timeout  0;

# keepalive_timeout  65;
client_max_body_size 50m;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;


 tcp_nodelay on;
 fastcgi_connect_timeout 300;
 fastcgi_send_timeout 300;
 fastcgi_read_timeout 300;
 fastcgi_buffer_size 64k;
 fastcgi_buffers 4 64k;
 fastcgi_busy_buffers_size 128k;
 fastcgi_temp_file_write_size 256k;


 gzip  on;
 gzip_disable "msie6";
 gzip_vary on;
 gzip_proxied any;
 gzip_comp_level 6;
 gzip_http_version 1.1;
 gzip_min_length 256;
 gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript application/vnd.ms-fontobject application/x-font-ttf font/opentype image/svg+xml image/x-icon;


server {

#   listen       80;

#   server_name  localhost;

#charset koi8-r;

access_log  /var/log/nginx/host.access.log;

#   location / {

#       root   html;

#       index  index.html index.htm;

#   }

#error_page  404              /404.html;

# redirect server error pages to the static page /50x.html

#

#   error_page   500 502 503 504  /50x.html;

#   location = /50x.html {

#       root   html;

#   }

# proxy the PHP scripts to Apache listening on 127.0.0.1:80

#

#location ~ \.php$ {

#    proxy_pass   http://127.0.0.1;

#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

#

#location ~ \.php$ {

#    root           html;

#    fastcgi_pass   127.0.0.1:9000;

#    fastcgi_index  index.php;

#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

#    include        fastcgi_params;

#}

# deny access to .htaccess files, if Apache's document root

# concurs with nginx's one

#

#location ~ /\.ht {

#    deny  all;

#}

}

# another virtual host using mix of IP-, name-, and port-based configuration

#

#server {

#    listen       8000;

#    listen       somename:8080;

#    server_name  somename  alias  another.alias;

#    location / {

#        root   html;

#        index  index.html index.htm;

#    }

#}

# HTTPS server

#

#server {

#    listen       443 ssl;

#    server_name  localhost;

#    ssl_certificate      cert.pem;

#    ssl_certificate_key  cert.key;

#    ssl_session_cache    shared:SSL:1m;

#    ssl_session_timeout  5m;

#    ssl_ciphers  HIGH:!aNULL:!MD5;

#    ssl_prefer_server_ciphers  on;

#    location / {

#        root   html;

#        index  index.html index.htm;

#    }

#}

include vhost/*.conf;

}

#################################################################













以上是关于centos7快速搭建subversion+nginx+php-fpm+mysql的主要内容,如果未能解决你的问题,请参考以下文章

快速搭建企业subversion

阿里云搭建svn

阿里云ESC搭建SVN服务端

CentOS7搭建配置SVN服务器

Centos7搭建SVN及配置

centos7.x搭建svn server