ubuntu 16.04 apache2 git gitweb

前端之家收集整理的这篇文章主要介绍了ubuntu 16.04 apache2 git gitweb前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
安装软件
sudo apt-get install git git-core
sudo apt-get install apache2

sudo apt-get install Git-core openssh-server openssl-client Python-setuptools

#启用相应模块

sudo a2enmod dav_fs
#sudo a2enmod dav

添加git用户用于管理所有代码仓库和用户权限
ivan@ubuntu:~$ sudo useradd -m git
设置git用户密码:
ivan@ubuntu:~$ sudo passwd git
第三步: 安装gitosis
ivan@ubuntu:~$ git clone git://eagain.NET/gitosis.git
ivan@ubuntu:~$ cd gitosis
ivan@ubuntu:~$python setup.py install
第四步: 切换到git用户并创建git仓库目录
ivan@ubuntu:~$ su git
Password:
$ cd ../git
$ ls
examples.desktop
$ pwd
/home/git
$ mkdir sample.git
$ cd sample.git
$ git --bare init
Initialized empty Git repository in /home/git/sample.git/

#设置apache2
sudo htpasswd -c /etc/apache2/dav_git.passwd dav
>New password: 123
>Re-type new password: 123
>Adding password for user dav
配置apache2:/etc/apache2/sites-available/000-default.conf,使用8001端口
<VirtualHost *:8001>
ServerName localhost
ScriptAlias /cgi-bin /var/www/gitweb 这是给/var/www/gitweb取个别名,叫做/cgi-bin
Alias /gitweb /var/www/gitweb 这是给/var/www/gitweb取个别名,叫做/gitweb
<Directory /var/www/gitweb>
Options +ExecCGI
Options +FollowSymLinks
Options +SymLinksIfOwnerMatch
AllowOverride All
order allow,deny
Allow from all
AddHandler cgi-script .cgi .pl .py
DirectoryIndex /gitweb.cgi
</Directory>

</VirtualHost>

Alias /icons/ "/usr/local/www/icons/" Options Indexes MultiViews AllowOverride None Order allow,deny Allow from all
Alias参数用于将URL与服务器文件系统中的真实位置进行直接映射,一般的文档将在DocumentRoot 中进行查询,然而使用Alias定义的路径将直接映射到相应目录下,而不再到DocumentRoot 下面进行查询。因此Alias可以用来映射一些公用文件的路径,例如保存了各种常用图标的icons路径。这样使得除了使用符号连接之外,文档根目录(DocumentRoot)外的目录也可以通过使用了Alias映射,提供给浏览器访问。
定义好映射的路径之后,应该需要使用Directory语句设置访问限制。

ScriptAlias /cgi-bin/ "/usr/local/www/cgi-bin/" AllowOverride None Options None Order allow,deny Allow from all
ScriptAlias也是用于URL路径的映射,但与Alias的不同在于,ScriptAlias是用于映射CGI程序的路径,这个路径下的文件都被定义为CGI程序,通过执行它们来获得结果,而非由服务器直接返回其内容。缺省情况下CGI程序使用cgi-bin目录作为虚拟路径。


sudo vim /etc/apache2/ports.conf

添加监听行:Listen 8001

重启apache server
/etc/init.d/apache2 restart

安装GitWeb
第一步: 安装必备软件模块
ivan@ubuntu:~$ sudo apt-get install gitweb apache2
第二步:修改gitweb.conf文件中$projectroot值
ivan@ubuntu:~$ sudo vim /etc/gitweb.conf(让git与apache2关联的设置)
# path to git projects (<project>.git)
$projectroot = "/home/git";
第三步:修改git仓库文件夹的权限
ivan@ubuntu:~$ sudo chmod 777 -R /home/git

更多细节参考:(https://review.openstack.org/Documentation/config-gitweb.html,主要是让git与apache2建立关系!通过cgi脚本程序)

Table of Contents
Gitweb Integration
Internal/Managed gitweb
External/Unmanaged gitweb
Alternatives to gitweb
SEE ALSO

Gitweb Integration

Gerrit Code Review can manage and generate hyperlinks to gitweb,allowing users to jump from Gerrit content to the same information,but shown by gitweb.

Internal/Managed gitweb

In the internal configuration,Gerrit inspects the request,enforces its project level access controls,and directly executesgitweb.cgiif the user is authorized to view the page.

To enable the internal configuration,setgitweb.cgiwith the path of the installed CGI. This defaults to/usr/lib/cgi-bin/gitweb.cgi,which is a common installation path for the 'gitweb' package on Linux distributions.

git config --file $site_path/etc/gerrit.config gitweb.cgi /usr/lib/cgi-bin/gitweb.cgi
git config --file $site_path/etc/gerrit.config --unset gitweb.url

Alternatively,if Gerrit is served behind reverse proxy,it can generate different URLs for gitweb’s links (they need to be rewritten to<gerrit>/gitweb?argson the web server). This allows for serving gitweb under a different URL than the Gerrit instance. To enable this feature,set both:gitweb.cgiandgitweb.url.

git config --file $site_path/etc/gerrit.config gitweb.cgi /usr/lib/cgi-bin/gitweb.cgi
git config --file $site_path/etc/gerrit.config gitweb.url /pretty/path/to/gitweb

After updating'$site_path'/etc/gerrit.config,the Gerrit server must be restarted and clients must reload the host page to see the change.

Configuration

Most of the gitweb configuration file is handled automatically by Gerrit Code Review. Site specific overrides can be placed in'$site_path'/etc/gitweb_config.perl,as this file is loaded as part of the generated configuration file.

logo and CSS

If the package-manager installed CGI (/usr/lib/cgi-bin/gitweb.cgi) is being used,the stock CSS and logo files will be served from either/usr/share/gitwebor/var/www.

Otherwise,Gerrit expectsgitweb.cssandgit-logo.pngto be found in the same directory as the CGI script itself. This matches with the default source code distribution,and most custom installations.

Access Control

Access controls for internally managed gitweb page views are enforced using the standard project READ +1 permission.

Also,in order for a user to be able to view any gitweb information for a project,the user must be able to read all references (including refs/Meta/config,refs/Meta/dashboards/*,etc.). If you have exclusive read permissions for any references,make sure to include all parties that should be able to read the gitweb info for any of the branches in that project.

External/Unmanaged gitweb

For the external configuration,gitweb runs under the control of an external web server,and Gerrit access controls are not enforced. Gerrit provides configuration parameters for integration with GitWeb.

Linux Installation

Install GitWeb

On Ubuntu:

sudo apt-get install gitweb

With Yum:

$ yum install gitweb
Configure GitWeb

Update/etc/gitweb.conf,add the public GIT repositories:

$projectroot = "/var/www/repo/";

# directory to use for temp files
$git_temp = "/tmp";

# target of the home link on top of all pages
#$home_link = $my_uri || "/";

# html text to include at home page
$home_text = "indextext.html";

# file with project list; by default,simply scan the projectroot dir.
$projects_list = $projectroot;

# stylesheet to use
# I took off the prefix / of the following path to put these files inside gitweb directory directly
$stylesheet = "gitweb.css";

# logo to use
$logo = "git-logo.png";

# the favicon
$favicon = "git-favicon.png";

Configure & Restart Apache Web Server

@H_867_301@Configure Apache

Link gitweb to/var/www/gitweb,check/etc/gitweb.confif unsure of paths:

$ sudo ln -s /usr/share/gitweb /var/www/gitweb(最重要的步骤之一,找到你自己的gitweb静态库安装位置然后链接到web目录这边来!)

Add the gitweb directory to the Apache configuration by creating a "gitweb" file inside the Apache conf.d directory:

$ touch /etc/apache/conf.d/gitweb

Add the following to /etc/apache/conf.d/gitweb:

Alias /gitweb /var/www/gitweb

Options Indexes FollowSymlinks ExecCGI
DirectoryIndex /cgi-bin/gitweb.cgi
AllowOverride None

NOTEThis may have already been added by yum/apt-get. If that’s the case,leave as is.

Restart the Apache Web Server

$ sudo /etc/init.d/apache2 restart

Now you should be able to view your repository projects online:

Windows Installation

Instructions are available for installing the GitWeb module distributed with MsysGit:

If you don’t have Apache installed,you can download the appropriate build for Windows fromapachelounge.org.

After you have installed Apache,you will want to create anew service user accountto use with Apache.

If you’re still having difficulty setting up permissions,you may find this tech note useful for configuring Apache Service to run under another account. You must grant the new account"run as service"permission:

The GitWeb version in msysgit is missing several important and required perl modules,including CGI.pm. The perl included with the msysgit distro 1.7.8 is broken.. Theunicore folder is missing along with utf8_heavy.pl and CGI.pm. You can verify by checking for perl modules. From an msys console,execute the following to check:

$ perl -mCGI -mEncode -mFcntl -mFile::Find -mFile::Basename -e ""

You may encounter the following exception:

$ perl -mCGI -mEncode -mFcntl -mFile::Find -mFile::Basename -e ""
Can't locate CGI.pm in @INC (@INC contains: /usr/lib/perl5/5.8.8/msys
/usr/lib/p erl5/5.8.8 /usr/lib/perl5/site_perl/5.8.8/msys
/usr/lib/perl5/site_perl/5.8.8 /u sr/lib/perl5/site_perl .). BEGIN
Failed--compilation aborted.

If you’re missing CGI.pm,you’ll have to deploy the module to the msys environment: You will have to retrieve them from the 5.8.8 distro on :

File: strawberry-perl-5.8.8.3.zip

contents:bin/lib/site/

copy the contents of lib intomsysgit/lib/perl5/5.8.8and overwrite existing files.

Enable GitWeb Integration

To enable the external gitweb integration,setgitweb.urlwith the URL of your gitweb CGI.

The CGI’s$projectrootshould be the same directory as gerrit.basePath,or a fairly current replica. If a replica is being used,ensure it uses a full mirror,so therefs/changes/*namespace is available.

$ git config -f $site_path/etc/gerrit.config gitweb.cgi $PATH_TO_GITWEB/gitweb.cgi
$ git config -f $site_path/etc/gerrit.config gitweb.url https://gitweb.corporation.com

If you’re not following the traditional {projectName}.git project naming conventions,you will want to customize Gerrit to read them. Add the following:

$ git config -f $site_path/etc/gerrit.config gitweb.type custom
$ git config -f $site_path/etc/gerrit.config gitweb.project ?p=\${project}\;a=summary
$ git config -f $site_path/etc/gerrit.config gitweb.revision ?p=\${project}\;a=commit\;h=\${commit}
$ git config -f $site_path/etc/gerrit.config gitweb.branch ?p=\${project}\;a=shortlog\;h=\${branch}
$ git config -f $site_path/etc/gerrit.config gitweb.roottree ?p=\${project}\;a=tree\;hb=\${commit}
$ git config -f $site_path/etc/gerrit.config gitweb.file ?p=\${project}\;hb=\${commit}\;f=\${file}
$ git config -f $site_path/etc/gerrit.config gitweb.filehistory ?p=\${project}\;a=history\;hb=\${branch}\;f=\${file}

After updating'$site_path'/etc/gerrit.config,the Gerrit server must be restarted and clients must reload the host page to see the change.

Note that when using a custom gitweb configuration,values must be specified for all of theproject,revision,branch,roottree,file,andfilehistorysettings,otherwise the configuration will not be used.

Access Control

Gitweb access controls can be implemented using standard web server access controls. This isn’t typically integrated with Gerrit’s own access controls. Caution must be taken to ensure the controls are consistent if access needs to be restricted.

Caching Gitweb

If your repository set is large and you are expecting a lot of users,you may want to look at the caching forks used by high-traffic sites like kernel.org or repo.or.cz.

Alternatives to gitweb

There are other alternatives to gitweb that can also be used with Gerrit,such as cgit.

cgit can be used by specifyinggitweb.typeto be 'cgit'.

It is also possible to define custom patterns.

SEE ALSO


猜你在找的Ubuntu相关文章