How to configure the docker file to run cgi-script like perl - perl

I have this files:
index.php
Dockerfile
/conf/myawesomesite.conf
cgi-bin/helloworld.pl
in /conf/myawesomesite.conf:
<VirtualHost *:80>
ServerAdmin webmaster#myawesomesite.com
ServerName myawesomesite.com
ServerAlias www.myawesomesite.com
DocumentRoot /var/www/html/myawesomesite.com/httpdocs
ErrorLog /var/www/myawesomesite.com/logs/error.log
CustomLog /var/www/myawesomesite.com/logs/access.log combined
Options ExecCGI
AddHandler cgi-script .pl
</VirtualHost>
in Dockerfile:
FROM ubuntu:16.04
## Install Base Packages
RUN apt-get update && apt-get -y install \
apache2 \
make \
curl \
git \
gcc
RUN a2enmod rewrite
## Install Perl
RUN apt-get update && apt-get -y install \
libapache2-mod-perl2 \
perl
RUN a2enmod perl
## Install PHP
RUN apt-get update && apt-get -y install \
php7.0 php7.0-cli php7.0-common php7.0-fpm php7.0-json \
php7.0-mbstring php7.0-mcrypt php7.0-mysql php7.0-opcache php7.0-readline \
libapache2-mod-php7.0
RUN a2enmod rewrite
EXPOSE 80
RUN mkdir -p /var/www/html/myawesomesite.com/httpdocs
RUN mkdir -p /var/www/myawesomesite.com/logs/
COPY ./conf/myawesomesite.conf /etc/apache2/sites-available/
RUN a2ensite myawesomesite
RUN a2dissite 000-default.conf
CMD /usr/sbin/apache2ctl -D FOREGROUND
build and run the container, index.php is executing correctly but when this page myawesomesite.com/cgi-bin/helloworld.pl the script is just printed not executed. Result below:
#!/usr/bin/perl
print "Content-Type:text/html\n\n";
print "Hello World!";
I'm expecting the result is Hello World! since i added these directives in my myawesomesite.conf file. But why?
Options ExecCGI
AddHandler cgi-script .pl

I had to add RUN a2enmod cgid to the Dockerfile and the following block to the conf (assuming the perl script was copied to /var/www/myawesomesite.com/www/cgi-bin/):
<Directory "/var/www/myawesomesite.com/www/cgi-bin/">
Options +ExecCGI
AddHandler cgi-script .pl
</Directory>

Try to add to your Dockerfile:
RUN chmod +x cgi-bin/helloworld.pl
CGI scripts must have executable bits set.

Related

node-poppler installation of poppler-utils and poppler-data

https://github.com/Fdawgs/node-poppler
When following the readme one thing I ran into is poppler-utils and poppler-data didn't get installed in /usr/bin. Based on that readme I'm expecting them to get installed there by default.
After running a find inside the container I found the files in /usr/share/doc. This doesn't seem right based on the readme.
How do I ensure poppler-utils and poppler-data get added into /usr/bin as expected in the readme.
Ultimately this is the code I'm instantiating:
const poppler = new Poppler('/usr/bin');
Dockerfile:
FROM docker.registry.sfg.corp.local/devops/nodejs-build-docker:16.16.60850 as build
ARG NAME
ARG IMAGE
ARG SNYK_TOKEN
ARG SNYK_ORGANIZATION
ARG SNYK_PROJECT
COPY . .
RUN apt-get update
RUN apt-get install poppler-utils -y
RUN apt-get install poppler-data -y
RUN chmod +x install-puppeteer.sh
RUN ./install-puppeteer.sh
RUN ./build.sh -n $NAME -i $IMAGE -t $SNYK_TOKEN -o $SNYK_ORGANIZATION -p $SNYK_PROJECT
FROM docker.registry.sfg.corp.local/node:16-buster
RUN apt-get update
RUN apt-get install poppler-utils -y
RUN apt-get install poppler-data -y
COPY ./install-puppeteer.sh .
RUN chmod +x install-puppeteer.sh
RUN ./install-puppeteer.sh
# add the chrome folder to the PATH
ENV PATH "$PATH:/opt/google/chrome"
COPY --from=build package.json package.json
COPY --from=build src src/
COPY --from=build node_modules node_modules/
COPY --from=build artifacts artifacts/
# Add tini to help prevent zombie chrome processes.
ADD https://github.com/krallin/tini/releases/download/v0.19.0/tini /tini
RUN chmod +x /tini
# Add user so we don't need --no-sandbox.
RUN groupadd -r pptruser && useradd -r -g pptruser -G audio,video pptruser \
&& mkdir -p /home/pptruser/Downloads \
&& mkdir -p /home/pptruser/.cache \
&& mkdir -p /home/pptruser/.cache/puppeteer \
&& chown -R pptruser:pptruser /home/pptruser \
&& chown -R pptruser:pptruser /node_modules
USER pptruser
RUN chmod +x node_modules/riley/bin/riley.sh
ENTRYPOINT ["/tini", "--"]
CMD ["node_modules/riley/bin/riley.sh"]

Problem installing modules with cpanm in Perl

I am absolutely new to Perl world. I've picked up a project left behind by a former employee & trying to get it to work. The project was originally in docker form & the requirement now is to run it in a non-docker form (don't get me started on this!) The project works like a charm in it's docker form. I've made the assumption that if I were to install all the packages installed in the docker file, the script should work. In the process of installing the packages, I am bumping into issues.
While the docker image uses ubuntu, the server I am trying on now uses RHEL7
DOCKER FILE
FROM ubuntu:focal-20200703 as ubuntu
FROM ubuntu as mytool
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y -qq build-essential libssl-dev tzdata bash curl wget perl cpanminus libcrypt-ssleay-perl libnet-ssleay-perl
RUN cpanm -n Data::Printer \
Log::Log4perl \
List::Util \
Test::More \
JSON \
JSON::XS \
YAML \
YAML::XS \
GitLab::API::v4 \
IO::Socket::SSL \
HTML::HashTable \
REST::Client \
MIME::Base64 \
File::Spec \
File::Basename \
File::Path \
List::MoreUtils \
DateTime::Format::ISO8601 \
Digest::MD5
ENV TZ=Pacific/Auckland
RUN echo $TZ > /etc/timezone && ln -snf /usr/share/zoneinfo/$TZ /etc/localtime
COPY docker/context/usr/local/bin/entrypoint.sh /usr/local/bin/entrypoint.sh
COPY docker/context/usr/local/etc/mytool/mytool.env.ctmpl /usr/local/etc/mytool/mytool.env.ctmpl
RUN mkdir -p /usr/local/bin /usr/local/bin/cache.d
WORKDIR /usr/local/bin
COPY mytool /usr/local/bin/
COPY lib/ /usr/local/bin/lib
# Container pilot obligatory parameters START
ENV SERVICE_NAME=mytool
ENV SERVICE_PRE_EXEC=/bin/true
ENV SERVICE_HEALTHCHECK_EXEC="test -f /usr/local/etc/mytool/mytool.env"
ENV SERVICE_TEMPLATE_CONFIG_PAIRS=/usr/local/etc/mytool/mytool.env.ctmpl:/usr/local/etc/mytool/mytool.env
EXPOSE 8080
ENTRYPOINT [""]
CMD ["/usr/local/bin/entrypoint.sh"]
# Container pilot obligatory parameters END
I've installed build-essential libssl-dev tzdata bash curl wget perl cpanminus libcrypt-ssleay-perl libnet-ssleay-perl successfully.
Problem is with cpanm stuff from the docker file
[root#npcrver01 home]# cpanm Log::Log4perl
! Finding Log::Log4perl on cpanmetadb failed.
! cannot open file '/root/.cpanm/sources/http%www.cpan.org/02packages.details.txt.gz': No such file or directory opening compressed index
! Couldn't find module or a distribution Log::Log4perl ()
Please could someone help me here
gosh it's the proxy setting. I had to do
export https_proxy=http://<IP>:<port>
export http_proxy=http://<IP>:<port>
export HTTPS_PROXY=http://<IP>:<port>
export HTTP_PROXY=http://<IP>:<port>
Everything is working fine now

Vagrantfile for Centos 6 LAMP stack

I need assistance putting together a Vagrantfile.
I am trying to setup a virtual machine on my Windows desktop for working on an existing PHP/MySQL application. I've been instructed to use Vagrant and VirtualBox. I've been going through the documentation for Vagrant and found this to be over my head with a lot of information out of date. I have some background in general Linux usage, but none in setting up LAMP servers on them.
What I have:
Vagrant 2.1.2
VirtualBox 5.2.18
Things I need in the VM:
Centos 6
Apache
MySQL 5.5
PHP 5.6
MySQLi/Mysqlnd (PDO optional)
Curl
DOM/SimpleXML
Any PHP extensions needed for a typical PHP application
It has taken a few weeks and a lot of wading through out of date tutorials, but I got it done. I am sharing so others on the LAMP service stack have a place to start in crafting their vagrantfile. Note that this was not done for elegance. It is a quick starter that is easy-ish to understand and adjust to one's needs.
A few small deviations of note were made from the above original post:
I went with Ubuntu/bionic64 instead of Centos 6, mostly because of the abundance of tutorial material I was able to find. Modifying this file for CentOS 6 shouldn't be too hard. CentOS uses Yum instead of Apt-get for package management. I'm not entirely certain what else is different.
I went with PHP 7.2 instead of 5.6.
I found PHP 7.2 comes with MySQLi and the native driver already installed out of the box.
Working vagrantfile and shell bootstrapper included, heavily commented for comprehension: https://pastebin.com/Eqvhq8KZ
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = '2'
#########################################################################
# VM Setup for LAMP stack application
#
# - Install PHP and packages
# - Install Apache
# - Configure /vagrant as document root
# - Config PHP for development and logging
# - Install MySQL
# - Setup database and permissions (username and password are "vagrant")
# - Install Composer
#########################################################################
#script = <<SCRIPT
#################### PHP ####################
apt-get install -y apt-utils php7.2 php7.2-bcmath php7.2-bz2 php7.2-cli php7.2-curl php7.2-intl php7.2-json php7.2-mbstring php7.2-opcache php7.2-soap php7.2-sqlite3 php7.2-xml php7.2-xsl php7.2-zip unzip
#################### APACHE2 ####################
apt-get install -y apache2 libapache2-mod-php7.2
# Remove /var/www default
rm -rf /var/www
# Symlink /vagrant to /var/www
ln -fs /vagrant /var/www
# Add ServerName to httpd.conf
echo "ServerName localhost" > /etc/apache2/httpd.conf
# Setup hosts file
VHOST=$(cat <<EOF
<VirtualHost *:80>
DocumentRoot "/vagrant"
ServerName localhost
<Directory "/vagrant">
Options Indexes FollowSymLinks MultiViews Includes
AllowOverride All
Require all granted
Order allow,deny
Allow from all
AddType text/html .shtm .shtml
AddOutputFilter INCLUDES .htm .html .shtm .shtml
</Directory>
</VirtualHost>
EOF
)
echo "${VHOST}" > /etc/apache2/sites-enabled/000-default.conf
# Enable mod_rewrite
a2enmod rewrite
# Put PHP into development configuration
mv /etc/php/7.2/apache2/php.ini /etc/php/7.2/apache2/php.ini.back
cp /usr/lib/php/7.2/php.ini-development /etc/php/7.2/apache2/php.ini
# Enable PHP extensions in php.ini
#sed -i 's/;extension=mysqli/extension=mysqli/' /etc/php/7.2/apache2/php.ini
# PHP will log its errors in a /log/error_log file
sed -i 's:;error_log = php_errors.log:error_log = /vagrant/log/error_log:' /etc/php/7.2/apache2/php.ini
# Restart apache
systemctl restart apache2.service
#################### MYSQL ####################
apt-get install -y mysql-server mysql-client-core-5.7 php7.2-mysql
systemctl start mysql.service
# Reset root password
#/usr/bin/mysqladmin -u root password 'root'
mysqladmin -u root password 'root'
# Setup database from root user and setup the application user
mysql -uroot -proot -e "CREATE DATABASE IF NOT EXISTS app"
mysql -uroot -proot app < /vagrant/db/schema.sql
mysql -uroot -proot -e "GRANT ALL PRIVILEGES ON *.* to 'vagrant'#'localhost' IDENTIFIED BY 'vagrant'"
mysql -uroot -proot -e "GRANT ALL PRIVILEGES ON *.* to 'vagrant'#'%' IDENTIFIED BY 'vagrant'"
mysql -uroot -proot -e "FLUSH PRIVILEGES"
# Allow remote connections for MySQL Workbench
MYSQLCONF=$(cat <<EOF
[mysqld]
bind-address = 0.0.0.0
EOF
)
echo "${MYSQLCONF}" >> /etc/mysql/my.cnf
# Restart mysql
/etc/init.d/mysql restart
#################### COMPOSER ####################
curl -sS http://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
# Run composer install
cd /vagrant && composer install
#################### FINISHED! ####################
echo "** [PHP] Visit http://localhost:8080 in your browser for to view the application **"
SCRIPT
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = 'ubuntu/bionic64'
config.ssh.insert_key = false
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.network "forwarded_port", guest: 443, host: 8081
config.vm.network "forwarded_port", guest: 3306, host: 3307
#config.vm.synced_folder '.', '/var/www/html'
# Provision runs only on the first "Vangrant up" command
config.vm.provision 'shell', privileged: true, inline: #script
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--memory", "2048"]
vb.customize ['modifyvm', :id, "--natdnshostresolver1", "on"]
end
end

How to install webacula 7 on centos 7

this is a tutorial to install webacula 7 (after bacula 7 with mysql)
this is the tutorial for centos+bcula that i used (without webmin section)
http://www.backupcentral.com/phpBB2/two-way-mirrors-of-external-mailing-lists-3/bacula-25/howto-install-bacula-7-on-centos-7-fresh-install-126395/
Then to install webacula:
yum install httpd php php-mysql php-gd
wget http://downloads.sourceforge.net/project/webacula/webacula/7.0.0/webacula-7.0.0.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fwebacula%2F%3Fsource%3Dtyp_redirect&ts=1429012567&use_mirror=garr
(download webacula 7.0.0)
yum install httpd php php-mysql
tar -xzvf /root/webacula-7.0.0.tar.gz\?r\=http...
mv webacula-7.0.0 /var/www/
mv /var/www/webacula-7.0.0/ /var/www/webacula
chown -R root.root .
chown apache.apache cache
groupadd bacula
usermod -aG bacula apache
chgrp bacula /usr/sbin/bconsole
/etc/bacula/bconsole.conf
chgrp bacula /etc/bacula/bconsole.conf
cd ../application
nano config.ini
update:
bacula.bconsole = "/usr/sbin/bconsole"
bacula.bconsolecmd = "-n -c /etc/bacula/bconsole.conf"
nano /etc/sudoers
comment:
# Defaults requiretty
nano /etc/bacula/bconsole.conf
update:
Password = "YOUR PASS"
nano /etc/selinux/config
update:
SELINUX=disabled
nano /etc/sudoers.d/apache
add:
apache ALL=NOPASSWD: /usr/sbin/bconsole
reboot (because the selinux)
check with this command:
su -l apache -s /bin/sh -c "/usr/bin/sudo /usr/sbin/bconsole -n -c /etc/bacula/bconsole.conf"
normal respons :
Connecting to Director localhost:9101
1000 OK: 1 bacula-dir Version: 7.0.5 (28 July 2014)
Enter a period to cancel a command.
*quit
cd /var/www/webacula/install/apache/
cp webacula.conf /etc/httpd/conf.d/webacula.conf
nano /etc/httpd/conf.d/webacula.conf
update:
Alias /webacula /usr/share/webacula/html
<Directory /usr/share/webacula/html>
...
Deny from all
to:
Alias /webacula /var/www/webacula/html
<Directory /var/www/webacula/html>
...
Allow from all
nano /var/www/webacula/application/config.ini
update your db pass
nano /etc/bacula/bacula-dir.conf
update :
catalog = all, !skipped, !saved
cd /var/www/webacula/install
./password-to-hash.php your bacula webming pass
take ther respons and put in:
nano db.conf
update:
db_pwd="your root mysql pass"
....
webacula_root_pwd="your res from ./password-to-hash.php"
cd MySql/
./10_make_tables.sh
./20_acl_make_tables.sh
systemctl restart httpd
add Zend to webacula:
cd /var/www/webacula/library
wget https://packages.zendframework.com/releases/ZendFramework-1.12.3/ZendFramework-1.12.3-minimal.tar.gz (download only ver 1.12.3!!!!!!)
tar -xzf ZendFramework-1.12.3-minimal.tar.gz
mkdir Zend
cp -Rf ZendFramework-1.12.3-minimal/library/Zend/* Zend/.
go to website :)
now we finished but for me the root password did not work, so to fix this i did:
mysql -uroot -p
use bacula;
update webacula_users set email='your email here';
go to website and reset password

How to start railo service in background on the Docker

My name Trang,
I have created Docker image on https://registry.hub.docker.com/u/trangunghoa/railo-mysql/
It is run ok.
Now I created Dockerfile but I can't start automatic Railo service. Please help me.
I have start by some commands at shell script:
exec /opt/railo/railo_ctl start
exec /opt/railo/railo_ctl start -D FOREGROUND
service railo_ctl restart
exec service railo_ctl restart
No command it work.
I looked inside your Dockerfile and identified the problem.
You can only use one CMD inside a Dockerfile. (if you use multiple CMD the old one will override) More info : https://docs.docker.com/reference/builder/#cmd
You need to know that Docker isn't made for running multiple process without a little bit of help. I suggest using supervisord : https://docs.docker.com/articles/using_supervisord/
You can't use RUN service inside a Dockerfile, the reason is simple the command service will be executed and start a daemon, then notify the execution was successful. The temporary container will be killed (and the daemon too) and after that the change will be committed.
What your Dockerfile should look like :
FROM ubuntu:trusty
MAINTAINER Trang Lee <trangunghoa#gmail.com>, Seta International Vietnam(info#setacinq.vn)
#Install base packages
RUN apt-get -y update
RUN apt-get install -y openjdk-7-jre-headless
RUN apt-get install -y tomcat7 tomcat7-admin apache2 libapache2-mod-jk
RUN apt-get purge -y openjdk-6-jre-headless icedtea-6-jre-cacao openjdk-6-jre-lib icedtea-6-jre-jamvm
RUN apt-get install -y supervisor
# config to enable .htaccess
ADD apache_default /etc/apache2/sites-available/000-default.conf
RUN a2enmod rewrite
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
# start service
ADD start-apache2.sh /start-apache2.sh
ADD railo.sh /railo.sh
ADD run.sh /run.sh
RUN chmod +x /*.sh
#RUN sudo service apache2 start
# install railo
RUN apt-get install -y wget
RUN wget http://www.getrailo.org/railo/remote/download42/4.2.1.000/tomcat/linux/railo-4.2.1.000-pl2-linux-x64-installer.run
RUN chmod -R 744 railo-4.2.1.000-pl2-linux-x64-installer.run
RUN ./railo-4.2.1.000-pl2-linux-x64-installer.run --mode unattended --railopass “123456”
# remove railo setup
#RUN rm -rf railo-4.2.1.000-pl2-linux-x64-installer.run
#RUN sudo service railo_ctl start
RUN mkdir -p /etc/service/railo
ADD start-railo.sh /etc/service/railo/run
RUN chmod 755 /etc/service/railo/run
# EXPOSE <port>
EXPOSE 80 8888
#CMD ["/railo.sh"]
#CMD ["/start-apache2.sh"]
# Supervisord configuration
RUN mkdir /var/log/supervisor
ADD ./supervisord.conf /etc/supervisor/conf.d/supervisord.conf
CMD ["/usr/bin/supervisord"]
With your supervisord.conf file looking something like that :
[supervisord]
nodaemon=true
[program:apache2]
command=/bin/bash -c "source /etc/apache2/envvars && exec /usr/sbin/apache2 -DFOREGROUND"
[program:railo]
command=/bin/bash -c "exec /opt/railo/railo_ctl start -D FOREGROUND"