I’ve built and rebuilt many demo Drupal 8 sites while trying out new D8 modules and themes and experimenting with new functionality like migrations. After installing D8 manually from scratch so many times, I decided to sit down and figure out how to build a Drupal site using Composer to make it easier. The process is actually very handy, sort of the way we’ve used Drush Make in the past, where you don’t actually store all the core and contributed module code in your repository, you just record which modules and versions you’re using and pull them in dynamically.
I was a little worried about changing the process I’ve used for a long time, but my worries were for nothing. Anyone who’s used to Drush would probably find it pretty easy to get this up and running.
TLDR: How to go from an empty directory to a fully functional Drupal site in two command lines:
sudo composer create-project drupal-composer/drupal-project:~8.0 drupal --stability dev --no-interaction
cd drupal/web
../vendor/bin/drush site-install --db-url=mysql://{username}:{password}@localhost/{database}
Install Composer
Let’s talk through the whole process, step by step. The first step is to install Composer on your local system. See https://getcomposer.org/download/ for more information about installing Composer.
Set Up A Project With Composer
To create a new Drupal project using Composer, type the following on the command line, where /var/drupal is the desired code location:
cd /var
sudo composer create-project drupal-composer/drupal-project:~8.0 drupal --stability dev --no-interaction
The packaging process downloads all the core modules, Devel, Drush and Drush Console, and then moves all the Drupal code into a ‘web’ subdirectory. It also moves the vendor directory outside of the web root. The new file structure will look like this:
You will end up with a composer.json file at the base of the project that might look like the following. You can see the beginning of the module list in the ‘require’ section, and that Drush and Drupal Console are included by default. You can also see rules that move contributed modules into ‘/contrib’ subfolders as they’re downloaded.
{
"name": "drupal-composer/drupal-project",
"description": "Project template for Drupal 8 projects with composer",
"type": "project",
"license": "GPL-2.0+",
"authors": [
{
"name": "",
"role": ""
}
],
"repositories": [
{
"type": "composer",
"url": "https://packagist.drupal-composer.org"
}
],
"require": {
"composer/installers": "^1.0.20",
"drupal/core": "8.0.*",
"drush/drush": "8.*",
"drupal/console": "~0.8",
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"post-install-cmd": "scripts/composer/post-install.sh"
},
"extra": {
"installer-paths": {
"web/core": ["type:drupal-core"],
"web/modules/contrib/{$name}": ["type:drupal-module"],
"web/profiles/contrib/{$name}": ["type:drupal-profile"],
"web/themes/contrib/{$name}": ["type:drupal-theme"],
"web/drush/commands/{$name}": ["type:drupal-drush"]
}
}
}
That site organization comes from https://github.com/drupal-composer/drupal-project/tree/8.x. A README.md file there describes the process for doing things like updating core. The contributed modules are coming from Packagist rather than directly from Drupal.org. That’s because the current Drupal versioning system doesn’t qualify as the semantic versioning the system needs. There is an ongoing discussion https://www.drupal.org/node/1612910 about how to fix that.
Install Drupal
The right version of Drush for Drupal 8 comes built into this package. If you have an empty database you can then install Drupal using the Drush version in the package:
cd drupal/web
../vendor/bin/drush site-install --db-url=mysql://{username}:{password}@localhost/{database}
If you don’t do the installation with Drush you can do it manually, but the Drush installation handles all this for you. The manual process for installing Drupal 8 is:
- Copy default.settings.php to settings.php and unprotect it
- Copy default.license.yml to license.yml and unprotect it
- Create sites/files and unprotect it
- Navigate to EXAMPLE.COM/install to provide the database credentials and follow the instructions.
Learn More 2501
Learn More 2502
Learn More 2503
Learn More 2504
Learn More 2505
Learn More 2506
Learn More 2507
Learn More 2508
Learn More 2509
Learn More 2510
Learn More 2511
Learn More 2512
Learn More 2513
Learn More 2514
Learn More 2515
Learn More 2516
Learn More 2517
Learn More 2518
Learn More 2519
Learn More 2520
Learn More 2521
Learn More 2522
Learn More 2523
Learn More 2524
Learn More 2525
Learn More 2526
Learn More 2527
Learn More 2528
Learn More 2529
Learn More 2530
Learn More 2531
Learn More 2532
Learn More 2533
Learn More 2534
Learn More 2535
Learn More 2536
Learn More 2537
Learn More 2538
Learn More 2539
Learn More 2540
Learn More 2541
Learn More 2542
Learn More 2543
Learn More 2544
Learn More 2545
Learn More 2546
Learn More 2547
Learn More 2548
Learn More 2549
Learn More 2550
Learn More 2551
Learn More 2552
Learn More 2553
Learn More 2554
Learn More 2555
Learn More 2556
Learn More 2557
Learn More 2558
Learn More 2559
Learn More 2560
Learn More 2561
Learn More 2562
Learn More 2563
Learn More 2564
Learn More 2565
Learn More 2566
Learn More 2567
Learn More 2568
Learn More 2569
Learn More 2570
Learn More 2571
Learn More 2572
Learn More 2573
Learn More 2574
Learn More 2575
Learn More 2576
Learn More 2577
Learn More 2578
Learn More 2579
Learn More 2580
Learn More 2581
Learn More 2582
Learn More 2583
Learn More 2584
Learn More 2585
Learn More 2586
Learn More 2587
Learn More 2588
Learn More 2589
Learn More 2590
Learn More 2591
Learn More 2592
Learn More 2593
Learn More 2594
Learn More 2595
Learn More 2596
Learn More 2597
Learn More 2598
Learn More 2599
Learn More 2600
Learn More 2601
Learn More 2602
Learn More 2603
Learn More 2604
Learn More 2605
Learn More 2606
Learn More 2607
Learn More 2608
Learn More 2609
Learn More 2610
Learn More 2611
Learn More 2612
Learn More 2613
Learn More 2614
Learn More 2615
Learn More 2616
Learn More 2617
Learn More 2618
Learn More 2619
Learn More 2620
Learn More 2621
Learn More 2622
Learn More 2623
Learn More 2624
Learn More 2625
Learn More 2626
Learn More 2627
Learn More 2628
Learn More 2629
Learn More 2630
Learn More 2631
Learn More 2632
Learn More 2633
Learn More 2634
Learn More 2635
Learn More 2636
Learn More 2637
Learn More 2638
Learn More 2639
Learn More 2640
Learn More 2641
Learn More 2642
Learn More 2643
Learn More 2644
Learn More 2645
Learn More 2646
Learn More 2647
Learn More 2648
Learn More 2649
Learn More 2650
Learn More 2651
Learn More 2652
Learn More 2653
Learn More 2654
Learn More 2655
Learn More 2656
Learn More 2657
Learn More 2658
Learn More 2659
Learn More 2660
Learn More 2661
Learn More 2662
Learn More 2663
Learn More 2664
Learn More 2665
Learn More 2666
Learn More 2667
Learn More 2668
Learn More 2669
Learn More 2670
Learn More 2671
Learn More 2672
Learn More 2673
Learn More 2674
Learn More 2675
Learn More 2676
Learn More 2677
Learn More 2678
Learn More 2679
Learn More 2680
Learn More 2681
Learn More 2682
Learn More 2683
Learn More 2684
Learn More 2685
Learn More 2686
Learn More 2687
Learn More 2688
Learn More 2689
Learn More 2690
Learn More 2691
Learn More 2692
Learn More 2693
Learn More 2694
Learn More 2695
Learn More 2696
Learn More 2697
Learn More 2698
Learn More 2699
Learn More 2700
Learn More 2701
Learn More 2702
Learn More 2703
Learn More 2704
Learn More 2705
Learn More 2706
Learn More 2707
Learn More 2708
Learn More 2709
Learn More 2710
Learn More 2711
Learn More 2712
Learn More 2713
Learn More 2714
Learn More 2715
Learn More 2716
Learn More 2717
Learn More 2718
Learn More 2719
Learn More 2720
Learn More 2721
Learn More 2722
Learn More 2723
Learn More 2724
Learn More 2725
Learn More 2726
Learn More 2727
Learn More 2728
Learn More 2729
Learn More 2730
Learn More 2731
Learn More 2732
Learn More 2733
Learn More 2734
Learn More 2735
Learn More 2736
Learn More 2737
Learn More 2738
Learn More 2739
Learn More 2740
Learn More 2741
Learn More 2742
Learn More 2743
Learn More 2744
Learn More 2745
Learn More 2746
Learn More 2747
Learn More 2748
Learn More 2749
Learn More 2750
Learn More 2751
Learn More 2752
Learn More 2753
Learn More 2754
Learn More 2755
Learn More 2756
Learn More 2757
Learn More 2758
Learn More 2759
Learn More 2760
Learn More 2761
Learn More 2762
Learn More 2763
Learn More 2764
Learn More 2765
Learn More 2766
Learn More 2767
Learn More 2768
Learn More 2769
Learn More 2770
Learn More 2771
Learn More 2772
Learn More 2773
Learn More 2774
Learn More 2775
Learn More 2776
Learn More 2777
Learn More 2778
Learn More 2779
Learn More 2780
Learn More 2781
Learn More 2782
Learn More 2783
Learn More 2784
Learn More 2785
Learn More 2786
Learn More 2787
Learn More 2788
Learn More 2789
Learn More 2790
Learn More 2791
Learn More 2792
Learn More 2793
Learn More 2794
Learn More 2795
Learn More 2796
Learn More 2797
Learn More 2798
Learn More 2799
Learn More 2800
Learn More 2801
Learn More 2802
Learn More 2803
Learn More 2804
Learn More 2805
Learn More 2806
Learn More 2807
Learn More 2808
Learn More 2809
Learn More 2810
Learn More 2811
Learn More 2812
Learn More 2813
Learn More 2814
Learn More 2815
Learn More 2816
Learn More 2817
Learn More 2818
Learn More 2819
Learn More 2820
Learn More 2821
Learn More 2822
Learn More 2823
Learn More 2824
Learn More 2825
Learn More 2826
Learn More 2827
Learn More 2828
Learn More 2829
Learn More 2830
Learn More 2831
Learn More 2832
Learn More 2833
Learn More 2834
Learn More 2835
Learn More 2836
Learn More 2837
Learn More 2838
Learn More 2839
Learn More 2840
Learn More 2841
Learn More 2842
Learn More 2843
Learn More 2844
Learn More 2845
Learn More 2846
Learn More 2847
Learn More 2848
Learn More 2849
Learn More 2850
Learn More 2851
Learn More 2852
Learn More 2853
Learn More 2854
Learn More 2855
Learn More 2856
Learn More 2857
Learn More 2858
Learn More 2859
Learn More 2860
Learn More 2861
Learn More 2862
Learn More 2863
Learn More 2864
Learn More 2865
Learn More 2866
Learn More 2867
Learn More 2868
Learn More 2869
Learn More 2870
Learn More 2871
Learn More 2872
Learn More 2873
Learn More 2874
Learn More 2875
Learn More 2876
Learn More 2877
Learn More 2878
Learn More 2879
Learn More 2880
Learn More 2881
Learn More 2882
Learn More 2883
Learn More 2884
Learn More 2885
Learn More 2886
Learn More 2887
Learn More 2888
Learn More 2889
Learn More 2890
Learn More 2891
Learn More 2892
Learn More 2893
Learn More 2894
Learn More 2895
Learn More 2896
Learn More 2897
Learn More 2898
Learn More 2899
Learn More 2900
Learn More 2901
Learn More 2902
Learn More 2903
Learn More 2904
Learn More 2905
Learn More 2906
Learn More 2907
Learn More 2908
Learn More 2909
Learn More 2910
Learn More 2911
Learn More 2912
Learn More 2913
Learn More 2914
Learn More 2915
Learn More 2916
Learn More 2917
Learn More 2918
Learn More 2919
Learn More 2920
Learn More 2921
Learn More 2922
Learn More 2923
Learn More 2924
Learn More 2925
Learn More 2926
Learn More 2927
Learn More 2928
Learn More 2929
Learn More 2930
Learn More 2931
Learn More 2932
Learn More 2933
Learn More 2934
Learn More 2935
Learn More 2936
Learn More 2937
Learn More 2938
Learn More 2939
Learn More 2940
Learn More 2941
Learn More 2942
Learn More 2943
Learn More 2944
Learn More 2945
Learn More 2946
Learn More 2947
Learn More 2948
Learn More 2949
Learn More 2950
Learn More 2951
Learn More 2952
Learn More 2953
Learn More 2954
Learn More 2955
Learn More 2956
Learn More 2957
Learn More 2958
Learn More 2959
Learn More 2960
Learn More 2961
Learn More 2962
Learn More 2963
Learn More 2964
Learn More 2965
Learn More 2966
Learn More 2967
Learn More 2968
Learn More 2969
Learn More 2970
Learn More 2971
Learn More 2972
Learn More 2973
Learn More 2974
Learn More 2975
Learn More 2976
Learn More 2977
Learn More 2978
Learn More 2979
Learn More 2980
Learn More 2981
Learn More 2982
Learn More 2983
Learn More 2984
Learn More 2985
Learn More 2986
Learn More 2987
Learn More 2988
Learn More 2989
Learn More 2990
Learn More 2991
Learn More 2992
Learn More 2993
Learn More 2994
Learn More 2995
Learn More 2996
Learn More 2997
Learn More 2998
Learn More 2999
Learn More 3000