Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Vagrant LAMP
============
Vagrant LAMP with Wordpress
===========================

Want to test a new web app but don't want to affect your current Apache / MySQL / PHP system?
Applications like MAMP are great, but they don't make it easy to maintain multiple, separate
Expand All @@ -11,6 +11,9 @@ Vagrant allows for Virtual Machines to be quickly setup, and easy to use.

And this project aims to make it very easy to spinup a complete LAMP stack in a matter of minutes.

It also installs the latest version of Wordpress into `/var/www/html` and
points it at a new MySQL database.

Requirements
------------
* VirtualBox <http://www.virtualbox.com>
Expand All @@ -21,16 +24,21 @@ Usage
-----

### Startup
$ git clone http://www.github.com/mattandersen/vagrant-lamp
$ cd vagrant-lamp
$ git clone http://www.github.com/nhsalpha/vagrant-lamp-wordpress
$ cd vagrant-lamp-wordpress
$ vagrant up

That is pretty simple.

### Connecting

#### Apache
The Apache server is available at <http://localhost:8888>
#### Wordpress

The Wordpress instance (running on Apache) is available at [http://localhost:8888](http://localhost:8888)

You should see the Wordpress install wizard and if all went well, it should
already be communicating with the database thanks to the config installed at
`/var/www/html/wp-config.php`

#### MySQL
Externally the MySQL server is available at port 8889, and when running on the VM it is available as a socket or at port 3306 as usual.
Expand Down
38 changes: 36 additions & 2 deletions provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ php_config_file="/etc/php5/apache2/php.ini"
xdebug_config_file="/etc/php5/mods-available/xdebug.ini"
mysql_config_file="/etc/mysql/my.cnf"
default_apache_index="/var/www/html/index.html"
wordpress_username="wordpress_user"
wordpress_password="password"
wordpress_database="wordpress"
wordpress_debug="true"

# This function is called at the very bottom of the file
main() {
Expand All @@ -30,6 +34,11 @@ EOD
php_go
mysql_go

download_wordpress_tarball
extract_wordpress_to_var_www_html_directory
create_database_in_mysql
configure_wordpress_mysql_credentials

touch /var/lock/vagrant-provision
}

Expand Down Expand Up @@ -60,13 +69,13 @@ apache_go() {
cat << EOF > ${apache_vhost_file}
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /vagrant/src
DocumentRoot /var/www/html
LogLevel debug

ErrorLog /var/log/apache2/error.log
CustomLog /var/log/apache2/access.log combined

<Directory /vagrant/src>
<Directory /var/www/html>
AllowOverride All
Require all granted
</Directory>
Expand Down Expand Up @@ -114,5 +123,30 @@ mysql_go() {
update-rc.d apache2 enable
}

download_wordpress_tarball() {
wget --quiet -c https://wordpress.org/latest.tar.gz -O /tmp/wordpress-latest.tar.gz
}

extract_wordpress_to_var_www_html_directory() {
rm -f /var/www/html/index.html
tar --directory=/var/www/html --extract --strip-components=1 -z -f /tmp/wordpress-latest.tar.gz
}

create_database_in_mysql() {
mysql -u root --password=root <<EOF
CREATE DATABASE IF NOT EXISTS ${wordpress_database};
GRANT ALL PRIVILEGES ON ${wordpress_database}.* TO "${wordpress_username}"@"localhost" IDENTIFIED BY "${wordpress_password}";
FLUSH PRIVILEGES;
EOF
}

configure_wordpress_mysql_credentials() {
sed -e "s/define('DB_NAME'.*/define('DB_NAME', '${wordpress_database}');/g" \
-e "s/define('DB_USER'.*/define('DB_USER', '${wordpress_username}');/g" \
-e "s/define('DB_PASSWORD'.*/define('DB_PASSWORD', '${wordpress_password}');/g" \
-e "s/define('WP_DEBUG'.*/define('WP_DEBUG', ${wordpress_debug});/g" \
/var/www/html/wp-config-sample.php > /var/www/html/wp-config.php
}

main
exit 0