Download a website on my computer to work with Vagrant¶
This case study is meant to get a fresh development environment from an existing Roadiz Source edition website and theme. Following code snippets are using some variables data, in theses examples I’ll use:
MYUSERas the MySQL database user.
MYPASSWORDas the MySQL database user password.
MYDATABASEas the MySQL database name.
~/Documents/Websitesas the working directory on your own computer.
database-YYYY-mm-dd.sqlis the mysql dump file name, replace
YYYY-mm-ddwith the current date.
mysuperwebsiteis your website root folder.
firstname.lastname@example.org:johndoe/SuperTheme.gitis an example Github repository for your theme.
SuperThemeis an example theme name and folder.
On the production server:¶
- Generate a database dump on your production server.
mysqldump -uMYUSER -pMYPASSWORD MYDATABASE > database-YYYY-mm-dd.sql
Then download it on your computer. You can also use phpmyadmin web tool to export your database tables. Make sure to disable foreign key verification and add the DROP IF EXISTS directive on phpmyadmin export form.
On your computer:¶
- Clone Roadiz on your favorite folder, choose well between master or develop branch if you want the stable version or the latest features.
cd ~/Documents/Websites; # Here I choose the develop branch, because I’m warrior git clone -b develop https://github.com/roadiz/roadiz.git mysuperwebsite;
- Clone your website theme in Roadiz
themes/folder, choose well your branch too. If you already have a develop branch, clone with
cd ~/Documents/Websites/mysuperwebsite/themes; # My theme already has a develop branch so… git clone -b develop email@example.com:johndoe/SuperTheme.git SuperTheme;
- [Optional] Initialize git-flow on the theme. You should always work on develop. Master branch is only for releases. If you don’t have git-flow on your computer, you can find some help on the official documentation.
cd ~/Documents/Websites/mysuperwebsite/themes/SuperTheme; # You must fetch every available branches before initializing git flow git checkout master; git checkout develop; git flow init; # Follow instructions # Git flow should checkout on develop branch for you
- Install Roadiz’ Composer dependencies (after cloning the theme to be sure that all composer dependencies are loaded)
cd ~/Documents/Websites/mysuperwebsite; composer install --no-dev;
- Launch your Vagrant environment. Do not to automatically provision your VM if you want to choose what tool to install.
vagrant up --no-provision; # ... lots of lines, bla bla bla
Choose tools to install on your VM,
roadiz provisioner is mandatory… obviously,
devtools provisioner will
install Composer, Node.js, Grunt and Bower commands. If you have lots of website on your computer, it’s better to
install these tools directly on your host machine, they will be more effective than on the VM. And you will be able to
take advantage of Composer and NPM cache between your dev websites.
# Everything vagrant provision --provision-with roadiz,phpmyadmin,mailcatcher,solr,devtools # OR on a dev computer vagrant provision --provision-with roadiz,phpmyadmin,mailcatcher,solr
- Import your database dump. First, you’ll need to copy it into your Roadiz website to make it available within your Vagrant VM. Then import it in your VM using the
mv ~/Downloads/database-YYYY-mm-dd.sql ~/Documents/Websites/mysuperwebsite/database-YYYY-mm-dd.sql; cd ~/Documents/Websites/mysuperwebsite; # Enter your VM vagrant ssh; # Your website is located in /var/www folder cd /var/www; mysql -uroadiz -proadiz roadiz < database-YYYY-mm-dd.sql; # Exit your VM exit;
- Update your conf/config.yml file to fill in your mysql credentials.
cd ~/Documents/Websites/mysuperwebsite; # composer should have create a starter config file for you subl conf/config.yml; # If you work SublimeText
- Use the
bin/roadiz generate:nsentitiesto regenerate Doctrine entities existing in database but not as files.
cd ~/Documents/Websites/mysuperwebsite; vagrant ssh; cd /var/www; bin/roadiz generate:nsentities; # You may have to check database schema if your production website is not up to # date with latest Roadiz bin/roadiz orm:schema-tool:update --dump-sql --force;
- Download your production documents to your dev VM. You don’t have to do this within your VM.
cd ~/Documents/Websites/mysuperwebsite/files; rsync -avcz -e "ssh -p 22" firstname.lastname@example.org:~/path/to/roadiz/files/ ./ # do not forget ending slashes in both paths.
- If you are using a Vagrant VM you have to add your IP address to the
dev.phpfile to authorize your host computer to use the development environment.
11. Connect to
http://localhost:8080/dev.php to begin. Every outgoing emails should be catched
by Mailcatcher. You can see them at address