Install LAMP on Vagrant for Web Development
Install LAMP on Vagrant for Web Development is a post written after the best tut on it was updated to “Install WordPress Dev Sites on Vagrant with Variable VVV” on “the coolest Guide on Planet“. IMHO the VVV is a overkill and not required by most developers further the learning curve is steep.
[su_tabs vertical=”yes”]
[su_tab title=”Install VirtualBox-Vagrant:“]
Step 1: Install VirtualBox: https://www.virtualbox.org/
Step 2: Download and Install “Vagrant” I use the “MAC OS X Universal (32 and 64-bit).
Step 3: Create a Directory where you would want to keep the development web pages. in my example ( you can use the finder also )
~ tsk$ > cd Sites ~ Sites tsk$ > mkdir mywebdev ~ Sites tsk$ > cd mywebdev ~ mywebdev tsk$ >
[/su_tab]
[su_tab title=”Vagrantfile“]
Step 4: Create a File “Vagrantfile” using “textwrangler” edit the same as follows
# -*- 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| # The most common configuration options are documented and commented below. # For a complete reference, please see the online documentation at # https://docs.vagrantup.com. config.vm.provision "fix-no-tty", type: "shell" do |s| s.privileged = false s.inline = "sudo sed -i '/tty/!s/mesg n/tty -s \\&\\& mesg n/' /root/.profile" end # config.vm.hostname = "wpDevBox" # Every Vagrant development environment requires a box. You can search for # boxes at https://atlas.hashicorp.com/search. config.vm.box = "hashicorp/precise64" config.vm.provision :shell, path: "bootstrap.sh" # Disable automatic box update checking. If you disable this, then # boxes will only be checked for updates when the user runs # `vagrant box outdated`. This is not recommended. # config.vm.box_check_update = false # 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, # accessing "localhost:8080" will access port 80 on the guest machine. # config.vm.network "forwarded_port", guest: 80, host: 8080 config.vm.network :forwarded_port, guest: 80, host: 8080, auto_correct: true # Create a private network, which allows host-only access to the machine # using a specific IP. # config.vm.network "private_network", ip: "192.168.33.10" config.vm.network :private_network, ip: "192.168.10.10" # Create a public network, which generally matched to bridged network. # Bridged networks make the machine appear as another physical device on # your network. # config.vm.network "public_network" # Share an additional folder to the guest VM. The first argument is # the path on the host to the actual folder. The second argument is # the path on the guest to mount the folder. And the optional third # argument is a set of non-required options. # config.vm.synced_folder "../data", "/vagrant_data" # Provider-specific configuration so you can fine-tune various # backing providers for Vagrant. These expose provider-specific options. # Example for VirtualBox: # # config.vm.provider "virtualbox" do |vb| # # Display the VirtualBox GUI when booting the machine # vb.gui = true # # # Customize the amount of memory on the VM: # vb.memory = "1024" # end # # View the documentation for the provider you are using for more # information on available options. config.vm.provider "virtualbox" do |vb| # Display the VirtualBox GUI when booting the machine # vb.gui = true # # Customize the amount of memory on the VM: vb.memory = "1024" # Customize the Name of the VM: vb.name = "wpLAMP" end end
[/su_tab]
[su_tab title=”bootstrap.sh“]
Step 5: Create a File “bootstrap.sh” which will be used by Vagrant to create the Virtual Machine
#!/usr/bin/env bash # Use single quotes instead of double quotes to make it work with special-character passwords PASSWORD='root' # PROJECTFOLDER='tsktech' # Updating repository apt-get update # Installing Apache sudo apt-get install -y apache2 # Installing MySQL and it's dependencies, Also, setting up root password for MySQL as it will prompt to enter the password during installation sudo debconf-set-selections <<< "mysql-server-5.5 mysql-server/root_password password $PASSWORD" sudo debconf-set-selections <<< "mysql-server-5.5 mysql-server/root_password_again password $PASSWORD" sudo apt-get -y install mysql-server libapache2-mod-auth-mysql php5-mysql # Installing PHP and it's dependencies sudo apt-get -y install php5 libapache2-mod-php5 php5-mcrypt # install phpmyadmin and give password(s) to installer # for simplicity I'm using the same password for mysql and phpmyadmin sudo debconf-set-selections <<< "phpmyadmin phpmyadmin/dbconfig-install boolean true" sudo debconf-set-selections <<< "phpmyadmin phpmyadmin/app-password-confirm password $PASSWORD" sudo debconf-set-selections <<< "phpmyadmin phpmyadmin/mysql/admin-pass password $PASSWORD" sudo debconf-set-selections <<< "phpmyadmin phpmyadmin/mysql/app-pass password $PASSWORD" sudo debconf-set-selections <<< "phpmyadmin phpmyadmin/reconfigure-webserver multiselect apache2" sudo apt-get -y install phpmyadmin # clean /var/www # sudo rm -Rf /var/www # symlink /var/www => /vagrant # ln -s /vagrant /var/www if ! [ -L /var/www ]; then rm -rf /var/www ln -fs /vagrant /var/www fi
[/su_tab]
[su_tab title=”Run First Time“]
Step 6: execute “Vagrant Up”
~ tsk$ > cd Sites ~ Sites tsk$ > cd mywebdev ~ mywebdev tsk$ > vagrant up
it will take some time to install the dependency and the files as detailed in bootstrap.sh.
==> default: dbconfig-common: flushing administrative password ==> default: * Reloading web server config apache2 ==> default: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName ==> default: ...done. ==> default: Processing triggers for libc-bin ... ==> default: ldconfig deferred processing now taking place mywebdev tsk$ >
[/su_tab]
[su_tab title=”More Steps..“]
Step 7: execute the following
mywebdev tsk$ > vagrant ssh Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic x86_64) * Documentation: https://help.ubuntu.com/ New release '14.04.3 LTS' available. Run 'do-release-upgrade' to upgrade to it. Welcome to your Vagrant-built virtual machine. Last login: Fri Sep 14 06:23:18 2012 from 10.0.2.2 vagrant@wpDevBox:~$ vagrant@wpDevBox:~$ mkdir /var/www/myblog
[/su_tab]
[su_tab title=”Few More Steps..“]
Step 8: execute the following
vagrant@wpDevBox:~$ sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/myblog.conf vagrant@wpDevBox:~$ sudo nano /etc/apache2/sites-available/myblog.conf
Step 9: edit the myblog.conf as follows
<VirtualHost *:80> ServerAdmin your_email_iD@gmail.com ServerName myblog.local ServerAlias www.myblog.local DocumentRoot /var/www/myblog # <Directory /> # Options FollowSymLinks # AllowOverride None # </Directory> <Directory /var/www/myblog/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
[/su_tab]
[su_tab title=”Enable Virtual Server: Virtual Box“]
Step 10: Execute the following to enable the virtual server
vagrant@wpDevBox:~$ sudo a2ensite myblog.conf Enabling site myblog.conf. To activate the new configuration, you need to run: service apache2 reload vagrant@wpDevBox:~$ sudo service apache2 restart * Restarting web server apache2 apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName ... waiting apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName [ OK ]
[/su_tab]
[su_tab title=”Web Development“]
that’s it.. you have VirtualBox running with the following installed “apache2, php5, phpmyadmin & mysql”. you can access the VB on the http://192.168.10.10
If you want to access the webpage http://myblog.local instead of http://192.168.10.10 then we have to edit the hosts file on the macbook
~ tsk$ sudo nano /etc/hosts ## # Host Database # # localhost is used to configure the loopback interface # when the system is booting. Do not change this entry. ## 127.0.0.1 localhost 255.255.255.255 broadcasthost ::1 localhost 192.168.10.10 myblog.local www.myblog.local
Note: to stop the VB use “Vagrant Halt” and start”Vagrant Up” to VB use “Vagrant Destroy”
Your Web Pages should be in Users/yourName/Sites/mywebdev/myblog
[/su_tab]
[su_tab title=”Install Worpress“]
We are developing a blog site hence we have to install “WordPress” the easiest way is using “wp-cli”
Step 11: Execute the following
~ tsk$ > cd Sites/mywebdev/ mywebdev tsk$ > vagrant up Bringing machine 'default' up with 'virtualbox' provider... ==> default: Checking if box 'hashicorp/precise64' is up to date... ==> default: Clearing any previously set forwarded ports... ==> default: Clearing any previously set network interfaces... ==> default: Preparing network interfaces based on configuration... default: Adapter 1: nat default: Adapter 2: hostonly ==> default: Forwarding ports... default: 80 => 8080 (adapter 1) default: 22 => 2222 (adapter 1) ==> default: Running 'pre-boot' VM customizations... ==> default: Booting VM... ==> default: Waiting for machine to boot. This may take a few minutes... default: SSH address: 127.0.0.1:2222 default: SSH username: vagrant default: SSH auth method: private key default: Warning: Connection timeout. Retrying... ==> default: Machine booted and ready! GuestAdditions 5.0.10 running --- OK. ==> default: Checking for guest additions in VM... ==> default: Checking for host entries ==> default: adding to (/etc/hosts) : 192.168.10.10 wpDevBox # VAGRANT: 32615fd58941c9765898b20118e21325 (default) / b353eae8-e87f-4df5-8a9b-54f7871ba8fe ==> default: Setting hostname... ==> default: Configuring and enabling network interfaces... ==> default: Mounting shared folders... default: /vagrant => /Users/tsk/Sites/mywebdev ==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision` ==> default: flag to force provisioning. Provisioners marked to run always will still run. mywebdev tsk$ > vagrant ssh
[/su_tab]
[su_tab title=”More Steps..“]
Step 11.2: next execute the following
vagrant@wpDevBox: sudo apt-get install curl Reading package lists... Done Building dependency tree Reading state information... Done The following extra packages will be installed: libcurl3 The following NEW packages will be installed: curl libcurl3 0 upgraded, 2 newly installed, 0 to remove and 186 not upgraded. Need to get 374 kB of archives. After this operation, 913 kB of additional disk space will be used. Do you want to continue [Y/n]? Y Get:1 http://us.archive.ubuntu.com/ubuntu/ precise-updates/main libcurl3 amd64 7.22.0-3ubuntu4.14 [236 kB] Get:2 http://us.archive.ubuntu.com/ubuntu/ precise-updates/main curl amd64 7.22.0-3ubuntu4.14 [138 kB] Fetched 374 kB in 1s (195 kB/s) Selecting previously unselected package libcurl3. (Reading database ... 75628 files and directories currently installed.) Unpacking libcurl3 (from .../libcurl3_7.22.0-3ubuntu4.14_amd64.deb) ... Selecting previously unselected package curl. Unpacking curl (from .../curl_7.22.0-3ubuntu4.14_amd64.deb) ... Processing triggers for man-db ... Setting up libcurl3 (7.22.0-3ubuntu4.14) ... Setting up curl (7.22.0-3ubuntu4.14) ... Processing triggers for libc-bin ... ldconfig deferred processing now taking place<br>
[/su_tab]
[su_tab title=”Install WP-CLI“]
Step 11.2: now let’s install wp-cli
vagrant@wpDevBox:~$ curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 1410k 100 1410k 0 0 253k 0 0:00:05 0:00:05 --:--:-- 402k
Step 11.3: check if wp-cli is installed
vagrant@wpDevBox:~$ php wp-cli.phar --info PHP binary: php PHP version: 5.3.10-1ubuntu3.21 php.ini used: /etc/php5/cli/php.ini WP-CLI root dir: phar://wp-cli.phar WP-CLI global config: WP-CLI project config: WP-CLI version: 0.21.0
Step 11.4: now to execute the following so that we can use “wp” instead of “php wp-cli.phar”
vagrant@wpDevBox:~$ chmod +x wp-cli.phar vagrant@wpDevBox:~$ sudo mv wp-cli.phar /usr/local/bin/wp vagrant@wpDevBox:~$ wp --info PHP binary: php PHP version: 5.3.10-1ubuntu3.21 php.ini used: /etc/php5/cli/php.ini WP-CLI root dir: phar://wp-cli.phar WP-CLI global config: WP-CLI project config: WP-CLI version: 0.21.0 vagrant@wpDevBox:~$
[/su_tab]
[su_tab title=”Finish WP Installation“]
Step 12: Now we are ready to install the WordPress. Execute the following
vagrant@wpDevBox:~$ cd /var/www/myblog/ vagrant@wpDevBox:/var/www/myblog$ wp core download Downloading WordPress 4.3.1 (en_US)... Success: WordPress downloaded. vagrant@wpDevBox:/var/www/myblog$ wp core config --dbhost=localhost --dbname=wp_myblog --dbuser=root --dbpass=root Success: Generated wp-config.php file. vagrant@wpDevBox:/var/www/myblog$ wp db create Success: Database created. vagrant@wpDevBox:/var/www/myblog$ wp core install --url=http://myblog.local --title=MyBlog --admin_user=yourName --admin_password=yourPasswaord --admin_email=youremailid@gmail.com sh: 1: /usr/sbin/sendmail: not found Success: WordPress installed successfully.
[/su_tab]
[/su_tabs]
boy..this was the longest how to post of mine