ArticSun
ArticSun

Reputation: 11

Install Phalcon with Vagrant/Puppet (git command not found)

I've succesfully setup a Vagrant/Puppet configuration to install a basic hashicorp/precise64 server with nginx, mysql, php5-fpm, etc. The server starts and I can use PHP without any problem (the webpage is reachable).

Phalcon gives me some problems however. I created a simple shell script (say install.sh) with the following content:

#!/bin/sh
git clone --depth=1 https://github.com/phalcon/cphalcon.git
cd cphalcon/build
./install
wait
service php5-fpm restart
service nginx restart

This shell script is copied to the root of the linux server and should then be executed with the following Puppet command:

exec { '/install_phalcon.sh':
require => File['/install_phalcon.sh'],
cwd => '/',
path => '/',
}

It starts executing the shell script, but it than gives errors like "git command not found". I've seen this before with commands like "cp" and "ln".

When you login the vagrant VM, use "sudo su" and then execute the shell script, all goes well.

Am I doing something wrong, is this a rights issue? And how to solve it in Vagrant/Puppet?

Thank you!

Upvotes: 0

Views: 831

Answers (2)

Lukas Liesis
Lukas Liesis

Reputation: 26393

I can share my vagrant and install file. I use Phalcon with Ubuntu. It works w/o any problems on Mac, Windows and Ubuntu machines.

Vagrantfile file (name of the file is just "Vagrantfile")

# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

  # Base Box
  # --------------------
  config.vm.box = "precise32"
  config.vm.box_url = "http://files.vagrantup.com/precise32.box"

  # Connect to IP
  # --------------------
  config.vm.network :private_network, ip: "192.168.5.0"

  # Forward to Port
  # --------------------
  #config.vm.network :forwarded_port, guest: 80, host: 8080

  # Optional (Remove if desired)
  config.vm.provider :virtualbox do |v|
    # How much RAM to give the VM (in MB)
    # -----------------------------------
    v.customize ["modifyvm", :id, "--memory", "700"]

    # Uncomment the Bottom two lines to enable muli-core in the VM
    #v.customize ["modifyvm", :id, "--cpus", "2"]
    #v.customize ["modifyvm", :id, "--ioapic", "on"]
  end

  # Provisioning Script
  # --------------------
  config.vm.provision "shell", path: "init.sh"

  # Synced Folder
  # --------------------
  config.vm.synced_folder "./", "/var/www/", :mount_options => [ "dmode=775", "fmode=644" ], :owner => 'www-data', :group => 'www-data'

end

and the installation file (name of the file is "init.sh"):

#!/bin/bash
# Using Precise32 Ubuntu
# to use closest ubuntu mirror by geographic location
echo 'deb mirror://mirrors.ubuntu.com/mirrors.txt precise main restricted universe multiverse' | cat - /etc/apt/sources.list > temp && mv temp /etc/apt/sources.list
echo 'deb mirror://mirrors.ubuntu.com/mirrors.txt precise-updates main restricted universe multiverse' | cat - /etc/apt/sources.list > temp && mv temp /etc/apt/sources.list
echo 'deb mirror://mirrors.ubuntu.com/mirrors.txt precise-backports main restricted universe multiverse' | cat - /etc/apt/sources.list > temp && mv temp /etc/apt/sources.list
echo 'deb mirror://mirrors.ubuntu.com/mirrors.txt precise-security main restricted universe multiverse' | cat - /etc/apt/sources.list > temp && mv temp /etc/apt/sources.list

sudo apt-get update
sudo apt-get update

#
# For PHP 5.5
#

sudo apt-get install -y python-software-properties
sudo add-apt-repository ppa:ondrej/php5
sudo apt-get update

#
# MySQL with root:<no password>
#
export DEBIAN_FRONTEND=noninteractive
apt-get -q -y install mysql-server

#
# PHP
#
sudo apt-get install -y php5 php5-dev apache2 libapache2-mod-php5 php5-mysql php5-curl php5-mcrypt php5-gd php5-imagick

#
# Redis
#
sudo apt-get install -y redis-server

#
# MongoDB
#
sudo apt-get install mongodb-clients mongodb-server

#
# Utilities
#
sudo apt-get install -y curl htop git-core gcc autoconf
sudo apt-get install -y libpcre3-dev

#
# Redis Configuration
# Allow us to Remote from Vagrant with Port
#
sudo cp /etc/redis/redis.conf /etc/redis/redis.bkup.conf
sudo sed -i 's/bind 127.0.0.1/bind 0.0.0.0/' /etc/redis/redis.conf
sudo /etc/init.d/redis-server restart

#
# MySQL Configuration
# Allow us to Remote from Vagrant with Port
#
sudo cp /etc/mysql/my.cnf /etc/mysql/my.bkup.cnf
# Note: Since the MySQL bind-address has a tab character I comment out the end line
sudo sed -i 's/bind-address/bind-address = 0.0.0.0#/' /etc/mysql/my.cnf

#
# Grant All Priveleges to ROOT for remote access
#
mysql -u root -Bse "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '' WITH GRANT OPTION;"
sudo service mysql restart



#
# Composer for PHP
#
sudo curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer

#
# Apache VHost
#
cd ~
echo '<VirtualHost *:80>
        DocumentRoot /var/www/public
        SetEnv APPLICATION_ENV "development"
</VirtualHost>

<Directory "/var/www/public">
        Options Indexes Followsymlinks
        AllowOverride All
        Require all granted
</Directory>
ErrorLog /var/www/logs/error.log
' > vagrant.conf

sudo mv vagrant.conf /etc/apache2/sites-available
sudo a2enmod rewrite

#
# Install PhalconPHP
# Enable it
#
cd ~
git clone --depth=1 git://github.com/phalcon/cphalcon.git
cd cphalcon/build
sudo ./install

echo "extension=phalcon.so" > phalcon.ini
sudo mv phalcon.ini /etc/php5/mods-available
sudo php5enmod phalcon
sudo php5enmod curl

#
# Install PhalconPHP DevTools
#
cd ~
echo '{"require": {"phalcon/devtools": "dev-master"}}' > composer.json
composer install
rm composer.json

sudo mkdir /opt/phalcon-tools
sudo mv ~/vendor/phalcon/devtools/* /opt/phalcon-tools
sudo ln -s /opt/phalcon-tools/phalcon.php /usr/bin/phalcon
sudo rm -rf ~vendor


#
# PHP.ini params edits
#
sudo echo "; ######### PHP.ini modifications from vagrant init.sh #######" >> /etc/php5/apache2/php.ini
sudo echo "error_reporting = E_ALL | E_STRICT" >> /etc/php5/apache2/php.ini
sudo echo "display_errors = On" >> /etc/php5/apache2/php.ini

#
# Reload apache
#
sudo a2ensite vagrant
sudo a2dissite 000-default
sudo service apache2 reload
sudo service apache2 restart
sudo service mongodb restart

#echo -e "----------------------------------------"
#echo -e "To create a Phalcon Project:\n"
#echo -e "----------------------------------------"
#echo -e "$ cd /var/www"
#echo -e "$ phalcon project projectname\n"
#echo -e
#echo -e "Then follow the README.md to copy/paste the VirtualHost!\n"

#echo -e "----------------------------------------"
#echo -e "Default Site: http://192.168.5.0"
#echo -e "----------------------------------------"

####### writable Volt directory
sudo mkdir /vagrant/cache/volt/
sudo chmod 777 /vagrant/cache/volt/

Upvotes: 0

Felix Frank
Felix Frank

Reputation: 8223

Your exec resource uses a $PATH value of /. This is a Very Bad Idea.

Many executables and virtually all shell scripts must rely on core utilities found in /bin, some in /usr/bin. For non-root commands, /bin:/usr/bin is usually a safe choice for the search path, and some scripts for the root user might rely on /sbin:/usr/sbin as well.

Try

exec { '/install_phalcon.sh':
    require => File['/install_phalcon.sh'],
    cwd => '/',
    path => [ '/bin', '/usr/bin' ],
}

Upvotes: 0

Related Questions