How to Start a Drupal Website
Learn step by step how to install Drupal locally.
When you start a new Drupal website, you will need to set it up locally first. There are multiple tools to do this: Acquia Dev Desktop, Ampps, Docker, Vagrant etc.
In this tutorial I’ll be using Vagrant and Virtualbox. I’m using a Mac, but if you use Windows or Linux, just download the version for your OS.
1. Install Vagrant and Virtualbox.
First, you will need to download and install them from these sites:
The install process is very intuitive so I won’t go into detail here. To check that vagrant is installed properly, go to the console and type vagrant. You should be getting a response like this:
Usage: vagrant [options] <command> [<args>]
2. Installing a virtual machine.
You can start one from scratch and add all the packages you need manually, but why bother when you can just download one ready to use? You can find some in this page: https://www.drupal.org/docs/develop/local-server-setup/virtual-machine-development-environments, although for this tutorial I’ll be using this instead: https://box.scotch.io/, as I do Wordpress development from time to time. If you are going to use only Drupal, you should consider using a virtual machine like: https://www.drupalvm.com/.
The install process is quite simple:
- Open a terminal and go to /Users/user/VirtualBox VMs (where user is your Mac user name).
- Run this command to clone the repository:
git clone https://github.com/scotch-io/scotch-box my-project - Rename the directory:
mv my-project scotchbox - Let’s start it:
cd scotchbox
vagrant up
If you get an error, run these commands: vagrant halt, vagrant plugin install vagrant-vbguest, vagrant up. - Open your browser and go to http://192.168.33.10/. You should see a “Welcome to Scotch Box” message.
3. Create the database.
Next thing we need to do is creating a database for Drupal. Run this in a terminal:
vagrant ssh
mysql -u root -proot
create database vanilladrupal8; (replace with your database name).
exit;
4. Install Drupal.
For previous versions of Drupal, you would only need to download Drupal core and add it to your environment. Since version 8, however, it’s recommended to use Composer to install it:
cd /var/www/public (you need to be inside your vm (vagrant ssh)).
composer create-project drupal/recommended-project:8.9.x my_site_name_dir (replace my_site_name_dir with your site name).
Now, open your browser and go to http://192.168.33.10/my_site_name_dir/web/core/install.php
Choose the language:
Choose profile (normally Standard):
Verify requirements. Ideally you should fix the warnings, but you can click at the bottom “continue anyway”, as it’s your local server anyway:
Next, database configuration. Use the database you created earlier, user root and password root:
Then, configure the site:
Once you press “Save and continue”, it will take you to the site homepage. You’re done!
5. Install Drush.
Drush is a command line shell and Unix scripting interface for Drupal.It’s a must have for developers as it has a lot of useful commands to interact with modules, themes, profiles, core, etc. Thanks to Drush you can do things like running updates from command line, execute SQL queries or run DB migrations.
To install it, run this command:
composer require drush/drush
Running the command above will add drush in the vendor folder, but if you want to run drush without having to type ./vendor/bin/drush all the time, you need to run these commands as well:
curl -OL https://github.com/drush-ops/drush-launcher/releases/latest/download/drush.phar (if you are in OSX)
Or
wget -O drush.phar https://github.com/drush-ops/drush-launcher/releases/latest/download/drush.phar (if you are in Linux)
Then
chmod +x drush.phar
sudo mv drush.phar /usr/local/bin/drush
I had to run this one too, but you might not need it:
sudo chmod u+x /usr/local/bin/drush
👉 Find out more about me here: https://sergioguardiola.net 🔥