Florida Drupal Users Group IRC: Freenode.org #drupal-florida
Complete Ubuntu 18.04 local development environment setup guide for Drupal 8. Includes LAMP, git, Composer, Drush, and RVM. Also, a few optional applications are included. (Sublime Text 3, PhpStorm, Node.js, Gulp.js Atom, and HexChat)
LOCAL set up only! Ubuntu 18.04 / LAMP / Drupal Sites Setup
5. vhost Setup and Configuration
7. Database Creation And Drupal Installation
10. Optional Database creation and Drupal Installation
There are multiple ways to download and install Ubuntu. Listed here are a couple of methods, along with excellent installation guides, to get you started. Choose one, and proceed to Updating your System.
For help installing Ubuntu onto a local hard drive using a USB, follow this guide.
pros: Most straight forward way to install Ubuntu. Easy to install.
cons: Requires additional hardware (USB). Locked into Ubuntu (unless you dualboot, not covered in this guide).
For help installing and running Ubuntu on a virtual machine in Windows, follow this guide.
pros: Can run Ubuntu on any operating system. Can create snapshots to backup virtual machines.
cons: Slower, and more resource intensive than a container in Docker.
For help installing an Ubuntu image and running it as a container through Docker, follow this guide.
pros: Can run Ubuntu on any operating system. More light weight, and boots up quicker than a virtual machine. Ability to create images allows consistancy between everyone who shares the image. Containers are disposable. If downloading a drupal image, setting up Drupal is easier and quicker than the other two options.
cons: Has more of a learning curve than the other two options.
- Open terminal:
Ctrl+Alt+T
- Run updates:
$ sudo apt-get update
- Add your username to the sudo group:
$ sudo adduser yourusername sudo
- Add your username to the www-data group:
$ sudo adduser yourusername www-data
- Install Apache:
$ sudo apt-get install apache2
- Open Apache main configuration file:
$ sudo nano /etc/apache2/apache2.conf
- Use the arrow key to scroll down to the end of the file and type in:
ServerName localhost
- Press CTRL+o (to save)
- Press Enter
- Press CTRL+x (to exit)
- You can check to make sure that it saved with:
$ cat /etc/apache2/apache2.conf
- Restart apache:
$ sudo service apache2 restart
- Change the ownership of /var/www/html to your username:
$ sudo chown yourusername:www-data /var/www/html -R
- Install MySQL:
$ sudo apt-get install mysql-server mysql-client
- Create a password. If this is your first time taking these steps, a sample user and password to use would be "root" (without quotes). Proceed to use this for the rest of the guide
- Check the service status with:
$ sudo /etc/init.d/mysql status
- Install PHP:
$ sudo apt-get -y install php7.2 libapache2-mod-php7.2
- Create a PHP file:
$ sudo nano /var/www/html/phpinfo.php
- Add the following code:
<?php
phpinfo();
?>
- Press CTRL+o (to save)
- Press Enter
- Press CTRL+x (to exit)
- Restart Apache:
$ sudo service apache2 restart
- Open browser and navigate to:
localhost/phpinfo.php
r enter the following in Terminal:
$ sudo systemctl status mysql
- Install phpMyAdmin:
$ sudo apt-get update
$ sudo apt-get install phpmyadmin php-mbstring php-gettext
- Important! Press the spacebar to choose Apache 2. An ***** will display.
- Press Tab (to navigate down the menu to ok)
- Press Enter
- Select Yes to configure with dbconfig-common
- Follow the prompts
- Enable mcrypt and mbstrings extentsions:
$ sudo phpenmod mcrypt
$ sudo phpenmod mbstring
- Restart Apache:
$ sudo service apache2 restart
- Test by navigating in the browser to:
localhost/phpmyadmin
- You can follow the rest of the tutorial for additional security; not required for local development
- Don’t ever do this on a live server but local is fine. Drupal php needs access:
$ chmod 777 /var/www/html
- Open the PHP configuration file:
$ sudo nano /etc/php/7.2/apache2/php.ini
- Press CTRL+w (to search) and type
memory_limit
- Change to:
memory_limit = 512M
- Press CTRL+o (to save)
- Press Enter
- Press CTRL+x (to exit)
- Change to root directory:
$ cd ~
- Create .ssh directory:
$ mkdir .ssh
- Change directory permissions:
$ sudo chmod 700 .ssh
- Create an RSA Key Pair (skip if you already have a key):
$ ssh-keygen -t rsa
- Press Enter three times (type a passphrase if you wish)
Note: You will see the following messages to which you can just press enter:
Enter file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]
Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]
- Change to root directory:
$ cd ~
- Install git:
$ sudo apt-get install git
- Set your name for git identity:
$ git config --global user.name yourname
- Set your email for git identity:
$ git config --global user.email [email protected]
- To add color to git use this command:
$ git config --global color.ui auto
- See all current values:
$ git config --list
Note! You must install composer before installing drush
- Change to root directory:
$ cd ~
- Install cURL:
$ sudo apt-get install curl
- Download Composer:
$ curl -sS https://getcomposer.org/installer | php
- Move composer to bin:
$ sudo mv composer.phar /usr/local/bin/composer
- Add path to the .bashrc:
$ sed -i '1i export PATH="$HOME/.composer/vendor/bin:$PATH"' $HOME/.bashrc
- Source the .bashrc file:
source $HOME/.bashrc
- (Optional) Check your current version of Composer
composer --version
For additional drush commands visit www.drushcommands.com
Installing Drush 8 (note, you may or may not need to precede each command with sudo
based on your user permissions)
- Change to your bin directory
$ cd /usr/local/bin
- create the drush-8 directory
$ mkdir drush-8
- Change to the new drush-8 directory
$ cd drush-8
- Install Drush 8 in the current directory
$ composer require drush/drush:8.x
- Create a symlink to drush-8 to enable global calling of the
drush8
command
$ ln -s /usr/local/bin/drush-8/vendor/bin/drush /usr/local/bin/drush8
- (Optional) Check your current version of drush8
$ drush8 --version
Installing Drush 7 (note, you may or may not need to precede each command with sudo
based on your user permissions)
- Change to your bin directory
$ cd /usr/local/bin
- create the drush-7 directory
$ mkdir drush-7
- Change to the new drush-7 directory
$ cd drush-7
- Install Drush 7 in the current directory
$ composer require drush/drush:7.x
- Create a symlink to drush-7 to enable global calling of the
drush7
command
$ ln -s /usr/local/bin/drush-7/vendor/bin/drush /usr/local/bin/drush7
- (Optional) Check your current version of drush7
$ drush7 --version
- Change to your bin directory and create a new drush file
$ cd /usr/local/bin
$ sudo nano drush
- Insert this script in the newly created file
#!/bin/sh
version=$(git config --get drush.version)
if [ "$version" = '7' ];
then
drush7 "$@"
else
drush8 "$@"
fi
Hit Ctrl+O to save the file Hit Enter Hit Ctrl+X to close the file
- Open /etc/apache2/mods-enabled/dir.conf for editing:
$ sudo nano /etc/apache2/mods-enabled/dir.conf
- Add a parameter reading "index.php" as the first item after "DirectoryIndex":
<IfModule mod_dir.c>
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>
Note: index.php may be listed later in the line. Delete the second instance of it.
- Press CTRL+o (to save)
- Press Enter
- Press CTRL+x (to exit)
- Restart Apache:
$ sudo service apache2 restart
- Enable the rewrite module for Apache:
$ sudo a2enmod rewrite
- Restart Apache:
$ sudo service apache2 restart
- Open /etc/apache2/apache2.conf for editing:
$ sudo nano /etc/apache2/apache2.conf
- Scroll down until you find:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
- Change
AllowOverride None
toAllowOverride All
:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
- Restart Apache:
$ sudo service apache2 restart
- Change to the /etc/apache2/sites-available directory:
$ cd /etc/apache2/sites-available
- Create and open a new vhost config file just for drupal:
$ sudo nano drupal
- Add in the following
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /var/www
ServerName localhost
</VirtualHost>
- Press CTRL+o (to save)
- Press Enter
- Press CTRL+x (to exit)
Create Symlinks for the drupal file in the sites-enabled directory
- Change to the /etc/apache2/sites-enabled directory:
$ cd /etc/apache2/sites-enabled
- Create a symlink to ../sites-available/drupal in /etc/apache2/sites-enabled:
$ sudo ln -s ../sites-available/drupal .
- Restart Apache
$ sudo service apache2 restart
- Change to root directory:
$ cd ~
- Change "foo" to your user. (If you are unsure of the name, type
pwd
in the command line):
$ ln -s /var/www/html /home/foo/sites
Now you can easily cd sites and you will be directly in the html folder
Future note: You can create and name a symlink wherever you like
- The first path is what you are linking
- The second path is where the link will be
Example:
$ ln -s /what/is/being/linked /where/symlink/goes/nameofsymlink
To remove a symlink: unlink sites (symlink name)
Configure Apache For Sites (Follow this for either site creation methods.)
- Open /etc/hosts file for editing:
$ sudo nano /etc/hosts
- Add the follow to the last line:
# Drupal sites
127.0.0.1 newsite.local
- Press CTRL+o (to save)
- Press Enter
- Press CTRL+x (to exit)
Future note: You will edit this file for every additional site so it will look like this:
# Drupal sites
127.0.0.1 newsite.local
127.0.0.1 newsite2.local
127.0.0.1 newsite3.local
- Open browser and navigate to http://localhost/phpmyadmin
- Create new database called newsite
Note: you shouldn't need "sudo" for these steps. If you get permission errors, please check the permissions for /var/www/html
- Change to your sites directory: (Hopefully you created a symlink. If you didn’t then use
$ cd /var/www/html
):
$ cd sites
- Clone Drupal 8:
- Go to https://drupal.org/project/drupal to verify the latest version.
- Click the "Version Control" tab.
- Select the correct version from the "Version to work from" drop down.
- Your git clone will look similar to the following:
$ git clone --branch 8.3.x https://git.drupal.org/project/drupal.git
- Change the name of the cloned drupal directory to the name of the new site:
$ mv drupal newsite.local
- Change to newsite.local/sites directory:
$ cd newsite.local/sites
- For Pantheon.io sites, copy example.settings.local.php to default and name it settings.local.php
$ cp example.settings.local.php default/settings.local.php
- Change to the default directory. Copy default.settings.php and rename as settings.php
$ cd default
$ cp default.settings.php settings.php
- Create the Directory Files
$ mkdir files
- Change file permissions
$ chmod 777 files
$ chmod 777 settings.php
$ chmod 777 settings.local.php
- Open browser and navigate to localhost/newsite.local Note: If you are getting a blank white screen here (called the White Screen of Death), try using an earlier version of Drupal, such as 8.0.x
- Complete install, making sure to fill in database name and password
- At any time, to update your Drupal site, run the following Drush command from the root of your site directory (replace X.X.X with the desired version)
$ drush pm-update projects drupal-X.X.X
Rinse and repeat this section for new drupal sites you may create
Sublime Text is a sophisticated text editor for code, html and prose.
- Install the GPG key:
$ wget -qO - https://download.sublimetext.com/sublimehq-pub.gpg | sudo apt-key add -
- Ensure apt is set up to work with https sources:
$ sudo apt-get install apt-transport-https
- Select 'stable' repository
$ echo "deb https://download.sublimetext.com/ apt/stable/" | sudo tee /etc/apt/sources.list.d/sublime-text.list
- Update apt sources and install Sublime Text
$ sudo apt-get update
$ sudo apt-get install sublime-text
- Add in drupal specific preferences https://drupal.org/node/1346890
- Setting up PhpStorm for Drupal's Coding Standards (Drupal.org)
- Drupal Development using PhpStorm (PhpStorm Documentation)
- Update apt sources
$ sudo apt-get update
- Install Terminator:
$ sudo apt-get install terminator
- Create a database, Replace database_name with the name of your choice.
$ mysqladmin -u root -p create database_name
- Enter your MySQL root password at the prompt.
- Open the mySQL client using root:
$ mysql -u root -p
-
Enter your MySQL root password at the prompt.
-
Create a user:
mysql> CREATE USER 'name_of_new_user'@'localhost' IDENTIFIED BY 'password_of_new_user';
- Grant name_of_new_user privileges to database_name:
mysql> GRANT ALL PRIVILEGES ON 'database_name'.* TO 'name_of_new_user'@'localhost';
- Reload the grant tables:
mysql> FLUSH PRIVILEGES;
- Exit mySQL
mysql> quit
RVM (“Ruby Version Manager”) Required for theming with sass/compass RVM allows you to install and manage multiple installations of Ruby on your system. It can also manage different gemsets. It is available for OS X, Linux, or other UNIX-like operating systems.
- Download signatures:
$ gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
- Download RVM
$ curl -sSL https://get.rvm.io | bash -s stable
- Source ~/.rvm/scripts/rvm:
$ source ~/.rvm/scripts/rvm
- Find current stable version at www.ruby-lang.org/en/downloads/
- Install current stable version of RVM:
$ rvm install 2.2.2
- Change terminal preferences by going to: Edit > Profile Preferences Title and Command
- Check the box to Run command as a login shell.
- Close terminal and reopen.
- Find the latest version www.ruby-lang.org/en/downloads/
- Switch to Ruby 2.2.2:
$ rvm use 2.2.2
- Verify Ruby version:
$ ruby -v
Install Options
- Option 1 is the recommended method for the masses, as it should be stable and secure.
- Options 2, 3, and 4 have the advantage of keeping your node and npm packages the most current
- To install Node.js, open a terminal and type the following command:
$ sudo apt-get install nodejs
- Then install the Node package manager called “npm”:
$ sudo apt-get install npm
- Create a symbolic link for “node” as many Node.js tools use this name to execute.
$ sudo ln -s /usr/bin/nodejs /usr/bin/node
- Now we should have both the node and npm commands working:
$ node -v
v8.10.0
$ npm -v
3.5.2
The process below is described here, too.
- Add the Node.js maintained repositories to your Ubuntu package source list with this command:
$ curl -sL https://deb.nodesource.com/setup | sudo bash -
- Then install Node.js with apt-get:
$ sudo apt-get install nodejs
- Optionally we can create a symbolic link for “node” (for reasons mentioned earlier):
$ sudo ln -s /usr/bin/nodejs /usr/bin/node
- Using this install option, we end up with newer versions of “nodejs” and “npm”:
$ node -v
v8.10.0
$ npm -v
3.5.2
Go to the official Node.js download page and download either the 32-bit or 64-bit Linux binary file, depending on your system type.
- You can check what CPU architecture your server has with these commands:
$ getconf LONG_BIT
64
$ uname -p
x86_64
- You can download this file from the browser or from the console. The latter is shown below (note: the specific Node.js version might be different for you):
$ wget http://nodejs.org/dist/v0.12.0/node-v0.12.0-linux-x64.tar.gz
- From a console window, go to the directory where the Node.js binary was downloaded to, and then execute the following command to install the Node.js binary package in “/usr/local/”:
$ sudo tar -C /usr/local --strip-components 1 -xzf node-v0.10.34-linux-x86.tar.gz
- You should now have both node and npm installed in “/usr/local/bin”. You can check this typing:
$ ls -l /usr/local/bin/node
$ ls -l /usr/local/bin/npm
Option 4: Install Node.js from the Github source repository.
On Ubuntu, the “nodejs” package has a similar name to the older one named “node”. The old one is an amateur packet radio program you can more than likely remove.
If you already have “node” installed, you might want to remove it. Some Node.js tools might execute Node.js as “node” instead of “nodejs” causing conflicts.
You can look for and remove the “node” package by executing these commands in a terminal. To access a terminal, navigate the desktop menu to: Applications -> Accessories -> Terminal.
Run this command and if it says “install” in the right column, “node” is on your system:
$ dpkg --get-selections | grep node
ax25-node install
node install
If you found the old “node” package installed, run this command to completely remove it:
$ sudo apt-get remove --purge node
- Install gulp globally:
$ npm install --global gulp
- Install gulp in your project devDependencies:
$ npm install --save-dev gulp
- Create a
gulpfile.js
at the root of your project:
var gulp = require('gulp');
gulp.task('default', function() {
// place code for your default task here
});
- Run gulp:
$ gulp
The default task will run and do nothing.
To run individual tasks, use gulp <task> <othertask>
.
You have an empty gulpfile and everything is installed. How do you REALLY get started? Check out the recipes and the list of articles for more information.
For API specific documentation you can check out the documentation for that.
The gulp community is growing, with new plugins being added daily. See the main website for a complete list.
- Update apt sources.
$ sudo apt-get update
- Install Hexchat with apt
$ sudo apt-get install hexchat
Debian and Ubuntu (deb/apt)
To install Atom on Debian, Ubuntu, or related distributions, add our official package repository to your system by running the following commands:
- Install key
$ wget -qO - https://packagecloud.io/AtomEditor/atom/gpgkey | sudo apt-key add -
$ sudo sh -c 'echo "deb [arch=amd64] https://packagecloud.io/AtomEditor/atom/any/ any main" > /etc/apt/sources.list.d/atom.list'
- Update apt sources
$ sudo apt-get update
- You can now install Atom using apt-get (or apt on Ubuntu):
$ sudo apt-get install atom
$ sudo apt-get install atom-beta
- Change to your sites directory: (Hopefully you created a symlink. If you didn’t then use $ cd /var/www/html):
$ cd sites
- Download Drupal:
$ sudo drush dl drupal --drupal-project-rename=site_directory_name
- Change to the site_directory_name
$ cd site_directory_name
- Drupal Site Install. This will also create your settings.php file:
$ drush si standard --account-name=admin --account-pass=admin --db-url=mysql://database_user_name:database_user_password@localhost/database_name
Note: as mentioned in previous steps, if this was your first time running through this, replace your account-name, account-pass, database_user_name, and database_user_password with the sample "root"
- Compressed database dump from old site in (mysql.zip or mysql.gz)
- All of the files or ability to git clone the files of the old site ** If you are not able to get a db dump and need to use backup and migrate module, Please follow a different set of directions, posted on page 10.
- Open browser and navigate to localhost/phpMyAdmin
- Create new database for your site. Example: oldsite or old_site
- Click on the newly created database
- Choose import, navigate to the compressed db file (mysql.gz) and click go
- Open the Hosts file:
$ sudo nano /etc/hosts
- Add under the last line
# Drupal sites
127.0.0.1 oldsite.local
-
Press CTRL+o (to save)
-
Press Enter
-
Press CTRL+x (to exit)
- Navigate to /sites (or /var/www/html if you didn’t create a symlink)
- Change the name of your folder to oldsite.local (basically we are adding .local and making sure the name of this folder matches the oldsite.local name in the hosts file)
- Navigate into the sites/default folder and delete any old settings.php
- Copy default.settings.php and rename it: settings.php
- Open the settings.php file:
$ sudo nano sites/default/settings.php
- You can copy/paste this into settings.php around line 219. Look for:
$databases = array();
$databases = array (
'default' =>
array (
'default' =>
array (
'database' => 'DATABASENAME',
'username' => 'root',
'password' => 'root',
'host' => 'localhost',
'port' => '',
'driver' => 'mysql',
'prefix' => '',
),
),
);
- Change
'database' => 'DATABASENAME',
to your oldsite database name - If your local phpMyAdmin has a different pw than root/root then change that too
- Press CTRL+o (to save)
- Press Enter
- Press CTRL+x (to exit)
- Navigate to localhost/oldsite.local
- You will need your old username/password as it is stored in the database to log in
- All of the files or ability to git clone the files of the old site
- Backup of the oldsite using backup_migrate module
- Open browser and navigate to localhost/phpmyadmin
- Create new database for your site. example: oldsite or old_site
- Open the Hosts file:
$ sudo nano /etc/hosts
- Add under the last line
# Drupal sites
127.0.0.1 oldsite.local
- Press CTRL+o (to save)
- Press Enter
- Press CTRL+x (to exit)
- Navigate to /sites (or /var/www/html if you didn’t create a symlink)
- Change the name of your folder to oldsite.local (basically we are adding .local and making sure the name of this folder matches the oldsite.local name in the hosts file)
- Navigate into the sites/default folder and delete any old settings.php
- Copy default.settings.php and rename it: settings.php
- In your browser, navigate to localhost/oldsite.local
- Complete the install process, making sure to complete the section when it asks for the database name and password.
- cd into the root of the oldsite.local
- Download the backup_migrate module:
$ drush dl backup_migrate
- Enable the backup_migrate module:
$ drush en backup_migrate
- Log into your site, go to configuration management, and restore backup_migrate database as usual
- Reset the admin username/password (assuming admin is the username)
- cd to the root of your oldsite.local
- Set username and password:
$ drush user-password admin --password=newpassword
- Only the front page shows, 404 on any other nodes
- Make sure there is an .htaccess file in the root of the site * If it is missing, simply copy/paste .htaccess into the root of your oldsite.local from another drupal site
- If .htaccess is there and still having issues, check for clean urls 2. In the browser, navigate to localhost/oldsite.local/?q=admin/config/search/clean-urls 3. There should be a checkmark and option to run clean urls 4. For additional clean url troubleshooting: https://www.drupal.org/node/15365 5. In the meantime, you can still painfully navigate the site with /?q=
- Missing images * If you git cloned, your files folder will be empty. Grab the files folder from the old site and place in sites/default/
- White screen of death (WOD):
$ drush updb
$ drush cr all