How do I add PHPadmin to my bootstrap.sh commands? - vagrant-provision

I've been away from PHP nearly four years, I've been working in javascript and Node.JS instead. I have a memory of what tools I was comfortable working with.. it's a rusty memory how it all went together. I've followed Traversy's tutorial to get the LAMP box running
and have connected from MySQL WorkBench.
I'd like to use PHPAdmin, How do I add PHPadmin to my bootstrap.sh commands?
Installing phpMyAdmin On Vagrant
I like this version best, cause each domain has it's own /phpadmin, but I don't understand how he is editing the config file from inside bootstrap.sh
A super-simple Vagrant LAMP stack bootstrap (installable with one command)
I tried this one first, but got an error from the first curly brace, saying it didn't recognize the character..
bootstrap.sh
# Use single quotes instead of double quotes to make it work with special-character passwords
PASSWORD='12345678'
PROJECTFOLDER='myproject'
# Update Packages
apt-get update
# Upgrade Packages
apt-get upgrade
# Basic Linux Stuff
apt-get install -y git
# Apache
apt-get install -y apache2
# Enable Apache Mods
a2enmod rewrite
#Add Onrej PPA Repo
apt-add-repository ppa:ondrej/php
apt-get update
# Install PHP
apt-get install -y php7.2
# PHP Apache Mod
apt-get install -y libapache2-mod-php7.2
# Restart Apache
service apache2 restart
# PHP Mods
apt-get install -y php7.2-common
apt-get install -y php7.2-mcrypt
apt-get install -y php7.2-zip
# Set MySQL Pass
debconf-set-selections <<< 'mysql-server mysql-server/root_password password $PASSWORD'
debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password $PASSWORD'
# Install MySQL
apt-get install -y mysql-server
# PHP-MYSQL lib
apt-get install -y php7.2-mysql
# Install phpmyadmin
# apt-get install phpmyadmin
# Restart Apache
sudo service apache2 restart
Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
# Box Settings
config.vm.box = "ubuntu/trusty64"
# Provider Settings
config.vm.provider "virtualbox" do |vb|
vb.memory = 2048
vb.cpus = 4
end
# Network Settings
# config.vm.network "forwarded_port", guest: 80, host: 8080
# config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
config.vm.network "private_network", ip: "192.168.33.10"
# config.vm.network "public_network"
# Folder Settings
config.vm.synced_folder ".", "/var/www/html", :nfs => { :mount_options => ["dmode=777", "fmode=666"] }
# Provision Settings
# config.vm.provision "shell", inline: <<-SHELL
# apt-get update
# apt-get install -y apache2
# SHELL
config.vm.provision "shell", path: "bootstrap.sh"
end

Related

Vagrant doesn't runs Inline shell script to Install packages

All of my packages are not Installed, seems Vagrant doesn't provision Inline shell script by default.
Last time I Installed packages manually but then I ran Into permission Issues, again I tried reinstalling vagrant box but still It doesn't run the Inline script.
Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "bento/ubuntu-16.04"
config.vm.box_version = "= 2.3.5"
config.vm.synced_folder ".", "/vagrant"
config.vm.network "forwarded_port", guest: 8000, host: 8000, host_ip: "127.0.0.1"
config.vm.network "forwarded_port", guest: 8080, host: 8080, host_ip: "127.0.0.1"
config.vm.network "forwarded_port", guest: 5000, host: 5000, host_ip: "127.0.0.1"
# Work around disconnected virtual network cable.
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--cableconnected1", "on"]
end
config.vm.provision "shell", inline: <<-SHELL
apt-get -qqy update
# Work around https://github.com/chef/bento/issues/661
# apt-get -qqy upgrade
DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force- confdef" -o Dpkg::Options::="--force-confold" upgrade
apt-get -qqy install make zip unzip postgresql
apt-get -qqy install python3 python3-pip
pip3 install --upgrade pip
pip3 install flask packaging oauth2client redis passlib flask-httpauth
pip3 install sqlalchemy flask-sqlalchemy psycopg2-binary bleach requests
apt-get -qqy install python python-pip
pip2 install --upgrade pip
pip2 install flask packaging oauth2client redis passlib flask-httpauth
pip2 install sqlalchemy flask-sqlalchemy psycopg2-binary bleach requests
su postgres -c 'createuser -dRS vagrant'
su vagrant -c 'createdb'
su vagrant -c 'createdb news'
su vagrant -c 'createdb forum'
su vagrant -c 'psql forum -f /vagrant/forum/forum.sql'
vagrantTip="[35m[1mThe shared directory is located at /vagrant\\nTo access your shared files: cd /vagrant[m"
echo -e $vagrantTip > /etc/motd
wget http://download.redis.io/redis-stable.tar.gz
tar xvzf redis-stable.tar.gz
cd redis-stable
make
make install
echo "Done installing your virtual machine!"
SHELL
end
you can always run one by one the lines of your script to check which one produces an error.
Here I see you have a space on --force- confdef you can easily fix with
DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade

apt-get command not found in Vagrant/Window

When I run vagran up command, I get the error apt-get command not found in vagrant, my pc is using window-10.
Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
# VM Box
config.vm.box = "centos-7"
config.vm.network "private_network", ip: "192.168.33.100"
config.vm.provider "virtualbox" do |vb|
vb.memory = 2048
vb.cpus = 4
end
config.vm.provision "shell", path: "bootstrap.sh"
end
bootstrap.sh
sudo apt-get update
sudo apt-get apgrate
sudo apt-get install -y git
you're using a centos box
config.vm.box = "centos-7"
so you should use the yum package manager, apt is used for ubuntu family and is not compatible with the other os family (Debian vs Fedora)
To install git on centos replace your bootstrap script by
yum update
yum install -y git
Have you tried using yum and trying $ vagrant box update? Also, you can get more in depth logs by using $ vagrant up --debug or if you would like to save it to a file $ vagrant up --debug &> vagrant.log. I always recommend doing some VM house keeping as well by making sure all VMs are stopped then run $ vagrant reload --provision on the VM having the issues. As always, the best part of using Vagrant is the ability to wipe it and start over again.

How to run ganache-cli from Vagrant box?

I am running ganache-cli in a Vagrant box and trying to connect Metamask (Google Chrome) to it. But Metamask fails to connect to it. It connects if ganache-cli runs on the host machine. This is my Vagrant file
Vagrant file
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.hostname = 'ethereum'
config.vm.box = "ubuntu/bionic64"
config.vm.provision :shell, path: "setup_dev_env.sh"
config.vm.box_check_update = false
config.vm.network "forwarded_port", guest: 3000, host: 3000, host_ip: "127.0.0.1"
config.vm.network "forwarded_port", guest: 8545, host: 8545, host_ip: "127.0.0.1"
config.vm.synced_folder "SOME_PATH", "/home/vagrant/code"
config.vm.provider "virtualbox" do |vb|
vb.gui = false
vb.memory = "4096"
end
end
Contents of setup_dev_env.sh
sudo apt-get install software-properties-common
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install -y --allow-unauthenticated python3-pip mypy build-essential ethereum npm
sudo npm install -g ganache-cli
sudo apt-get update
Start ganache-cli with ganache-cli --host 0.0.0.0 and in Metamask enter details for Custom RPC in New RPC URL as http://0.0.0.0:8545

unable to sync folder in vagrant

I am using vagrant box 'ubuntu/trusty64'. I am trying to sync folder in vagrant and for that, I have modified my vagrant file. The file is:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "foo-box"
config.vm.network "forwarded_port", guest: 8000, host: 8000, host_ip: "127.0.0.1"
config.vm.network "forwarded_port", guest: 8080, host: 8080, host_ip: "127.0.0.1"
config.vm.network "forwarded_port", guest: 5000, host: 5000, host_ip: "127.0.0.1"
# Work around disconnected virtual network cable.
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--cableconnected1", "on"]
end
Vagrant.configure("2") do |config|
config.vm.synced_folder "C:/fullstack/vagrant", "home/vagrant"
end
config.vm.provision "shell", inline: <<-SHELL
apt-get -qqy update
apt-get -qqy upgrade
apt-get -qqy install make zip unzip postgresql
apt-get -qqy install python3 python3-pip
pip3 install --upgrade pip
pip3 install flask packaging oauth2client redis passlib flask-httpauth
pip3 install sqlalchemy flask-sqlalchemy psycopg2 bleach
apt-get -qqy install python python-pip
pip2 install --upgrade pip
pip2 install flask packaging oauth2client redis passlib flask-httpauth
pip2 install sqlalchemy flask-sqlalchemy psycopg2 bleach
su postgres -c 'createuser -dRS vagrant'
su vagrant -c 'createdb'
su vagrant -c 'createdb news'
su vagrant -c 'createdb forum'
su vagrant -c 'psql forum -f /vagrant/forum/forum.sql'
vagrantTip="[35m[1mThe shared directory is located at /vagrant\\nTo access your shared files: cd /vagrant[m"
echo -e $vagrantTip > /etc/motd
wget http://download.redis.io/redis-stable.tar.gz
tar xvzf redis-stable.tar.gz
cd redis-stable
make
make install
echo "Done installing your virtual machine!"
SHELL
end
I have also tried answer given in https://stackoverflow.com/questions/29731003/synced-folder-in-vagrant-is-not-syncing-in-realtime but of no help.
The path to my project on host machine is C:\fullstack. The content of the folder fullstack is
README.md vagrant/ Vagrantfile
And further the content of vagrant folder is
catalog/ forum/ tournament/ Vagrantfile
The content in both the vagrantfile file is same.
I tried to make an empty directory in guest machine in vagrant directory but the directory didn't show in host machine. Please suggest something.
You dont need to re-introduce a configure section, just have your Vagrantfile as
Vagrant.configure("2") do |config|
config.vm.box = "foo-box"
config.vm.network "forwarded_port", guest: 8000, host: 8000, host_ip: "127.0.0.1"
config.vm.network "forwarded_port", guest: 8080, host: 8080, host_ip: "127.0.0.1"
config.vm.network "forwarded_port", guest: 5000, host: 5000, host_ip: "127.0.0.1"
# Work around disconnected virtual network cable.
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--cableconnected1", "on"]
end
config.vm.synced_folder "C:/fullstack/vagrant", "home/vagrant/stack"
Also its not really good to sync on your /home/vagrant folder directly as this folder has the .ssh folder (ssh might not work) and bash information, its better to have a subdirectory of the main home folder.

vagrant path to shell script windows

There is a problem with the path to a shell script on windows.
On linux, the Vagrantfile works fine.
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.provider :virtualbox do |vb|
vb.name = "studstat_dev"
end
config.vm.network "forwarded_port", guest: 8000, host: 8888
config.vm.network "forwarded_port", guest: 5432, host: 15432
# Provisioning mit Shell-Script
config.vm.provision "shell", path: "studstat.sh"
end
studstat.sh
#!/bin/sh -e
# Edit the following to change the name of the database user that will be created:
APP_DB_USER=vagrant
APP_DB_PASS=vagrant
# Edit the following to change the name of the database that is created (defaults to the user name)
APP_DB_NAME=studstat
# Edit the following to change the version of PostgreSQL that is installed
PG_VERSION=9.4
export DEBIAN_FRONTEND=noninteractive
PG_REPO_APT_SOURCE=/etc/apt/sources.list.d/pgdg.list
if [ ! -f "$PG_REPO_APT_SOURCE" ]
then
# Add PG apt repo:
echo "deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main" > "$PG_REPO_APT_SOURCE"
# Add PGDG repo key:
wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | apt-key add -
fi
# Update package list and upgrade all packagesini
apt-get update
apt-get -y upgrade
# install packages for postgres + python3
apt-get -y install "postgresql-$PG_VERSION" "postgresql-contrib-$PG_VERSION"
apt-get -y install vim git python3-setuptools python3-dev libpq-dev python3-pip
# install virtualenv via pip3, not yet in ubuntu repository (20.11.15)
pip3 install virtualenv
PG_CONF="/etc/postgresql/$PG_VERSION/main/postgresql.conf"
PG_HBA="/etc/postgresql/$PG_VERSION/main/pg_hba.conf"
PG_DIR="/var/lib/postgresql/$PG_VERSION/main"
# Edit postgresql.conf to change listen address to '*':
sed -i "s/#listen_addresses = 'localhost'/listen_addresses = '*'/" "$PG_CONF"
# Append to pg_hba.conf to add password auth:
echo "host all all all md5" >> "$PG_HBA"
# Explicitly set default client_encoding
echo "client_encoding = utf8" >> "$PG_CONF"
# generate locales
locale-gen de_DE.UTF-8
update-locale LANG=de_DE.UTF-8
# Restart so that all new config is loaded:
service postgresql restart
cat << EOF | su - postgres -c psql
-- Create the database user:
CREATE USER $APP_DB_USER WITH PASSWORD '$APP_DB_PASS';
-- Create the database:
CREATE DATABASE $APP_DB_NAME WITH OWNER=$APP_DB_USER
LC_COLLATE='de_DE.UTF-8'
LC_CTYPE='de_DE.UTF-8'
ENCODING='UTF8'
TEMPLATE=template0;
EOF
The script is in the same folder as the Vagrantfile. Relevant output of vagrant shell:
==> default: Running provisioner: shell...
default: Running: C:Users/hema0004/AppData/Local/Temp/vagrant-shell20160201-2732-1v2m7qa.sh
==> default: gpg: no valid OpenPGP data found.
The SSH command responded with a non-zero exit status. Vagrant assumes, that this means the command failed. The output for this command should be in the log above. Please read the output to determine what went wrong.
The given path to log does not exist on my mashine.
Without shell script, vagrant works fine, any ideas?
[Edit]: I can access the machine but I can not execute the script from within the machine:
/bin/sh: 0: Illegal option -
Thx, martin
The problem was that the box had no access to the internet because of missing environment variables. These variables should have been provided via the vagrant-proxyconf plugin. The underlaying problem was, that path to $VAGRANT_HOME where the proxy configuration is provided was wrong.
can you try from the following repo
# Add PGDG repo key:
apt-get install -y ca-certificates wget
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -

Resources