Skip to content

Instantly share code, notes, and snippets.

@raulqf
Last active March 29, 2018 13:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raulqf/8785d5c52084dcbad7438c05c5d16fba to your computer and use it in GitHub Desktop.
Save raulqf/8785d5c52084dcbad7438c05c5d16fba to your computer and use it in GitHub Desktop.
How to Migrate your Drupal site to a new Virtual Machine using Ubuntu

Export the drupal site

  1. Export the database using the export functionality from phpmyadmin. Use the default configuration - Quick, Format SQL. Remember to select the database to export before accessing to this operation. How to install phpmyadmin

  2. Compress the web page code to send to the new virtual machine. You can do it by the following command:

     $ tar -czvf name-of-archive.tar.gz /path/to/directory-or-file
    

Install Apache in the new machine

The following packages must be installed (remove the comments):

    $ sudo apt-get install vim  //vim editor
    $ sudo apt-get install a2ensite  //apache module to enable sites 
    $ sudo apt-get install apache2  //apache itself
    $ sudo /etc/init.d/apache2 restart  //restart apache to aply the changes
    $ sudo apt-get install php7.0 //install php - version 7.0 can change concerning your distro (Ubuntu 16.04LTS)
    $ sudo apt-get install libapache2-mod-php7.0  //apache module for php. Be aware of the version
    $ sudo /etc/init.d/apache2 restart //restart again
    $ sudo apt-get install mysql-server //install mysql server, you must define the root password for the master table
    $ sudo apt-get install php7.0-mysql //package to run mysql with php

To check if the installation have succeded, you must see the apache default web page if you insert your virtual machine ip in your browser.

Now, we have to configure apache to point to our site. To this end we must configure a virutal host.

Configure Virtual Host

  1. Go to the sites-available directory from your apache2 installation and configure the respective file.

     $ cd /etc/apache2/sites-available
     $ sudo cp 000-default.conf oursite.conf
     $ vim oursite.conf
    
  2. Configure the file similar to the following example:

    <VirtualHost *:80>
      ServerAdmin oursite@oursite.com
      ServerName oursite.com
      ServerAlias www.oursite.com
      DocumentRoot /var/www/html/index.php
    
      <Directory /var/www/html/oursite>
       Options FollowSymlinks
       AllowOverride All
      </Directory>
      
      # AllowOverride All to allow the use of .htaccess files
    
      ErrorLog ${APACHE_LOG_DIR}/error.log
      CustomLog ${APACHE_LOG_DIR}/access.log combined
    
     </VirtualHost>
    
  3. Enable the site using the a2ensite previously installed:

     $ sudo a2ensite oursite.conf //run this command from the sites-availabe directory
    
  4. Restart apache

    $ sudo service apache2 restart //restart again
    

Import database using phpmyadmin

First of all we must configure php to accept larger files to be uploaded. We must then modify the following file:

   $ sudo nano /etc/php/7.0/apache2/php.ini

Values to be modified are these three:

   upload_max_filesize = 1000M
   memory_limit = 1500M
   post_max_size = 1500M

Select your suitable values according to the file size of your database to be imported. After configuring thee file, we must restart apache.

Deploy Drupal Site

Once uploaded your site to the server, we must copy the drupal project to the ubuntu web folder:

  $ sudo cp drupal_site /var/www/html/drupal_site

Finally, we must check the drupal site settings to point to the target database using the respective user that has permissions over the imported database. This file is located in drupal_site/sites/default/settings.php.

Source

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment