Vagrantfile for Centos 6 LAMP stack - vagrantfile

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

Related

Postgresql: how can install it in a different location in a linux server?

I would like to install postgresql in a linux (ubuntu) server.
If I do the following:
sudo apt-get install postgresql
it is going to install it in
/var/lib/postgresql/9.5/main
while I would like to have it in
/home/database/postgresql/9.5/main
Postgres uses the PGDATA environment variable to understand where do you want it to work. Edit the init script (either /etc/init.d/postgresql or /usr/lib/systemd/postgresql.service) and set the PGDATA accordingly. For example:
# Note: changing PGDATA will typically require adjusting SELinux
# configuration as well.
# Note: do not use a PGDATA pathname containing spaces, or you will
# break postgresql-setup.
[Unit]
Description=PostgreSQL database server
After=syslog.target
After=network.target
[Service]
Type=forking
User=postgres
Group=postgres
# Note: avoid inserting whitespace in these Environment= lines, or you may
# break postgresql-setup.
# Location of database directory
Environment=PGDATA=/var/sql/pgsql/
# Where to send early-startup messages from the server (before the logging
# options of postgresql.conf take effect)
# This is normally controlled by the global default set by systemd
# StandardOutput=syslog
# Disable OOM kill on the postmaster
OOMScoreAdjust=-1000
#ExecStartPre=/usr/local/pgsql/bin/postgresql95-check-db-dir ${PGDATA}
ExecStart=/usr/local/pgsql/bin/pg_ctl start -D ${PGDATA} -s -w -t 300
ExecStop=/usr/local/pgsql/bin/pg_ctl stop -D ${PGDATA} -s -m fast
ExecReload=/usr/local/pgsql/bin/pg_ctl reload -D ${PGDATA} -s
# Give a reasonable amount of time for the server to start up/shut down
TimeoutSec=300
[Install]
WantedBy=multi-user.target
You may also try to symlink /var/lib/postgresql/9.5/main to /home/database/postgresql/9.5/main - might be simpler.

Knowage BI - SQL Server DataSource

I have a question about knowage (opensource BI software - www.knowage-suite.com).
Can anyone tell me how create DataSource with a SQL Server connection?
Regards,
Tomasz
0> put MSSQL JDBC driver into `./<your_knowage_installation_directory>/lib` folder
1> log in (on web-UI) as administrator
2> data source
3> click on red '+' sign
4> give a label and choose your dialect (SQL-Server)
5> fill your credential (need SQLSErver auth, not active directory)
6> insert into JDBC this: `jdbc:sqlserver://<YOUR_SERVER_IP>`
7> insert `com.microsoft.sqlserver.jdbc.SQLServerDriver` as driver
8> create your dataset as a query (remember `use <your_db_name>` at the beginning of your query)
link to MSSQL jdbc drivers
Below are given steps for installing Knowage and setting up DB.
Install MySQL
1.
sudo apt-get install mysql-server
2.
Modified /etc/mysql/mysql.conf.d/mysqld.cnf and changed
from
bind-address = 127.0.0.1
to
bind-address = *
3.
mysql -u root -p
ALTER USER 'root'#'%' IDENTIFIED BY ''mypswd ';
GRANT ALL PRIVILEGES ON * . * TO 'root'#'%' IDENTIFIED BY ''mypswd';
FLUSH PRIVILEGES;
service mysql restart
Install Java
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
sudo apt-get install oracle-java8-set-default
export JAVA_HOME=/usr/lib/jvm/java-8-oracle
export PATH=$JAVA_HOME/bin:$PATH
Install Knowage
1. Download Knowage
wget http://download.forge.ow2.org/knowage/Knowage-6_2_0-RC-CE-Installer-Unix-20180509.zip
unzip Knowage-6_2_0-RC-CE-Installer-Unix-20180509.zip
2. Create Swap Memory (https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-16-04)
sudo swapon --show
free -h
df -h
sudo fallocate -l 4G /swapfile
ls -lh /swapfile
sudo chmod 600 /swapfile
ls -lh /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo swapon --show
free -h
Setup Knowage
sh Knowage-6_2_0-RC-CE-Installer-Unix-20180509.sh -c
Used existing MySQL DB and it created knowage_ce with following tables.
Add Database Source in conf/server.xml
<Resource name="jdbc/knowage" auth="Container"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/knowage_ce"
username="root"
password="mypswd"
maxActive="20" maxIdle="10"
maxWait="-1"/>
Download MySQL Connector and copy to lib dir
cp mysql-connector-java-5.1.46.jar /home/babbarkrishan/knowage/Knowage-Server-CE/lib/
start the knowage server in /bin
sh startup.sh
Hope it will resolve your problem.
Regards,
Krishan

How to configure the docker file to run cgi-script like 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.

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

NTLM with Apache + CentOS 5

I tried to install NTLM on CentOS 5 with Apache 2.
I did the following steps.
cd /tmp
wget http://search.cpan.org/CPAN/authors/id/S/SP/SPEEVES/Apache2-AuthenNTLM-0.02.tar.gz
tar zxvf Apache2-AuthenNTLM-0.02.tar.gz
cd Apache2-AuthenNTLM-0.02
perl Makefile.pl
make install
After that I added to my httpd.conf the following:
<Directory “/var/www/htlm/secure”>
Options Indexes
PerlAuthenHandler Apache2::AuthenNTLM
AuthType ntlm,basic
AuthName Secure Access
require valid-user
PerlAddVar ntdomain “YOURDOMAIN domaincontroller backupdomaincontroller”
PerlSetVar defaultdomain YOURDOMAIN
PerlSetVar splitdomainprefix 1
PerlSetVar ntlmdebug 0
PerlSetVar ntlmauthoritative off
</Directory>
Now I tried to restart the httpd service but I got the following error:
service httpd restart
Stopping httpd: [ OK ]
Starting httpd: Syntax error on line 1018 of /etc/httpd/conf/httpd.conf:
Invalid command 'PerlAuthenHandler', perhaps misspelled or defined by a module not included in the server configuration
[FAILED]
Do I need to add something else or do I need to add a module?
Thanks
Regards Paul
According to http://www.webmasterworld.com/forum13/4292.htm, you need mod_perl too.