Linux CentOS下部署LabelMeAnnotationTool

作者:Kinglong    发表时间:2022-09-14 18:11   

关键词:LabelMeAnnotationTool   apache   php   perl   cgi  

1. 服务器需求web server requirements

1) Run an Apache server (see special configuration instructions for Ubuntu or Windows).

8080

2) Enable authconfig in Apache so that server side includes (SSI) will work. This will allow SVG drawing capabilities. This is the most common source of errors, so make sure this step is working.

AllowOverride AuthConfig

3)Allow perl/CGI scripts to run. This is the second most common source of errors.

LoadModule cgi_module modules/mod_cgi.so

注:Linux 下,默认就会集成 perl 环境。执行 perl -version可测试。

linux – 使用Apache / Httpd在CentOS 7上运行Perl CGI脚本 (huati365.com)

4)Make sure the php5 and libapache2-mod-php5 libraries are installed. You can install them on Linux by running the following:

$ sudo apt-get install php5 libapache2-mod-php5

以上是ubuntu的命令,centos的包名不同

centos 改成  yum install php 既不是yum install php5 也不是yum install libapache2-mod-php5

libapache2-mod-php5安装找不到包Yum install libapache2-mod-php5 - CentOS

 

php5安装 (可以直接用yum install php)

http://t.zoukankan.com/xxdebug-p-14142266.html

4.1)创建文件夹

mkdir /usr/local/src/php

cd /usr/local/src/php

wget   http://cn2.php.net/distributions/php-5.3.28.tar.bz2

4.2)安装依赖

yum install -y gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libpng libpng-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses curl openssl-devel gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel readline-devel libxslt-devel expat-devel xmlrpc-c xmlrpc-c-devel

4.3)解压下载的php源码包

tar -xjvf php-5.3.28.tar.bz2
cd /usr/local/src/php/php-5.3.28
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --enable-sysvsem --enable-sockets --enable-pcntl --enable-mbstring --enable-mysqlnd --enable-opcache --enable-shmop --enable-zip --enable-ftp --enable-gd-native-ttf --enable-wddx --enable-soap
make

4.4)安装

make install

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

cp /usr/local/src/php/php-5.3.28/php.ini-development /usr/local/php/etc/php.ini-development

cp /usr/local/php/etc/php.ini-development /usr/local/php/etc/php.ini

cp /usr/local/src/php/php-5.3.28/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

4.5)添加权限

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

4.6)添加开机启动

chkconfig --add php-fpm

4.7)设置启动等级

chkconfig --level 35 php-fpm on

 

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

vim /usr/local/php/etc/php-fpm.conf

找到 ;pid = run/php-fpm.pid 去掉前面的分号

4.8)启动

service php-fpm start

9090

linux php改端口号的方法:1、找到安装的PHP7配置文件所在路径php-fpm.conf ;2、通过“listen = 0.0.0.0:9090”修改端口号即可。

4.9)设置环境变量

vim /etc/profile

底部添加

PATH=$PATH:/usr/local/php/bin

export PATH=$PATH:/usr/local/php/bin
环境变量生效 source /etc/profile

command not found  profile文件中存在 PARH 参数错误情况 export单词写错了

4.10)查看安装版本

php -v

5)(Optional) See special configuration instructions if you are installing on Ubuntu or Windows.

If you are not able to draw polygons, check to see if the page is loaded as an "application/xhtml+xml" page (you can see this in Firefox by navigating to Tools->Page Info). If it is not, be sure that SSI are enabled (see above for enabling authconfig in Apache).

Make sure that your images have read permissions on your web server and folders in the "Annotations" folder have write permissions. Also, "annotationCache/TmpAnnotations" needs to have write permissions.

 

2. 部署

1. 将 LabelMe 标注工具代码放在网页服务器上(网页服务器配置要求见上文)。

LabelMeAnnotationTool-master.zip 上传到服务器/var/www/html下,解压

cd /var/www/html

unzip LabelMeAnnotationTool-master.zip

将代码拷贝到/var/www/html下

2. 在命令行转到代码所在目录,上运行: make,这将设置 perl 脚本需要的全局变量。

cd /var/www/html

make

提示如下:

Setting base href: /var/www/html

Setting ./annotationTools/php/globalvariables.php: /var/www/html/

Setting write permissions

 3. 在「Images」文件夹内创建一个子文件夹,将我们的图像放在该文件夹内。如:「Images/example_folder/img1.jpg」。确保所有的图像的扩展名为「.jpg」,文件夹/文件名由字母和数字构成(即不包含空格和其他字符)。

4. 使用网页浏览器前往以下 URL 地址:http://172.16.11.33:8080/tool.html?collection=LabelMe&mode=f&folder=example_folder&image=img1.jpg

http://localhost/tool.html?collection=LabelMe&mode=f&folder=example_folder&image=img1.jpg

5. 标注图像。点击「show me another image」前往下一个图像。

6. 现在,你所作出的标注将出现在「Annotations」文件夹内。

 

3. 报错处理

500错误,查看 /var/log/httpd/error_log

 

3.1  报错No matching DirectoryIndex (index.html)

访问网址http://172.16.11.33:8080/报错:

Cannot serve directory /var/www/html/: No matching DirectoryIndex (index.html) found, and server-generated directory index forbidden by Options directive

访问网址http://172.16.11.33:8080/tool.html?collection=LabelMe&mode=f&folder=example_folder&image=img1.jpg

 

3.2  报错:.htaccess 导致 500错误 Options not allowed here

 [core:alert] [pid 49270] [client 192.168.5.37:53545] /var/www/html/.htaccess: Options not allowed here

这是由于客户在自己的网站的目录内放置了.htaccess文件。使用.htaccess文件,可以对网站目录的一些特性做子定义,如调整默认首页顺序、设置是否允许目录浏览、对网站目录做用户验证等功能进行定义。

解决方法 取消.htaccess文件。

移动或者改名.htaccess文件。但是这样会造成一些特殊配置的丢失,可能影响站点的正常运行。

3.3  StartupLabelMe is not defined

运行起来,不再报错500。

网页报错StartupLabelMe is not defined

以下这段js库没有正常引入html页面。尝试使用script标签引入。

<script type="text/javascript">
// <![CDATA[
<!--#include virtual="./annotationTools/js/jquery-1.9.1.js" -->
<!--#include virtual="./annotationTools/js/image.js" -->
.......
<!--#include virtual="./annotationTools/js/startup.js" -->
<!--#include virtual="./annotationTools/js/xml_accessors.js" -->
// ]]>
</script>

 

改成:

<script type="text/javascript" src="./annotationTools/js/jquery-1.9.1.js" ></script>

......

<script type="text/javascript" src="./annotationTools/js/startup.js" ></script>

......

3.4  cgi请求 403 forbidden

file_info.js:424          GET http://172.16.11.33:8080/annotationTools/perl/fetch_image.cgi?mode=f&username=anonymous&collection=labelme&folder=example_folder&image=img1.jpg 403 (Forbidden)

my_scripts.js:59          POST http://172.16.11.33:8080/annotationTools/perl/write_logfile.cgi 403 (Forbidden)

3.4.1  处理1 安装perl-CGI

  • 确保C盘Perl下已安装Perl
  • CGI不包含在Perl的标准发行版中,安装:yum install perl-CGI。

3.4.2  处理2  apache的httpd.conf文件增加配置

log日志错误:

ExecCGI is off in this directory: /var/www/html/annotationTools/perl/fetch_image.cgi

在http.conf中,定义的cgi运行位置是/var/www/cgi-bin/,而现在,运行的位置变化了,需要重新说明。
解决方法:在http.conf中加入,然后重启apache:
<Directory "/var/www/html/annotationTools/perl/">

    AllowOverride ALL

    Allow from all

    Options +ExecCGI

    AddHandler cgi-script .cgi .pl

</Directory>

3.4.3  处理3:权限问题

没有权限

Permission denied: exec of '/var/www/html/annotationTools/perl/fetch_image.cgi' failed, referer: http://172.16.11.33:8080/tool.html?

Permission denied: exec of '/var/www/html/annotationTools/perl/write_logfile.cgi' failed

chcon -R -t httpd_sys_content_t /var/www/html/annotationTools/perl

未解决。

3.5 尝试将cgi运行起来

3.5.1  cgi配置

https://blog.csdn.net/marxw520/article/details/84411721

 

先尝试用一个空的html目录将cgi运行起来。

修改配置文件,找到如下一段,在options后加上:ExecCGI

<Directory "/var/www/html">

      Options -Indexes FollowSymLinks ExecCGI

      AllowOverride All

      Order allow,deny
        Allow from all

</Directory>

报错:Either all Options must start with + or -, or no Option may.

如果您有目录选项,请注意它们都必须在前面加上一个+或-,或者根本没有。

配置改成以下FollowSymLinks ExecCGI前带“+”,解决。

<Directory "/var/www/html">

      Options -Indexes +FollowSymLinks +ExecCGI

      AllowOverride All

      Order allow,deny
        Allow from all

</Directory>

或者

<Directory /var/www/>

        Options Indexes FollowSymLinks ExecCGI   #加上ExecCGI,使其支持cgi程序

        AllowOverride None

        Require all granted

        AddHandler cgi-script .exe .pl .cgi   #添加cgi程序将要处理的后缀名

</Directory>

3.5.2  权限问题

访问/cgi-bin/test.cgi被拒绝 var/www/cgi-bin/test.cgi

访问/test.cgi被拒绝  var/www/html/test.cgi

Permission denied: exec of '/var/www/html/test.cgi' failed

 

http://cn.voidcc.com/question/p-wnwolqti-kx.html

777的权限就是:rwxrwxrwx 。 第一位7等于4+2+1,所以就是rwx,所有者有读取、写入、执行的权限;第二位7也是4+2+1,rwx,同组用户具有读取、写入、执行权限;第三位7,代表公共用户有读取、写入、执行的权限。

755的权限就是:rwxr-xr-x。第一位7等于4+2+1,所以就是rwx,所有者有读取、写入、执行的权限;第二位5也是4+0+1,r-x,同组用户具有读取、执行权限;第三位5,代表公共用户有读取、执行的权限。

(1)尝试解决cgi-bin目录访问权限:成功!

chmod -R 777  /var/www/cgi-bin/

访问:http://172.16.11.33:8080/cgi-bin/test.cgi

test.cgi代码:

#!/usr/bin/perl -w

use warnings;

use CGI qw(:standard);

#! must use 'my' to define a variable

print header;

my $now_string = localtime();

print "<b>Hello, CGI using Perl!</b><br/>It's $now_string NOW!<br />";

 

问题: 尝试访问html目录下的cgi文件,失败!

test.cgi和first.cgi拷贝到html下

chmod -R 777  /var/www/html

Permission denied: exec of '/var/www/html/test.cgi' failed

End of script output before headers: test.cgi

3.5.3  apache设置全目录执行cgi

http://www.linuxfly.org/post/331/

https://www.php.cn/apache/437122.html

配置apache运行cgi程序可分为两种情况,一是ScriptAlias目录的CGI,二是ScriptAlias以外目录的CGI。默认情况下,Apache 只允许在cgi-bin目录下执行 CGI 程序。

由于安全原因,CGI程序通常被限制在ScriptAlias指定的目录中,如此,管理员就可以严格地控制谁可以使用CGI程序。但是,如果采取了恰当的安全方法措施,则没有理由不允许其他目录中的CGI程序运行。比如,你可能希望用户在UserDir指定的宿主目录中存放页面,而他们有自己的CGI程序,但无权存取cgi-bin目录,这样,就产生了运行其他目录中CGI程序的需求。

允许在任意目录中执行CGI有两个步骤。首先,必须使用AddHandler或SetHandler指令激活cgi-script处理程序。其次,必须在Options指令中指定ExecCGI。

打开Apache设置文件/etc/httpd/conf/httpd.conf,修改 

(1)取消AddHandler cgi-script .cgi .pl前的注释:

    AddHandler cgi-script .cgi .pl

(2)为Options添加ExecCGI