使用Vagrant / Puppet安装Phalcon(找不到git命令)

时间:2014-08-13 14:11:49

标签: php shell vagrant puppet phalcon

我成功设置了Vagrant / Puppet配置,用nginx,mysql,php5-fpm等安装基本的hashicorp / precise64服务器。服务器启动,我可以毫无问题地使用PHP(网页可以访问) )。

然而,Phalcon给了我一些问题。我创建了一个简单的shell脚本(比如install.sh),其中包含以下内容:

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

将此shell脚本复制到linux服务器的根目录,然后使用以下Puppet命令执行:

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

它开始执行shell脚本,但它不会出现" git命令未找到"等错误。我以前用#34; cp"等命令看过这个。和" ln"。

当您登录流浪汉VM时,请使用" sudo su"然后执行shell脚本,一切顺利。

我做错了什么,这是权利问题吗?如何在Vagrant / Puppet中解决它?

谢谢!

2 个答案:

答案 0 :(得分:0)

您的exec资源使用$PATH/。这是一个非常糟糕的主意。

许多可执行文件和几乎所有 shell脚本必须依赖于/bin中的核心实用程序,/usr/bin中的某些核心实用程序。对于非root命令,/bin:/usr/bin通常是搜索路径的安全选择,root用户的某些脚本也可能依赖/sbin:/usr/sbin

尝试

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

答案 1 :(得分:0)

我可以分享我的流浪汉并安装文件。我使用Phalcon和Ubuntu。它适用于Mac,Windows和Ubuntu机器上的任何问题。

Vagrantfile文件(文件名只是“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

和安装文件(文件名是“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/