Skip to content

Commit

Permalink
Merge branch 'master' of github.com:digitalquery/wp-vagrant
Browse files Browse the repository at this point in the history
  • Loading branch information
anugupta committed Jun 5, 2016
2 parents 2cbf388 + 5e55ecd commit ac7ebb4
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 44 deletions.
22 changes: 13 additions & 9 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +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
* 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
Expand All @@ -24,9 +25,8 @@ This Vagrant box and provisioning is based on [this box from Paul Herron](https:
* Ubuntu 14.04 LTS (Trusty Tahir)
* Nginx, listening on port 80
* MySQL, listening for remote connections
* PHP 5.5, with OpCache and XDebug
* Choose between PHP 5.5, 5.6 or 7.0, with OpCache and XDebug
* PHP-FPM
* PHP-Unit
* [Byobu](http://byobu.co/)
* [WP-CLI](wp-cli.org)
* APCu
Expand Down Expand Up @@ -71,7 +71,7 @@ Use these instructions if you want to create a new WP site with the default empt
1. Fire up Vagrant to create the VM and then run the provisioning scripts
* `vagrant up`
* This may take a little while as the provisioning scripts download and install everything
1. Browse to `http://wpvagrant.dev` - you should see the default twentyfourteen theme
1. Browse to your hostname - you should see the default twentyfourteen theme


### Existing WP install
Expand All @@ -98,19 +98,23 @@ Use these intructions if you have an existing WP install
* set to true if you want to import a database ( and have a SQL dump file in the wp-vagrant folder)
* `import_site_domain=''`
* Put the domain that you were using, this should be the same domain as the database dump.
* We will search for this domain in the database and change it to `wpvagrant.dev`
* We will search for this domain in the database and change it to $hostname
1. `vagrant up`
1. Browse to `http://wpvagrant.dev` - and you should see your site up and running
1. Browse to your hostname - and you should see your site up and running

### 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

### Settings.sh

The full list.
The full list - more comments and explanation are in the `settings.sh`file itself.

##### Basic Settings

* `install_wordpress=true`
* `wp_version=""`
* `hostname='wpvagrant.dev' # change this in the Vagrantfile as well`
* `php_version='7.0' # valid values: '5.5', '5.6' or '7.0'`
* `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_path='/vagrant'`
* `mysql_root_password='root'`

Expand Down
23 changes: 9 additions & 14 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

# 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_url = "https://vagrantcloud.com/ubuntu/trusty64"

# 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,
Expand Down Expand Up @@ -42,22 +42,18 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
#
config.vm.provider :virtualbox do |vb|
# Don't boot with headless mode
# vb.gui = true

# Set VM memory to 512MB
# Set VM memory size
vb.customize ["modifyvm", :id, "--memory", "512"]


# these 2 commands massively speed up DNS resolution, which means outbound
# connections don't take forever (eg the WP admin dashboard and update page)
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]

end

config.vm.provision :shell, :path => "wp-vagrant/bootstrap.sh"
config.vm.network "private_network", ip: "192.168.50.2"
config.vm.hostname = "wpvagrant.dev"
config.hostsupdater.remove_on_suspend = true
Expand All @@ -66,14 +62,13 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
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'"

end



#config.vm.provider :virtualbox do |vb|
#vb.customize ["modifyvm", :id, "--memory", "1024"]
#vb.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root", "1"]
#end
# provisioning script
if ( provisioning_file = File.file?('wp-vagrant/bootstrap.sh') )
config.vm.provision "shell" do |s|
s.path = provisioning_file
end
end

end
21 changes: 9 additions & 12 deletions bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@
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"

# have taken a decision not to update this by default
# all this provisioning has been moved into the base box setup (digitalquery/wpvagrant)

# apt-get update && apt-get upgrade -y
# apt-get install -qy nginx php5 php5-fpm php5-apcu php5-gd php5-mysql php5-cgi php5-cli php5-curl php5-xdebug phpunit vim git-core mysql-server-5.5 mysql-client curl byobu

# default packages (php, mysql, nginx, etc), are preinstalled in the base boxs

echo "**** add byobu config"
. /vagrant/wp-vagrant/configs/byobu.sh
Expand All @@ -25,15 +20,17 @@ echo "**** mysql config…"
mv /etc/mysql/my.cnf /etc/mysql/my.cnf.default
cp /vagrant/wp-vagrant/mysql/my.cnf /etc/mysql/my.cnf

echo "**** Moving php config files into place…"
mv /etc/php5/fpm/php.ini /etc/php5/fpm/php.ini.default
cp /vagrant/wp-vagrant/php/php.ini /etc/php5/fpm/php.ini
sudo cp /vagrant/wp-vagrant/php/20-xdebug.ini /etc/php5/fpm/conf.d/
cp /vagrant/wp-vagrant/php/www.conf /etc/php5/fpm/pool.d/
echo "**** Set PHP to ${php_version} and copy config files"
. /vagrant/wp-vagrant/php/php.sh


echo "Starting services…"
service nginx restart
service php5-fpm 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


Expand Down
2 changes: 1 addition & 1 deletion mysql/import_database.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ if [ ! -z $wp_db_name ] && $import_database; then

if [ ! -z $import_site_domain ]; then
echo "**** wp-cli search and replace"
wp --path=$wp_path --allow-root search-replace $import_site_domain wpvagrant.dev
wp --path=$wp_path --allow-root search-replace $import_site_domain $hostname
fi

;;
Expand Down
4 changes: 2 additions & 2 deletions nginx/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ server {
#max file upload size limit
client_max_body_size 20M;

server_name wpvagrant.dev 192.168.2.50;
server_name %%hostname%% 192.168.2.50;

location / {
try_files $uri $uri/ /index.php?$args;
Expand All @@ -31,7 +31,7 @@ server {
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_pass unix:/var/run/php/php%%php_version%%-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
Expand Down
9 changes: 8 additions & 1 deletion nginx/nginx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ if [ -f /etc/nginx/sites-enabled/default.conf ]; then
fi


# copy our site config and synlink it
# copy our site config and symlink it
cp /vagrant/wp-vagrant/nginx/default.conf /etc/nginx/sites-available/
ln -s /etc/nginx/sites-available/default.conf /etc/nginx/sites-enabled/default.conf

# rename vhost server name to hostname
echo "nginx vhost conf..."
sed -i "s/%%hostname%%/${hostname}/" /etc/nginx/sites-enabled/default.conf

# php version for fpm
sed -i "s/%%php_version%%/${php_version}/" /etc/nginx/sites-enabled/default.conf
14 changes: 14 additions & 0 deletions php/php.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash


# backup existing php.ini
mv /etc/php/${php_version}/fpm/php.ini /etc/php/${php_version}/fpm/php.ini.default

cp /vagrant/wp-vagrant/php/php.ini /etc/php/${php_version}/fpm/php.ini
cp /vagrant/wp-vagrant/php/20-xdebug.ini /etc/php/${php_version}/fpm/conf.d/
cp /vagrant/wp-vagrant/php/www.conf /etc/php/${php_version}/fpm/pool.d/

sed -i "s/%%php_version%%/${php_version}/" //etc/php/${php_version}/fpm/pool.d/www.conf


update-alternatives --set php /usr/bin/php${php_version}
2 changes: 1 addition & 1 deletion php/www.conf
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ group = vagrant
; specific port;
; '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = /var/run/php5-fpm.sock
listen = /var/run/php/php%%php_version%%-fpm.sock

; Set listen(2) backlog.
; Default Value: 65535 (-1 on FreeBSD and OpenBSD)
Expand Down
23 changes: 20 additions & 3 deletions settings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@
# Basic settings
#

# this is hostname for the vagrant box
# make sure to change it in the Vagrantfile as well
hostname='wpvagrant.dev'

# PHP version to install
# valid values:
# 5.5
# 5.6
# 7.0
php_version='7.0'


# set install_wordpress to true to download and install latest version of WP
install_wordpress=true

Expand All @@ -24,19 +36,24 @@ mysql_root_password='root'

###############################################################################
# WP database
# this will create a db with these details
#


# name of database: eg wordpress
wp_db_name='vagrant_test'
wp_db_name='wp_vagrant'

# database user name
# database user name, leave empty for root
wp_db_user=''

# database password
wp_db_password=''

###############################################################################
# WP admin / install
# if this is a new db install, then use these details for the
# initial WP admin user
# ignored if install_wordpress is false
#

wp_admin_user='admin'
Expand All @@ -45,7 +62,7 @@ wp_admin_password='123'

wp_admin_email='[email protected]'

wp_site_title='Vagrant'
wp_site_title='WP Vagrant'



Expand Down
2 changes: 1 addition & 1 deletion wp/install-wp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ PHP
# install database
wp core install --allow-root \
--path=$wp_path \
--url=wpvagrant.dev \
--url=${hostname} \
--admin_user=$wp_admin_user \
--admin_password=$wp_admin_password \
--admin_email=$wp_admin_email \
Expand Down

0 comments on commit ac7ebb4

Please sign in to comment.