在Ubuntu安裝LXR

安裝Ubuntu

apache 2.4

mysql-sever

libapache2-mod-perl2

perl

(1)啟動WebServer

#sudo apt install apache2

#vi /etc/httpd/conf/httpd.conf

#sudo systemctl start apache2

(2)安裝mysql

#udo apt install mysql-server

#sudo systemctl start mysql

#sudo mysql_secure_installation //設定root密碼

(3)安裝所需要的套件與perl相關套件

#sudo apt install ctags

#sudo apt install perl //通常安裝系統時會一起已安裝

#sudo apt install build-essential

#sudo cpan App::cpanminus

#sudo cpan File::MMagic

#sudo apt install libapache2-mod-perl2

#sudo apt install libdbi-perl

#sudo apt install libdbd-mysql-perl

(4)安裝編譯環境

#sudo apt install gcc

#sudo apt install flex

(5)安裝glimpse與swish-e

#sudo apt install glimpse

#sudo apt install swish-e

(6)設定LXR

#cp lxr-2.0.3.tgz /var/www/html

#cd /var/www/html

#tar -zxvf lxr-2.0.3.tgz

#mv lxr-2.0.3 lxr

#./scripts/configure-lxr.pl -vv

[root@localhost lxr]# ./scripts/configure-lxr.pl -vv

Configure for single/multiple trees? [S/m] >

Do you intend to add other trees later? [yes/NO] >

Server type? [dedicated/SHARED] >

--- Host name or IP? [//localhost] >

--- Alias name or IP? > //192.168.1.7

--- Alias name or IP? >

URL section name for LXR in your server? [/lxr] > 一台主機有需多不同的lxr,修改成lxr原始碼所對應的資料夾,例如:lxr2、lxr3、lxr4

Database engine? [MYSQL/oracle/postgres/sqlite] >

--- Directory for glimpse databases? > /var/www/html/glimpse

Is your Apache version 2.4 or higher? [YES/no] >

--- Use 'buttons-and-menus' instead of 'link' interface? [YES/no] >

--- Caption in page header? (e.g. Project XYZZY displayed by LXR) > LXR

Do you need a specific encoding for this tree ? [yes/NO] >

How is your tree stored? [FILES/cvs/git/svn/hg/bk] >

--- Source directory? (e.g. /home/myself/project-tree) > /var/www/html

Name to display for the path root? (e.g. Project or $v for version) [$v] >

Label for version selection menu? [Version] >

Version enumeration method? [LIST/file/function] >

--- Version name? > slxr

--- Version name? (hit return to stop) >

--- Default displayed version is first in 'range'? [YES/no] >

--- Directory to ignore, e.g. CVSROOT or CVS? (hit return to stop) >

--- Include directory, e.g. /include? (hit return to stop) >

--- Database name? > lxr

--- DB user name? [lxr] >

--- DB password? [lxrpw] > mysql的使用者lxr密碼

--- DB table prefix? [lxr_] >

(7)執行「./custom.d/initdb.sh」用於 建立資料庫與新增資料庫使用者

若無法登入,請重新執行./scripts/configure-lxr.pl -vv,輸入正確mysql的使用者lxr密碼,重新產生initdb.sh,再執行./custom.d/initdb.sh

(8)拷貝「lxr.conf」到上一層目錄

cp ./custom.d/lxr.conf /var/www/html/lxr

(9)使用ctags與glimpse產生索引

在 /var/www/html 資料夾下,將要進行顯示的程式碼放置於slxr資料夾下

#./genxref --checkonly

#./genxref --url=http://192.168.1.7/lxr --versions=slxr

http://192.168.1.7/lxr為網址需要修改,因為設定為SHARED,可以有多目錄

slxr為Version Name,執行「./genxref --url=http://192.168.1.7/lxr --versions=slxr」建立索引

以下為建立索引值螢幕顯示的畫面

This is glimpseindex version 4.18.5, 2006.

Indexing "/var/www/html/slxr" ...

Size of files being indexed = 1115614 B, Total #of files = 110

Index-directory: "/var/www/html/glimpse/lxr/slxr"

Glimpse-files created here:

-rw-r--r--. 1 root root 4785 2015-05-23 08:55 .glimpse_filenames

-rw-r--r--. 1 root root 440 2015-05-23 08:55 .glimpse_filenames_index

-rw-r--r--. 1 root root 0 2015-05-23 08:55 .glimpse_filetimes

-rw-------. 1 root root 102620 2015-05-23 08:55 .glimpse_index

-rw-r--r--. 1 root root 116 2015-05-23 08:55 .glimpse_messages

-rw-------. 1 root root 46058 2015-05-23 08:55 .glimpse_partitions

-rw-r--r--. 1 root root 396 2015-05-23 08:55 .glimpse_statistics

-rw-r--r--. 1 root root 262144 2015-05-23 08:55 .glimpse_turbo

*** slxr /custom.d/

--- slxr apache2-require.pl 1432299033-379 1 :: 0

--- slxr hg-lxr-ext.py 1432299033-2413 2 :: 8

--- slxr initdb.sh 1432299033-7142 3 :: 0

--- slxr lxr.conf 1432299033-6808 4 :: 0

--- slxr lxr.ctxt 1432299033-554 5 :: 0

*** slxr /lib/LXR/Files/

--- slxr BK.pm 1432299033-8306 6 :: 20

--- slxr CVS.pm 1432299033-23529 7 :: 20

--- slxr GIT.pm 1432299033-10286 8 :: 16

--- slxr Mercurial.pm 1432299033-9794 9 :: 16

--- slxr Plain.pm 1432299033-5227 10 :: 15

--- slxr Subversion.pm 1432299033-9874 11 :: 18

*** slxr /lib/LXR/Index/

--- slxr Mysql.pm 1432299033-5982 12 :: 4

--- slxr Oracle.pm 1432299033-2296 13 :: 2

--- slxr Postgres.pm 1432299033-6994 14 :: 4

--- slxr SQLite.pm 1432299033-4056 15 :: 4

...

(10)設定apache

#sudo vi /etc/apache2/site-available/000-default.conf

將apache-lxrserver.conf整合到000-default.conf,如下。

<VirtualHost *:8000>

#ServerName www.example.com

ServerAdmin webmaster@localhost

DocumentRoot /var/www/html

ErrorLog ${APACHE_LOG_DIR}/error.log

CustomLog ${APACHE_LOG_DIR}/access.log combined

<IfDefine MODPERL2>

PerlSwitches -T

</IfDefine>

<IfDefine !MODPERL2>

PerlTaintCheck On

</IfDefine>



<IfModule mod_version.c>

<IfDefine MODPERL2>

# ----------------> absolute path to the LXR root directory

PerlPostConfigRequire /var/www/html/lxr/custom.d/apache2-require.pl

</IfDefine>

<IfDefine !MODPERL2>

# ----------------> absolute path to the LXR root directory

PerlRequire /var/www/html/lxr/custom.d/apache2-require.pl

</IfDefine>

</IfModule>

<Directory "/var/www/html">

Options FollowSymLinks Indexes ExecCGI

AllowOverride AuthConfig FileInfo Limit Options

Require all granted

AddHandler cgi-script .cgi .pl

</Directory>

<Directory "/var/www/html/lxr">

Options FollowSymLinks Indexes ExecCGI

AllowOverride AuthConfig FileInfo Limit Options

Require all granted

#AddHandler cgi-script .cgi .pl

</Directory>

</VirtualHost>


啟動site設定,與重新啟動網頁伺服器apache

#a2ensite 001-default

#systemctl restart apache2

(11)使用瀏覽器瀏覽http://192.168.1.7/lxr/source結果如下。

(12)使用LXR一個建立多個tree

首先執行「scripts/configure-lxr.pl -vv」

# ./scripts/configure-lxr.pl -vv

*** LXR configurator (version: 1.15) ***

LXR root directory is /var/www/html/lxr

Configuration will be stored in custom.d/

Configure for single/multiple trees? [S/m] > m

*** LXR web server configuration ***

Many different configurations are possible, they are related to the way

LXR service is accessed, i.e. to the structure of the URL.

Refer to the User's Manual for a description of the variants.

LXR can be located at the server-root (so called dedicated)

or lower in the server hierarchy (shared because there are

usually other pages or sections).

Server type? [dedicated/SHARED] >

...

Tree designation? [ARGUMENT

/section name

/prefix in host

/hostname

/embedded in section] >

The computer hosting the server is described by an URL.

The form is scheme://host_name:port

where:

- scheme is either http or https (http: can be omitted),

- host_name can be given as an IP address such as 123.45.67.89

or a domain name like localhost or lxr.url.example,

- port may be omitted if standard for the scheme.

--- Host name or IP? [//localhost] >

--- Alias name or IP? > //xxx.xxx.xxx.xxx

--- Alias name or IP? >

URL section name for LXR in your server? [/lxr] >

Will it be shared by all trees? [YES/no] >

*** LXR database configuration ***

....

Database engine? [MYSQL/oracle/postgres/sqlite] >

The safest option is to create one database per tree.

You can however create a single database for all your trees with a specific set of

tables for each tree (though this is not recommended).

How do you setup the databases? [PER TREE/global] >

All databases can be accessed with the same username and

can also be described under the same names.

Will you share database characteristics? [YES/no] >

Will you use the same username and password for all DBs? [YES/no] >

--- DB user name? [lxr] >

--- DB password ? [lxrpw] >

Will you give the same prefix to all tables? [YES/no] >

--- Common table prefix? [lxr_] >

--- Directory for glimpse databases? > /var/www/html/glimpse

--- Directory for swish-e databases? > /var/www/html/swish-e

REMINDER: after this configuration step, open lxr.conf

and comment out one of 'glimpsebin' or 'swishbin'.

Is your Apache version 2.4 or higher? [YES/no] >

file .htaccess written into LXR root directory

file apache2-require.pl written into configuration directory

file apache-lxrserver.conf written into configuration directory

file lighttpd-lxrserver.conf written into configuration directory

file nginx-lxrserver.conf written into configuration directory

file thttpd-lxrserver.conf written into configuration directory

Mercurial support files written into configuration directory

*** LXR master configuration file setup ***

Global section part

*** Configuring auxiliary tool paths

*** Host name previously defined as http://localhost

*** Configuring HTML parameters

*** 'Buttons-and-menus' interface is recommended for the kernel

*** to avoid screen cluttering.

--- Use 'buttons-and-menus' instead of 'link' interface? [YES/no] >

...

*** You previously defined the virtual root as /lxr

--- Caption in page header? (e.g. Project XYZZY displayed by LXR) > OnlineJudge displayed by LXR

Do you want a speed switch button for this tree ? [YES/no] >

--- Short title for button? (e.g. XYZZY) >

No default choice, try again...

--- Short title for button? (e.g. XYZZY) > OnlineJudge

--- Tree identification in URL? (e.g. the-tree) > oj

Do you need a specific encoding for this tree ? [yes/NO] >

*** Describing tree location

How is your tree stored? [FILES/cvs/git/svn/hg/bk] >

*** A source directory contains one sub-directory for every version.

--- Source directory? (e.g. /home/myself/project-tree) > /var/www/html

Name to display for the path root? (e.g. Project or $v for version) [$v] >

*** Enumerating versions

Label for version selection menu? [Version] >

*** Versions can be explicitly enumerated, be read from a file or computed

*** by a function. The latter case is recommended for VCS-stored trees.

Version enumeration method? [LIST/file/function] >

--- Version name? > oj-backend

--- Version name? (hit return to stop) > JudgeServer

--- Version name? (hit return to stop) >

*** By default, first version in list is displayed. You may also indicate

*** a prefered version.

--- Default displayed version is first in 'range'? [YES/no] >

*** Setting directory lists

*** Some directories may contain non-public project data (binaries,

*** compilers caches, SCM control data, ...). They can be hidden from LXR.

--- Directory to ignore, e.g. CVSROOT or CVS? (hit return to stop) >

*** If your source code uses "include" statements (#include, require, ...)

*** LXR needs hints to resolve the destination file.

--- Include directory, e.g. /include? (hit return to stop) >

*** Configuring data storage

--- Database name? > oj

Do you want to override the global 'lxr' user name? [yes/NO] >

Do you want to override the global 'lxr_' table prefix? [yes/NO] >

*** Configure another tree? [YES/no] >

*** Configuring LXR server parameters

*** The virtual root is the fixed URL part after the hostname.

*** You previously defined the virtual root as /lxr

--- Caption in page header? (e.g. Project XYZZY displayed by LXR) > LXR

Do you want a speed switch button for this tree ? [YES/no] >

--- Short title for button? (e.g. XYZZY) > LXR

--- Tree identification in URL? (e.g. the-tree) > lxr

Do you need a specific encoding for this tree ? [yes/NO] >

*** Describing tree location

How is your tree stored? [FILES/cvs/git/svn/hg/bk] >

*** A source directory contains one sub-directory for every version.

--- Source directory? (e.g. /home/myself/project-tree) > /var/www/html

Name to display for the path root? (e.g. Project or $v for version) [$v] >

*** Enumerating versions

Label for version selection menu? [Version] >

*** Versions can be explicitly enumerated, be read from a file or computed

*** by a function. The latter case is recommended for VCS-stored trees.

Version enumeration method? [LIST/file/function] >

--- Version name? > slxr

--- Version name? (hit return to stop) >

*** By default, first version in list is displayed. You may also indicate

*** a prefered version.

--- Default displayed version is first in 'range'? [YES/no] >

*** Setting directory lists

*** Some directories may contain non-public project data (binaries,

*** compilers caches, SCM control data, ...). They can be hidden from LXR.

--- Directory to ignore, e.g. CVSROOT or CVS? (hit return to stop) >

*** If your source code uses "include" statements (#include, require, ...)

*** LXR needs hints to resolve the destination file.

--- Include directory, e.g. /include? (hit return to stop) >

*** Configuring data storage

--- Database name? > lxr

Do you want to override the global 'lxr' user name? [yes/NO] >

Do you want to override the global 'lxr_' table prefix? [yes/NO] >

*** Configure another tree? [YES/no] > no

執行結束產生/custom.d/initdb.sh與/custom.d/lxr.conf

(13)執行initdb.sh產生資料庫與空白資料表

(/var/www/html/lxr)#./custom.d/initdb.sh

(14)移動lxr.conf到上一層資料夾,修改lxr.conf

(/var/www/html/lxr)#mv ./custom.d/lxr.conf ./

(/var/www/html/lxr)#vi ./lxr.conf

去除

#, 'swishbin' => '/usr/bin/swish-e'

#, 'swishdirbase' => '/var/www/html/swish-e'

(15)在/var/www/html資料夾在準備oj-backend、JudgeServer與slxr三個放有程式碼的資料夾。執行「./genxref --allurl」就可以產生兩個原始碼樹,第一個樹有oj-backend與JudgeServer,第二個樹有LXR原始碼。

(/var/www/html/lxr)#./genxref --allurl

(16)瀏覽器瀏覽 http://xxx:8000/lxr/source出現兩個樹的LXR,如下圖。

相關網站

https://sourceforge.net/projects/lxr/files/stable/

https://lxr.sourceforge.io/zh/1-0-InstallSteps/1-0-install1tools.php