Created
March 11, 2019 13:44
-
-
Save marcoris/7dbe5983722d7e2b30d57f01a16b41d5 to your computer and use it in GitHub Desktop.
Vagrant setup with MySQL import
This file contains 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 | |
# Update apt | |
apt-get update -y | |
# Setup apache | |
apt-get install -y apache2 | |
a2enmod rewrite | |
sed -i 's/AllowOverride None/AllowOverride All/' /etc/apache2/sites-available/default | |
rm -rf /var/www | |
ln -fs /vagrant /var/www | |
# Setup PHP (and PEAR) | |
apt-get install -y php5 | |
# Setup MySQL | |
debconf-set-selections <<< 'mysql-server-<version> mysql-server/root_password password password' | |
debconf-set-selections <<< 'mysql-server-<version> mysql-server/root_password_again password password' | |
apt-get install -y mysql-server | |
# Connect PHP and MySQL | |
apt-get install -y php5-mysql | |
# Setup database | |
mysql -uroot -ppassword -e "CREATE DATABASE database;" | |
# Make MySQL external accessible | |
mysql -uroot -ppassword -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password';" | |
mysql -uroot -ppassword -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'password';" | |
sed -i 's/^bind-address/#bind-address/' /etc/mysql/my.cnf | |
sed -i 's/^skip-external-locking/#skip-external-locking/' /etc/mysql/my.cnf | |
sudo service mysql restart | |
# Import bootstrap SQL | |
mysql -uroot -ppassword database < bootstrap.sql | |
# Install Curl | |
apt-get install -y curl php5-curl | |
# Install mcrypt (for Laravel) | |
apt-get install -y php5-mcrypt | |
# Install composer | |
curl -sS http://getcomposer.org/installer | php | |
sudo mv composer.phar /usr/local/bin/composer | |
# Run composer install | |
cd /vagrant && composer install --dev | |
# Run migrations | |
php /vagrant/artisan migrate --seed | |
# Change apache document root | |
sed -i 's#DocumentRoot /var/www#DocumentRoot /var/www/public#' /etc/apache2/sites-available/default | |
sudo service apache2 restart | |
# Output success message | |
echo -e "\nYour machine has been provisioned" | |
echo "--------------------------------" | |
echo "MySQL is available on port 4001 with username 'root' and password 'password' (you have to use 127.0.0.1 as opposed to 'localhost')" | |
echo "Apache is available on port 4000" | |
echo "Head over to http://localhost:4000 to get started" |
This file contains 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
VAGRANTFILE_API_VERSION = "2" | |
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| | |
config.vm.box = "precise32" | |
config.vm.box_url = "http://files.vagrantup.com/precise32.box" | |
config.vm.provision :shell, :path => "bootstrap.sh" | |
config.vm.network :forwarded_port, host: 4000, guest: 80 | |
config.vm.network :forwarded_port, host: 4001, guest: 3306 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment