Last active
January 2, 2016 23:19
-
-
Save xthiago/8375457 to your computer and use it in GitHub Desktop.
Vagrant: LAMP (Ubuntu 12.04 + Apache2 + MySQL 5.5 + PHP 5.5) + nodejs + wkhtmltopdf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
echo ">>> Iniciando script de instalação" | |
sudo apt-get update | |
# Define diretivas que permitirão instalar MySQL sem perguntar senha | |
sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password password root' | |
sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password root' | |
echo ">>> Instalando aplicativos base" | |
# Install base items | |
sudo apt-get install -y vim curl wget build-essential python-software-properties | |
echo ">>> Instalando aplicativos necessários para habilitar vagrant com NFS (melhora desempenho)" | |
# instala o suporte a NFS (sem ele o Vagrant fica uma carroça) | |
# Notas: | |
# - para usarmos Vagrant com NFS é necessário que tanto host quanto guest tenham suporte instalado. | |
# - no host, rode: sudo apt-get install nfs-common nfs-kernel-server portmap (note o nfs-common nfs-kernel-server que o guest não tem) | |
# - embora tenha colocado o pacote 'portmap', o apt-get instalou o pacote 'rpcbind' em seu lugar. | |
sudo apt-get install nfs-common portmap -y | |
echo ">>> Instalando git" | |
sudo apt-get install -y git-core | |
echo ">>> Adicionando PPA's e instalando pacotes do servidor LAMP" | |
# Add repo for latest PHP | |
sudo add-apt-repository -y ppa:ondrej/php5 | |
# Update Again | |
sudo apt-get update | |
# Install the Rest | |
sudo apt-get install -y \ | |
php5 \ | |
apache2 \ | |
libapache2-mod-php5 \ | |
php5-mysql \ | |
php5-curl \ | |
php5-gd \ | |
php5-mcrypt \ | |
php5-xdebug \ | |
mysql-server \ | |
php5-cli \ | |
php5-imagick \ | |
php-pear \ | |
php5-intl | |
#php-apc \ | |
echo ">>> Configurando o servidor" | |
# xdebug Config | |
cat << EOF | sudo tee -a /etc/php5/mods-available/xdebug.ini | |
xdebug.scream=0 | |
xdebug.cli_color=1 | |
xdebug.show_local_vars=1 | |
xdebug.max_nesting_level=250 | |
EOF | |
# Apache Config | |
sudo a2enmod rewrite | |
#sudo cp /etc/apache2/sites-enabled/000-default /etc/apache2/sites-enabled/000-default.old | |
VHOST=$(cat <<EOF | |
<VirtualHost *:80> | |
ServerAdmin webmaster@localhost | |
#ServerName $ServerName | |
DocumentRoot /vagrant | |
<Directory $DocumentRoot> | |
Options -Indexes +FollowSymLinks +MultiViews | |
AllowOverride All | |
Order allow,deny | |
Allow from all | |
Require all granted | |
</Directory> | |
# Possible values include: debug, info, notice, warn, error, crit, | |
# alert, emerg. | |
LogLevel warn | |
CustomLog /var/log/apache/access.log combined | |
ErrorLog /var/log/apache/error.log | |
</VirtualHost> | |
EOF | |
) | |
#echo "${VHOST}" > /etc/apache2/sites-enabled/000-default | |
# PHP Config | |
sed -i "s/error_reporting = .*/error_reporting = E_ALL/" /etc/php5/apache2/php.ini | |
sed -i "s/error_reporting = .*/error_reporting = E_ALL/" /etc/php5/cli/php.ini | |
sed -i "s/display_errors = .*/display_errors = On/" /etc/php5/apache2/php.ini | |
sed -i "s/display_errors = .*/display_errors = On/" /etc/php5/cli/php.ini | |
# -r a baixo é pro sed aceitar ?: http://stackoverflow.com/questions/6156259/sed-expression-dont-allow-optional-grouped-string | |
sed -r -i "s,;?date.timezone =.*,date.timezone = America/Sao_Paulo," /etc/php5/apache2/php.ini | |
sed -r -i "s,;?date.timezone =.*,date.timezone = America/Sao_Paulo," /etc/php5/cli/php.ini | |
#Mysql config | |
sed -i 's/127.0.0.1/0.0.0.0/g' /etc/mysql/my.cnf | |
mysql --password=root -u root --execute="GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION; FLUSH PRIVILEGES;" | |
service mysql restart | |
#Apache config | |
sed -i 's/User ${APACHE_RUN_USER}/User vagrant/g' /etc/apache2/apache2.conf | |
sed -i 's/Group ${APACHE_RUN_GROUP}/Group vagrant/g' /etc/apache2/apache2.conf | |
sudo service apache2 restart | |
echo ">>> wkhtmltopdf (usado pelo Snappy para renderizar PDF)" | |
sudo apt-get install xvfb wkhtmltopdf -y | |
echo ">>> Instalando nodejs" | |
#nodejs (necessário: build-essential g++) | |
mkdir -p /tmp/node | |
curl -sS http://nodejs.org/dist/v0.10.24/node-v0.10.24.tar.gz | tar xz -C /tmp/node | |
cd /tmp/node/node-v0.10.24 | |
./configure | |
make | |
sudo make install | |
## sudo npm config set registry http://registry.npmjs.org/ | |
sudo npm install -g less | |
sudo npm install -g uglify-js | |
sudo npm install -g uglifycss | |
echo ">>> Instalando composer" | |
# Composer | |
curl -sS https://getcomposer.org/installer | php | |
sudo mv composer.phar /usr/local/bin/composer | |
echo ">>> Inicializando aplicação" | |
# configura diretorio da aplicacao | |
sudo rm -rf /var/www/ | |
sudo ln -sf /vagrant/web /var/www | |
sudo chown www-data.www-data /vagrant -R | |
# inicializando aplicacao | |
cd /vagrant/ | |
rm -rf app/cache/* | |
rm -rf app/logs/* | |
chmod 777 -R app/cache/ | |
chmod 777 -R app/logs/ | |
#composer install | |
echo "<?php phpinfo(); ?>" > /vagrant/web/info.php |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
VAGRANTFILE_API_VERSION = "2" | |
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| | |
config.vm.box = "ubuntu1204-64" | |
config.vm.provision :shell, :path => "bootstrap.sh" | |
config.vm.network :forwarded_port, host: 2015, guest: 80 | |
config.vm.hostname = "yourhostname" | |
#config.vm.synced_folder ".", "/vagrant", type: "nfs" | |
config.vm.network "private_network", ip: "10.0.1.10" | |
config.vm.provider :virtualbox do |virtualbox| | |
virtualbox.customize ["modifyvm", :id, "--memory", "2048"] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment