Last active
September 30, 2020 15:19
-
-
Save ronanmccoy/b20b6301848783066a6b23e95def5999 to your computer and use it in GitHub Desktop.
A vagrantfile and provisions script for a local LAMP development environment. This installs PHP7.2, MySQL, and Apache. The provision script also includes additional services that can be installed. The VM is configured to run a single site from /var/www/html/ in the the guest (which is mapped to ./webroot).
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 | |
###################################################################### | |
## READ ME | |
## Review the script before running it. Uncomment any additional | |
## packages/settings needed, and comment out what is not needed. | |
## | |
## What is uncommented here by default represents my own standard | |
## settings. | |
###################################################################### | |
echo -e "\n\n============================================\n" | |
echo -e "Begin provisioning.\n" | |
echo -e "============================================\n\n" | |
echo -e " --> Updating the server.\n\n" | |
sudo apt-get update >/dev/null 2>&1 | |
sudo apt-get upgrade >/dev/null 2>&1 | |
echo -e "\n --> Installing cURL.\n\n" | |
sudo apt-get install -y curl >/dev/null 2>&1 | |
echo -e "\n --> Installing MySQL tools.\n\n" | |
sudo apt-get install -y mysql-client >/dev/null 2>&1 | |
# echo -e "\n --> Installing Htop, a process monitoring tool.\n\n" | |
# sudo apt-get install -y htop >/dev/null 2>&1 | |
# echo -e "\n --> Installing git and git-flow \n\n" | |
# sudo apt-get install -y git >/dev/null 2>&1 | |
# sudo apt-get install -y git-flow >/dev/null 2>&1 | |
# echo -e "\n --> Installing make. \n\n" | |
# sudo apt-get install -y make >/dev/null 2>&1 | |
# echo -e "\n --> Installing vim. \n\n" | |
# sudo apt-get install -y vim >/dev/null 2>&1 | |
# echo -e "\n --> Installing SASL libraries. \n\n" | |
# sudo apt-get install -y libsasl2-dev >/dev/null 2>&1 | |
# echo -e "\n --> Installing redis. \n\n" | |
# sudo apt-get install -y redis-server >/dev/null 2>&1 | |
# echo -e "\n --> Installing memcached. \n\n" | |
# sudo apt-get install -y memcached >/dev/null 2>&1 | |
# echo -e "\n --> Installing wget. \n\n" | |
# sudo apt-get install -y wget >/dev/null 2>&1 | |
# echo -e "\n --> Installing GZip.\n\n" | |
# sudo apt-get install -y gzip >/dev/null 2>&1 | |
## If using nginx, uncomment this and comment out the 'apache' stuff that follows. | |
# echo -e "\n --> Installing NGINX. \n\n" | |
# sudo apt-get install -y nginx | |
# sudo service nginx start | |
## if using apache, this should be uncommented, and commet out the 'nginx' stuff above. | |
echo -e "\n --> Installing Apache.\n\n" | |
sudo apt-get install -y apache2 >/dev/null 2>&1 | |
echo "ServerName localhost" >> /etc/apache2/apache2.conf | |
## In some cases PHP7.1 might be better suited, in which case simply change 7.2 to 7.1 should suffice. | |
echo -e "\n --> Installing PHP 7.2 and common modules.\n\n" | |
sudo apt-get install -y python-software-properties >/dev/null 2>&1 | |
sudo add-apt-repository -y ppa:ondrej/php >/dev/null 2>&1 | |
sudo apt-get update >/dev/null 2>&1 | |
sudo apt-get install -y php7.2 >/dev/null 2>&1 | |
sudo apt-get install -y php-pear >/dev/null 2>&1 | |
sudo apt-get install -y php7.2-curl >/dev/null 2>&1 | |
sudo apt-get install -y php7.2-dev >/dev/null 2>&1 | |
sudo apt-get install -y php7.2-gd >/dev/null 2>&1 | |
sudo apt-get install -y php7.2-mbstring >/dev/null 2>&1 | |
sudo apt-get install -y php7.2-zip >/dev/null 2>&1 | |
sudo apt-get install -y php7.2-mysql >/dev/null 2>&1 | |
sudo apt-get install -y php7.2-xml >/dev/null 2>&1 | |
# sudo apt-get install -y php7.2-cli >/dev/null 2>&1 | |
# sudo apt-get install -y php7.2-memcached >/dev/null 2>&1 | |
# sudo apt-get install -y php7.2-redis >/dev/null 2>&1 | |
# sudo apt-get install -y php7.2-imagick >/dev/null 2>&1 | |
# sudo apt-get install -y php7.2-gmp >/dev/null 2>&1 | |
# sudo apt-get install -y php7.2-json >/dev/null 2>&1 | |
# sudo apt-get install -y php7.2-mcrypt >/dev/null 2>&1 | |
# sudo apt-get install -y php7.2-mongodb >/dev/null 2>&1 | |
# sudo apt-get install -y php7.2-mysql >/dev/null 2>&1 | |
# sudo apt-get install -y php7.2-odbc >/dev/null 2>&1 | |
# sudo apt-get install -y php7.2-pgsql >/dev/null 2>&1 | |
# sudo apt-get install -y php7.2-sqlite3 >/dev/null 2>&1 | |
# sudo apt-get install -y php7.2-xsl >/dev/null 2>&1 | |
echo -e "\n --> Installing MySQL server and configure it to use 'root' as password.\n\n" | |
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' | |
sudo apt-get -q -y install mysql-server >/dev/null 2>&1 | |
ROOT_DB_PASSWORD="mypass" | |
echo -e "\n --> Update MySQL configuration to make it accessible from host via root.\n" | |
echo -e "--> NOTE THAT THIS IS NOT SECURE AND FOR DEVELOPMENT ONLY!!!!!!!!!!!\n\n" | |
sed -i -e 's/127.0.0.1/0.0.0.0/' /etc/mysql/mysql.conf.d/mysqld.cnf | |
SQL="GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mypass' WITH GRANT OPTION; FLUSH PRIVILEGES;" | |
mysql -uroot -p${ROOT_DB_PASSWORD} -e "${SQL}" | |
## Modify the timezone as needed. | |
echo -e "\n --> Set timezone for MySQL to 'America/Los_Angeles'. \n\n" | |
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -uroot -p${ROOT_DB_PASSWORD} mysql | |
sudo sed -ri '/\[mysqld\]/ a\ default-time-zone = \x27America/Los_Angeles\x27' /etc/mysql/mysql.conf.d/mysqld.cnf | |
echo -e "\n --> Restarting services. \n\n" | |
sudo service mysql restart | |
sudo service apache2 reload | |
# echo -e "\n --> Installing Composer.\n\n" | |
# sudo curl -s https://getcomposer.org/installer | php | |
# sudo mv composer.phar /usr/local/bin/composer | |
# Set timezone (modify this if needed). | |
echo -e "\n --> Configuring time zone for the server. \n\n" | |
sudo timedatectl set-timezone America/Los_Angeles | |
# Set up sync'ing for time. | |
sudo apt-get install -y ntp >/dev/null 2>&1 | |
## | |
## Additional services that are not needed but may help in managing the server. | |
## Note that for webmin specifically, a port needs to be forwarded for it to work. | |
## | |
## WEBMIN | |
## ref.: https://doxfer.webmin.com/Webmin/Installation#apt-get_.28Debian.2FUbuntu.2FMint.29 | |
## IMPORTANT: Make sure wget is being installed above. Credentials for webmin should be vagrant/vagrant. | |
## | |
# echo -e "\n --> Installing Webmin.\n\n" | |
# sudo sh -c 'echo "deb http://download.webmin.com/download/repository sarge contrib" > /etc/apt/sources.list.d/webmin.list' | |
# sudo wget -qO - http://www.webmin.com/jcameron-key.asc | sudo apt-key add - | |
# sudo apt-get update | |
# sudo apt-get install -y webmin >/dev/null 2>&1 | |
## | |
## PHPMYAdmin | |
## IMPORTANT: access php my admin using /phpmyadmin, and credentials are the same as mysql. | |
## | |
# echo -e "\n --> Installing PHPMyAdmin. \n\n" | |
# sudo debconf-set-selections <<< 'phpmyadmin phpmyadmin/dbconfig-install boolean true' | |
# sudo debconf-set-selections <<< 'phpmyadmin phpmyadmin/app-password-confirm password ${ROOT_DB_PASSWORD}' | |
# sudo debconf-set-selections <<< 'phpmyadmin phpmyadmin/mysql/admin-pass password ${ROOT_DB_PASSWORD}' | |
# sudo debconf-set-selections <<< 'phpmyadmin phpmyadmin/mysql/app-pass password ${ROOT_DB_PASSWORD}' | |
# sudo debconf-set-selections <<< 'phpmyadmin phpmyadmin/reconfigure-webserver multiselect apache2' | |
# | |
# sudo apt-get install -y phpmyadmin >/dev/null 2>&1 | |
# sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/sites-enabled/phpmyadmin.conf | |
# sudo service apache2 restart | |
## | |
## Elastic Search | |
## IMPORTANT: this may involve some work to get elastic search working correctly. | |
## see https://www.elastic.co/guide/en/elasticsearch/reference/current/deb.html#deb-repo | |
## | |
# echo -e "\n --> Installing Java 8 and ElasticSearch. \n\n" | |
# sudo apt-add-repository ppa:webupd8team/java >/dev/null 2>&1 | |
# sudo apt-get update >/dev/null 2>&1 | |
# echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections | |
# sudo apt-get install -y -q oracle-java8-installer >/dev/null 2>&1 | |
# | |
# sudo apt-get install -y apt-transport-https >/dev/null 2>&1 | |
# echo "deb https://artifacts.elastic.co/packages/6.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-6.x.list | |
# sudo apt-get update >/dev/null 2>&1 | |
# sudo apt-get -y install elasticsearch >/dev/null 2>&1 | |
## Update binding to access elasticsearch from outside the VM | |
# sudo su - # switches to root (see last few comments of https://gist.github.com/maxivak/c318fd085231b9ab934e631401c876b1) | |
# sudo echo "network.host: 0.0.0.0" >> /etc/elasticsearch/elasticsearch.yml # ref. https://qbox.io/blog/qbox-a-vagrant-virtual-machine-for-elasticsearch-2-x. | |
# | |
## Enable CORS for elasticsearch: not secure, this basically allows any source to access this instance of elasticsearch. | |
# sudo echo "http.cors.enabled: true" >> /etc/elasticsearch/elasticsearch.yml | |
# sudo echo "http.cors.allow-origin: /https?:\/\/.*/" >> /etc/elasticsearch/elasticsearch.yml | |
# | |
## restart/start elasticsearch. | |
# sudo /etc/init.d/elasticsearch restart | |
# | |
## Set elasticsearch to start automatically. | |
# sudo /bin/systemctl daemon-reload | |
# sudo /bin/systemctl enable elasticsearch.service | |
# echo -e "Check that elasticsearch is running by trying 'curl http://localhost:9200/?pretty' from guest environ. \n\n" | |
## Note: this should return some JSON. | |
echo -e "\n --> Done \n\n" | |
echo -e "============================================ \n" | |
echo -e "Finished provisioning.\n" | |
echo -e "============================================\n\n" | |
echo -e "\n\n" |
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
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
# All Vagrant configuration is done below. The "2" in Vagrant.configure | |
# configures the configuration version (we support older styles for | |
# backwards compatibility). Please don't change it unless you know what | |
# you're doing. | |
Vagrant.configure("2") do |config| | |
config.vm.box = "ubuntu/xenial64" | |
config.vm.network "forwarded_port", guest: 22, host: 2209 ## SSH | |
config.vm.network "forwarded_port", guest: 3306, host: 3309 ## MySQL (allows access to mysql from the host, change the host port to any available port) | |
# config.vm.network "forwarded_port", guest: 10000, host: 10000 ## Webmin, in case needed. | |
# config.vm.network "forwarded_port", guest: 9200, host: 9201 ## Elastic Search (the REST API) if needed. | |
config.vm.network "private_network", ip: "192.168.33.10" ## This can be whatever you want on 192.168.xxx.xxx net. | |
config.vm.synced_folder "webroot", "/var/www/html" ## access the default webroot on the guest from the host, where 'webroot' is a directory that exists on the same level as this vagrantfile, in this case. | |
config.vm.provider "virtualbox" do |vb| | |
# vb.name = "add name of the vm to be seen in virtualbox gui." ## TODO: put a name to your VM here, or delete this line if a specific VM name is not important. | |
# vb.memory = "4096" ## to bump the memory available for the VM. | |
end | |
config.vm.provision :shell, path: "provision.sh" ## the provision file to run after the VM is ready. | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment