Typically when we work with a Web server, we edit our files locally, and then "push" them up to our Web server (perhaps using SCP, rsync, Git push, or maybe even FTP). The same will be true with our Vagrant server: you need a way to get files from your host machine, to the guest server. You could either use SCP, but we will enable file sharing to make life a lot easier. With file sharing enabled you will be able to drap-and-drop files into specific directories within your Vagrant instance using your local file manager (e.g. Finder or Windows Explorer). The files will be immediately shared, and recognized by your server, allowing you to continue working on the files with your favorite IDEs and code editing tools without the upload step. Technically, enabling file sharing isn't necessary, but I think you'll agree it is a lot more convenient than SCPing files to your guest server.
Lesson Outcomes
By the end of this lesson you will be able to share files between your host and guest machines without the use of SCP. After enabling file sharing, you should be able to copy a file into the shared folder in your Vagrantfile and have it automatically appear inside the Vagrant instance. e.g. you can load a static web page created on your local machine without having to use SCP.
Lesson Summary
As long as you're using basic file sharing (no NFS), it should work "out of the box" for Windows 8, and OSX.
- Configure synced folder in Vagrantfile.
- Locate and remove:
# config.vm.synced_folder "../data", "/vagrant_data"
- In its place, add:
config.vm.synced_folder "docroot", "/var/www"
- Create a new directory using the name identified in the file Vagrantfile.
$ mkdir docroot
- Reload the vagrant instance (and restart the server). The contents of
/var/www
will appear indocroot
.
$ vagrant reload
$ vagrant ssh
$ sudo /etc/init.d/apache start
$ exit
- Edit the Web page from the host machine.
- Refresh the browser to see the changed file.
Gotchas
This lesson was recorded using VirtualBox 4.3.6 and Vagrant 1.4.3. There is a known issue for file sharing with VirtualBox 4.3.10. If you get the following error message: "Failed to mount folders in Linux guest. This is usually because the "vboxsf" file system is not available." you have encountered this bug. Consider downgrading VirtualBox to 4.3.8, or follow the troubleshooting tips in the issue queue for your particular host machine.
If you are having problems with file permissions / ownership, try editing the permisisons from the host machine, not the guest machine. This is most noticeable when you are creating a new Drupal instance and there are folders / files created automatically by the system. Vagrant won't give a warning to explain why it won't change permissions, it simply doesn't show any changes after running chommands such as: chmod +w <directory_name>
.
If you are still having problems with silent file permissions, update your Vagrantfile as follows:
- Locate the setting for
config.vm.synced_folder
- Add a server-friendly owner, by adding the following to the end:
, :owner => "www-data"
- Add a server-friendly group, by adding the following to the end:
, :group => "www-data"
If you're STILL having problems, update your Vagrantfile to give more permissive defaults.
- Locate the setting for
config.vm.synced_folder
and add the following to the end:, :mount_options => ['dmode=775', 'fmode=664']
- The final line should be something like this (all one line):
config.vm.synced_folder "docroot", "/var/www", :owner => "www-data", :group => "www-data", :mount_options => ['dmode=775', 'fmode=664']
Introduction to Vagrant
CourseI'm sure you've heard by now that PHPtemplate is being replaced by Twig in Drupal 8. If you're a front end developer, you may be excited or afraid about how this will affect you. Let's take a look at the guiding principles behind the Twig initiative and where you can find documentation for theming in Drupal 8.
With the number of internet connected devices increasing rapidly it's important to make sure that your content, and your business, can be read and understood by machines. Creating an Application Programmer Interface, or API, which exposes your content in machine readable formats like JSON or XML is one of the best ways to accomplish this. Next week Joe Shindelar will be hosting a free webinar to show you how to build APIs on top of Drupal 7 with the Services module.
Drupalize.Me Podcast Episode 37
Blog postThis week's episode of our podcast, Bunny Ears Are Fuzzy, is a bit of a different than our regular podcast.
This week we are wrapping up our Working with Media Module in Drupal 7 series. We complete the site by getting our music views into place and adding YouTube video embeds.
In this lesson we already have albums and a nice player all set up, now we just need to make them easy to find and play. We're going to use the clone feature of the Views module to create a music listing page and then get a music block on the home page, next to the Photos block we already have. Using Views' clone feature will make this a pretty quick process for us.
Note: This series is covering Media Module version 1.x. To learn about Media Module 2.x, check out our Using Drupal Chapter 4: Media Management series.
Additional resources
Embed YouTube Videos
FreeOur band has been capturing stuff on videos for a while, and it's super easy for them to put them up on YouTube. YouTube has been perfect for them, and they want to keep using that, but they also want people to be able to find those videos on their site. In this lesson we'll create a new video content type and set it up to use remote media with the Media Internet Sources module, which comes with the Media package. When we add our video field to the content type we will not be configuring it for upload, which is what we used for the audio files on our albums. This configuration, with Media Internet Sources and the Media YouTube module, will allow our users to simply copy and paste in a YouTube URL or embed code to get a playable video on our site. In the process of working with the Media YouTube module, we'll also take our first dip into the Media file type display settings to make sure our video preview doesn't break our editing experience.
Note: This series is covering Media Module version 1.x. To learn about Media Module 2.x, check out our Using Drupal Chapter 4: Media Management series.
Additional resources
We have our video content type created, and we can get our videos on the site. The final step to completing this website is to create our video listing page and front page block. Like we did with the music views, we will clone an existing view to speed our work. To get our videos to display properly though we're going to have to dive deeper into our file type display settings, and in particular we will look at both a file type field setting, and the actual file display to get a custom-sized embedded video player on our listing page.
Note: This series is covering Media Module version 1.x. To learn about Media Module 2.x, check out our Using Drupal Chapter 4: Media Management series.
We've built a pretty great, and media-rich, site for our band. We nailed all of the requirements they had, and learned a lot about media in Drupal in the process. In this wrap-up lesson we're going to take a tour of the completed site to review how we built it, and step through the modules we used and how. Then we look froward by taking a quick look at some other useful modules to explore: oEmbed and File Lock.
Note: This series is covering Media Module version 1.x. To learn about Media Module 2.x, check out our Using Drupal Chapter 4: Media Management series.
Additional resources
This week, we'll tame images and audio files as we continue our Working with Media Module in Drupal 7 series with Addison Berry.
Insert module provides a simple, clean way to get out images in-line, but we are not taking advantage of the fact that we have the Media browser for a unified experience. In order to get the Media browser in the picture for in-line images, and provide a really cohesive editing experience, we're going to give our users a WYSIWYG (what you see is what you get) toolbar, and add our browser to that toolbar. We'll be using the WYSIWYG module, along with the external CKeditor library.
Note: This series is covering Media Module version 1.x. To learn about Media Module 2.x, check out our Using Drupal Chapter 4: Media Management series.
Additional resources
We need to add our own audio player to make the audio experience nice and slick on the site so people don't have to download the files to listen to them. In this lesson we'll install the jPlayer module and the jPlayer library, then make sure our configuration is set the way we want.
Note: This series is covering Media Module version 1.x. To learn about Media Module 2.x, check out our Using Drupal Chapter 4: Media Management series.
Additional resources
Aside from things like photo galleries or images for albums, our content creators on the site are going to want to be able to add images to blog posts and do things like put a bio picture on the bio page. The article content type already has an image field, but that doesn't help us very much with getting that image inside the body of our content. In this lesson we're going to add in-line images using the Insert module.
Note: This series is covering Media Module version 1.x. To learn about Media Module 2.x, check out our Using Drupal Chapter 4: Media Management series.
Additional resources
Probably the most important thing that our band wants to be able to do is upload their music! In this lesson we're going to create an Album content type with a title, cover art, description, and list of songs.
Note: This series is covering Media Module version 1.x. To learn about Media Module 2.x, check out our Using Drupal Chapter 4: Media Management series.
It's great that we can list our audio files in our albums, but a link to download isn't a great way for people to experience the music. Media module is helpful to get the music up there, but it doesn't provide any players for audio and video files. We need to add our own player to make the audio experience nice and slick. In this lesson, we'll review the following players:
- MediaElement
- MediaFront
- jPlayer
Note: This series is covering Media Module version 1.x. To learn about Media Module 2.x, check out our Using Drupal Chapter 4: Media Management series.
Additional resources
Exploring the New Drupal 8 Display Modes
Blog postDrupalize.Me Podcast Episode 36
Blog postIn our latest podcast episode we have two guests, Klaus Purer (klausi) and Lin Clark (linclark) joining Addi and Joe Fender to talk about the new REST module that has been added to Drupal 8 core.
Release Day: Creating Image Galleries
Blog postThis week we turn our attention back to the Working with Media Module in Drupal 7 series. We have a basic site in place, and now we need to add some features to make it rich with media. These three videos walk through the steps to create good-looking image galleries. They also show how we can work with third-party JavaScript libraries to enhance features on our site. Finally we add a listing page and front page block so users can find our new galleries.
We have some nice looking galleries now, but there still isn't a good way for people to find and view them. In this lesson, we're going to use Views to create a Photos list page, along with a menu item, and then we'll make a Photos home page block. That block will be created with Views as well, and when you click on it, you will go to our new Photos list page.
Note: This series is covering Media Module version 1.x. To learn about Media Module 2.x, check out our Using Drupal Chapter 4: Media Management series.