diff --git a/README.markdown b/README.markdown index 9175e3b..df749cd 100644 --- a/README.markdown +++ b/README.markdown @@ -1,6 +1,6 @@ -# Vagrant Box with Ubuntu 14.04, Nginx, MySQL and PHP-FPM +# Vagrant Box with Ubuntu 18.04, Nginx, MySQL and PHP-FPM -A Vagrant setup to create an Ubuntu 14.04 (Trusty) virtual machine with Nginx, MySQL and PHP for WordPress development. +A Vagrant setup to create an Ubuntu 18.04 (Bionic) virtual machine with Nginx, MySQL and PHP for WordPress development. Intended to be as simple as possible: @@ -9,7 +9,7 @@ Intended to be as simple as possible: * Quickly create a fresh WP instance served up via the Vagrant server. * Optionally specify which version of WP to install -* Choose PHP 5.5, 5.6 or 7.0 +* Choose PHP 5.6, 7.0, 7.1, 7.2, or 7.3 * Can be dropped into an existing WP directory to provide a LEMP testing and development server with minimal config changes * Can load database dump as part of provisioning * Renames all domain references using WP-CLI @@ -22,10 +22,10 @@ This Vagrant box and provisioning is based on [this box from Paul Herron](https: ## What's included in the VM? -* Ubuntu 14.04 LTS (Trusty Tahir) +* Ubuntu 18.04 LTS (Bionic Beaver) (https://app.vagrantup.com/ubuntu/boxes/bionic64) * Nginx, listening on port 80 * MySQL, listening for remote connections -* Choose between PHP 5.5, 5.6 or 7.0, with OpCache and XDebug +* Choose between PHP 5.6, 7.0, 7.1, 7.2, or 7.3, with OpCache and XDebug * PHP-FPM * [Byobu](http://byobu.co/) * [WP-CLI](wp-cli.org) @@ -82,8 +82,10 @@ Use these intructions if you have an existing WP install 1. Clone the wp-vagrant repo * `git clone git@github.com:digitalquery/wp-vagrant.git` * This creates a subfolder called `wp-vagrant` -1. Copy the VagrantFile into the site root directory +1. Copy the `Vagrantfile` into the site root directory * `cp wp-vagrant/Vagrantfile .` + * Or alternatively, create a symbolic link: + * `ln -s wp-vagrant/Vagrantfile Vagrantfile` 1. If you want to import a database during the provisioning, then put a SQL dump file into the `wp-vagrant` folder. **This file must have a .sql extension** 1. Using your editor of choice, edit `wp-vagrant/settings.sh` * `install_wordpress=false ` @@ -104,17 +106,17 @@ Use these intructions if you have an existing WP install ### PHP version -To change the PHP version, edit `settings.sh` and set the `php_version` setting to 5.5, 5.6 or 7.0. Run `vagrant provision` if you're changing an already created vagrant instance +To change the PHP version, edit `settings.sh` and set the `php_version` setting to 5.6, 7.0, 7.1, 7.2, or 7.3. Run `vagrant provision` if you're changing an already created vagrant instance ### Settings.sh -The full list - more comments and explanation are in the `settings.sh`file itself. +The full list - more comments and explanation are in the `settings.sh`file itself. ##### Basic Settings -* `hostname='wpvagrant.dev' # change this in the Vagrantfile as well` -* `php_version='7.0' # valid values: '5.5', '5.6' or '7.0'` +* `hostname='wpvagrant.test' # change this in the Vagrantfile as well` +* `php_version='7.2' # valid values: '5.6', '7.0', '7.1', '7.2', or '7.3'` * `install_wordpress=true # change to false if this is being dropped in to an existing WP folder ` -* `wp_version="" # eg wp_version="3.5.2 or 4.0-beta1". Leave blank for latest stable release` +* `wp_version="" # eg wp_version="3.5.2 or 4.0-beta1". Leave blank for latest stable release` * `wp_path='/vagrant'` * `mysql_root_password='root'` @@ -126,7 +128,7 @@ The full list - more comments and explanation are in the `settings.sh`file itsel ##### WP admin and site setup details * `wp_admin_user='admin'` * `wp_admin_password='123'` -* `wp_admin_email='root@example.com'` +* `wp_admin_email='root@wpvagrant.test'` * `wp_site_title='Vagrant'` ##### Database import diff --git a/Vagrantfile b/Vagrantfile index 498a172..9b5817d 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -10,11 +10,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| # please see the online documentation at vagrantup.com. # Every Vagrant virtual environment requires a box to build off of. - config.vm.box = "digitalquery/wpvagrant" - - # The url from where the 'config.vm.box' box will be fetched if it - # doesn't already exist on the user's system. - # config.vm.box_url = "https://vagrantcloud.com/ubuntu/trusty64" + config.vm.box = "ubuntu/bionic64" # Create a forwarded port mapping which allows access to a specific port # within the machine from a port on the host machine. In the example below, @@ -55,21 +51,20 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| end config.vm.network "private_network", ip: "192.168.50.2" - config.vm.hostname = "wpvagrant.dev" + config.vm.hostname = "wpvagrant.test" config.hostsupdater.remove_on_suspend = true # Vagrant triggers - config.trigger.before :destroy, :stdout => true do - info "Dumping the database before destroying the VM..." - run "vagrant ssh -c 'sh /vagrant/wp-vagrant/mysql/db_dump.sh'" + config.trigger.before :destroy do |trigger| + trigger.info = "Dumping the database before destroying the VM..." + trigger.run_remote = {inline: "sh /vagrant/wp-vagrant/mysql/db_dump.sh"} end # provisioning script provisioning_file = 'wp-vagrant/bootstrap.sh' if ( File.file?(provisioning_file) ) - config.vm.provision "shell" do |s| - s.path = provisioning_file - end + config.vm.provision "shell", + inline: ". /vagrant/wp-vagrant/bootstrap.sh" end end diff --git a/bootstrap.sh b/bootstrap.sh index f9caa1e..8bd9aa9 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -5,16 +5,17 @@ # . /vagrant/wp-vagrant/settings.sh -debconf-set-selections <<< "mysql-server-5.5 mysql-server/root_password password $mysql_root_password" -debconf-set-selections <<< "mysql-server-5.5 mysql-server/root_password_again password $mysql_root_password" +# https://serversforhackers.com/c/installing-mysql-with-debconf +debconf-set-selections <<< "mysql-server mysql-server/root_password password $mysql_root_password" +debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $mysql_root_password" -# default packages (php, mysql, nginx, etc), are preinstalled in the base box -# update anyway, and also make sure php-mbstring is installed -# we'll move this into the base box next update +add-apt-repository -y ppa:ondrej/php +add-apt-repository -y ppa:ondrej/nginx-mainline apt-get update apt-get upgrade -apt-get install php-mbstring php7.0-mbstring php5.5-mbstring php5.6-mbstring -y + +apt-get install -y nginx php${php_version} php${php_version}-fpm php${php_version}-gd php${php_version}-mysql php${php_version}-cgi php${php_version}-cli php${php_version}-curl php${php_version}-mbstring ffmpeg vim git-core mysql-server mysql-client curl tmux echo "**** add byobu config" . /vagrant/wp-vagrant/configs/byobu.sh @@ -23,8 +24,7 @@ echo "**** Moving nginx config files into place…" . /vagrant/wp-vagrant/nginx/nginx.sh echo "**** mysql config…" -mv /etc/mysql/my.cnf /etc/mysql/my.cnf.default -cp /vagrant/wp-vagrant/mysql/my.cnf /etc/mysql/my.cnf +. /vagrant/wp-vagrant/mysql/mysql.sh echo "**** Set PHP to ${php_version} and copy config files" . /vagrant/wp-vagrant/php/php.sh @@ -32,10 +32,6 @@ echo "**** Set PHP to ${php_version} and copy config files" echo "Starting services…" service nginx restart -service php5.5-fpm stop -service php5.6-fpm stop -service php7.0-fpm stop - service php${php_version}-fpm restart service mysql restart diff --git a/mysql/create_database.sh b/mysql/create_database.sh index ec1fb34..926a999 100644 --- a/mysql/create_database.sh +++ b/mysql/create_database.sh @@ -6,11 +6,11 @@ if [ ! -z $wp_db_name ] ; then echo "**** creating database" - mysql -u root -p$mysql_root_password -e "CREATE DATABASE IF NOT EXISTS $wp_db_name;" + mysql --defaults-extra-file=~/.mysql_root.cnf -e "CREATE DATABASE IF NOT EXISTS $wp_db_name;" if [ ! -z "$wp_db_user" ]; then echo "**** adding custom user" - mysql -u root -p$mysql_root_password -e "GRANT ALL ON $wp_db_name.* TO '$wp_db_user'@'localhost' IDENTIFIED BY '$wp_db_password'" + mysql --defaults-extra-file=~/.mysql_root.cnf -e "GRANT ALL ON $wp_db_name.* TO '$wp_db_user'@'localhost' IDENTIFIED BY '$wp_db_password'" fi else diff --git a/mysql/db_dump.sh b/mysql/db_dump.sh index c007f4d..8a68a92 100644 --- a/mysql/db_dump.sh +++ b/mysql/db_dump.sh @@ -22,7 +22,7 @@ if [ ! -z $wp_db_name ]; then mkdir /vagrant/wp-vagrant/db_dumps fi - mysqldump -u root --password=$mysql_root_password $wp_db_name > /vagrant/wp-vagrant/db_dumps/$db_dump_file + mysqldump --defaults-extra-file=~/.mysql_root.cnf $wp_db_name > /vagrant/wp-vagrant/db_dumps/$db_dump_file if [ ! "$?" -eq 0 ]; then echo "***** DATABASE DUMP FAILED - YOU MAY WISH TO ABORT VAGRANT DESTROY." diff --git a/mysql/import_database.sh b/mysql/import_database.sh index 533e79b..c323478 100644 --- a/mysql/import_database.sh +++ b/mysql/import_database.sh @@ -17,7 +17,7 @@ if [ ! -z $wp_db_name ] && $import_database; then echo "**** SQL file found - proceeding with import" wp_db_dump_file=$(find /vagrant/wp-vagrant -maxdepth 1 -name '*.sql') echo "**** import filename is: $wp_db_dump_file" - mysql -u root -p$mysql_root_password $wp_db_name < $wp_db_dump_file + mysql --defaults-extra-file=~/.mysql_root.cnf $wp_db_name < $wp_db_dump_file if [ ! -z $import_site_domain ]; then echo "**** wp-cli search and replace" diff --git a/mysql/my.cnf b/mysql/my.cnf deleted file mode 100644 index 56f3229..0000000 --- a/mysql/my.cnf +++ /dev/null @@ -1,127 +0,0 @@ -# -# The MySQL database server configuration file. -# -# You can copy this to one of: -# - "/etc/mysql/my.cnf" to set global options, -# - "~/.my.cnf" to set user-specific options. -# -# One can use all long options that the program supports. -# Run program with --help to get a list of available options and with -# --print-defaults to see which it would actually understand and use. -# -# For explanations see -# http://dev.mysql.com/doc/mysql/en/server-system-variables.html - -# This will be passed to all mysql clients -# It has been reported that passwords should be enclosed with ticks/quotes -# escpecially if they contain "#" chars... -# Remember to edit /etc/mysql/debian.cnf when changing the socket location. -[client] -port = 3306 -socket = /var/run/mysqld/mysqld.sock - -# Here is entries for some specific programs -# The following values assume you have at least 32M ram - -# This was formally known as [safe_mysqld]. Both versions are currently parsed. -[mysqld_safe] -socket = /var/run/mysqld/mysqld.sock -nice = 0 - -[mysqld] -# -# * Basic Settings -# -user = mysql -pid-file = /var/run/mysqld/mysqld.pid -socket = /var/run/mysqld/mysqld.sock -port = 3306 -basedir = /usr -datadir = /var/lib/mysql -tmpdir = /tmp -lc-messages-dir = /usr/share/mysql -skip-external-locking -# -# Instead of skip-networking the default is now to listen only on -# localhost which is more compatible and is not less secure. -bind-address = 0.0.0.0 -# -# * Fine Tuning -# -key_buffer_size = 16M -max_allowed_packet = 16M -thread_stack = 192K -thread_cache_size = 8 -# This replaces the startup script and checks MyISAM tables if needed -# the first time they are touched -myisam-recover = BACKUP -#max_connections = 100 -#table_cache = 64 -#thread_concurrency = 10 -# -# * Query Cache Configuration -# -query_cache_limit = 1M -query_cache_size = 16M -# -# * Logging and Replication -# -# Both location gets rotated by the cronjob. -# Be aware that this log type is a performance killer. -# As of 5.1 you can enable the log at runtime! -#general_log_file = /var/log/mysql/mysql.log -#general_log = 1 -# -# Error log - should be very few entries. -# -log_error = /var/log/mysql/error.log -# -# Here you can see queries with especially long duration -#log_slow_queries = /var/log/mysql/mysql-slow.log -#long_query_time = 2 -#log-queries-not-using-indexes -# -# The following can be used as easy to replay backup logs or for replication. -# note: if you are setting up a replication slave, see README.Debian about -# other settings you may need to change. -#server-id = 1 -#log_bin = /var/log/mysql/mysql-bin.log -expire_logs_days = 10 -max_binlog_size = 100M -#binlog_do_db = include_database_name -#binlog_ignore_db = include_database_name -# -# * InnoDB -# -# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/. -# Read the manual for more InnoDB related options. There are many! -# -# * Security Features -# -# Read the manual, too, if you want chroot! -# chroot = /var/lib/mysql/ -# -# For generating SSL certificates I recommend the OpenSSL GUI "tinyca". -# -# ssl-ca=/etc/mysql/cacert.pem -# ssl-cert=/etc/mysql/server-cert.pem -# ssl-key=/etc/mysql/server-key.pem - - - -[mysqldump] -quick -quote-names -max_allowed_packet = 16M - -[mysql] -#no-auto-rehash # faster start of mysql but no tab completition - -[isamchk] -key_buffer_size = 16M - -# -# * IMPORTANT: Additional settings that can override those from this file! -# The files must end with '.cnf', otherwise they'll be ignored. -# -!includedir /etc/mysql/conf.d/ diff --git a/mysql/mysql.sh b/mysql/mysql.sh new file mode 100644 index 0000000..510d9b0 --- /dev/null +++ b/mysql/mysql.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +cp /etc/mysql/mysql.conf.d/mysqld.cnf /etc/mysql/mysql.conf.d/mysqld.cnf.default + +# Allow access from host machine (digitalquery#21) +sed -i 's/bind-address[[:space:]]\+= 127\.0\.0\.1/bind-address = 0.0.0.0/' /etc/mysql/mysql.conf.d/mysqld.cnf + +# https://stackoverflow.com/a/22933056/2603230 +echo "[client] +user = root +password = $mysql_root_password +host = localhost +" > ~/.mysql_root.cnf diff --git a/nginx/default.conf b/nginx/default.conf index 8dd78b6..c0326eb 100644 --- a/nginx/default.conf +++ b/nginx/default.conf @@ -33,6 +33,7 @@ server { fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php/php%%php_version%%-fpm.sock; fastcgi_index index.php; - include fastcgi_params; + # https://stackoverflow.com/a/16887296/2603230 + include fastcgi.conf; } } diff --git a/nginx/nginx.sh b/nginx/nginx.sh index 28a4cee..aa9525a 100644 --- a/nginx/nginx.sh +++ b/nginx/nginx.sh @@ -1,5 +1,8 @@ #!/usr/bin/env bash +# Start after boot +sudo update-rc.d nginx enable + # copy nginx config cp /vagrant/wp-vagrant/nginx/nginx.conf /etc/nginx/ diff --git a/settings.sh b/settings.sh index eda5443..e25d867 100644 --- a/settings.sh +++ b/settings.sh @@ -8,14 +8,16 @@ # this is hostname for the vagrant box # make sure to change it in the Vagrantfile as well -hostname='wpvagrant.dev' +hostname='wpvagrant.test' # PHP version to install # valid values: -# 5.5 # 5.6 # 7.0 -php_version='7.0' +# 7.1 +# 7.2 +# 7.3 +php_version='7.2' # specify path (inside the Vagrant VM) to WordPress to allow wp-cli to do search and replace # shouldn't need to change this from /vagrant unless you've made other config changes @@ -65,7 +67,7 @@ wp_db_password='' wp_admin_user='admin' wp_admin_password='123' -wp_admin_email='root@example.com' +wp_admin_email='root@wpvagrant.test' wp_site_title='WP Vagrant' # diff --git a/wp/wp-cli.sh b/wp/wp-cli.sh index 8d9d0ce..bc15ce6 100644 --- a/wp/wp-cli.sh +++ b/wp/wp-cli.sh @@ -4,6 +4,12 @@ if [ -f /usr/local/bin/wp ]; then echo "**** updating wp-cli" sudo wp cli update --allow-root --yes +else + echo "**** installing wp-cli" + cd ~/ + curl -Os https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar + chmod +x wp-cli.phar + sudo mv wp-cli.phar /usr/local/bin/wp fi wpcli_defaults_folder='/home/vagrant/.wp-cli'