Project

General

Profile

Set up a New Website » History » Revision 6

Revision 5 (Jon Goldberg, 11/21/2017 08:42 PM) → Revision 6/17 (Jon Goldberg, 11/21/2017 09:51 PM)

{{last_updated_at}} by {{last_updated_by}} 

 {{>toc}} 

 # Set up a New Website 

 -     TODO: Let's Encrypt 

 ## Overview 

 Use this document when a) creating a new Drupal/WordPress site, or b) when you need to clone an existing site (create a live or test site from a local dev or existing live site). 

 If you don't have a Bitbucket repo to store the site, you must first [Create a Site Repo](Create-a-Site-Repo_88002545.html). 

 ## Create DNS records 

 If this is a live site, obtain the namehost credentials from the client.  If this is a test site, use the [DNS Management](DNS-Management_88003176.html) documentation.  Test sites 
 have a domain name of "example.megaphonetech.com", where "example" is replaced by the shortname of the client (e.g. "nwu.megaphonetech.com"). 

 ## Cloning an Existing Site 

 *Use these instructions if the site already has a git repo.* 

 * Clone the existing git repo. 
 * Move to the newly created directory and initialize git. 
 * Add origin as a remote (substitute the correct repo name below). 

 ~~~ shell 
 # Could be /home, could be /var/www, check where other sites on the server are (if any). 
 cd /home 
 mkdir -p clone.example.org/htdocs 
 cd clone.example.org/htdocs 
 git init 
 # substitute your own repo name for "example" 
 git remote add origin ssh://git@git.megaphonetech.com:10022/megaphone/example.git 
 # Next line is optional, and shouldn't happen on local dev machines.    It allows pushing when your git remote is read-only. 
 git config remote.origin.pushurl https://git.megaphonetech.com/megaphone/example.git 
 git pull origin master 
 git submodule update --init --recursive 
 git branch --set-upstream master origin/master 
 ~~~ 

 ### Copy/edit settings.php/civicrm.settings.php/wp-config.php 

 *Skip this step if this is a new site from scratch (i.e. not a clone ofan existing site). 

 The git repo does NOT include settings.php or civicrm.settings.php. These files contain the server-specific settings - so we don't want to accidentally overwrite them with settings from another server. Instead, copy the settings from the server you just cloned. 

 Copy settings from an existing server: 

 ~~~ shell 
 # Copy settings.php (Drupal) file from the old server 
 scp curds:/var/www/staging/cpehn/sites/default/settings.php . 
 # For CiviCRM on Drupal: 
 scp curds:/var/www/staging/cpehn/sites/default/civicrm.settings.php . 
 # If WordPress: 
 scp curds:/var/www/staging/aclu/wp-config.php . 
 # For CiviCRM on WordPress: 
 scp curds:/var/www/staging/aclu/wp-content/plugins/civicrm/civicrm.settings.php . 

 # Copy those files to your local install: 
 # For example: cp ./settings.php /home/jon/local/cpehn/sites/default 
 ~~~ 

 For Drupal, you must edit the file and change the database name, MySQL username, and MySQL password to match the new server's settings. 

 For Wordpress, you must change the database name, MySQL username, MySQL password, and WP\_HOME and WP\_SITEURL if defined. You must also run `wp search-replace www.oldsitename.org www.newsitename.org` after the database is loaded. 

 For CiviCRM, you must do edit the same settings twice (once for the CMS, once for CiviCRM), plus change the \$BASE\_URL and all file paths for cache files, overrides, etc.  For non-live states, you should also uncomment the `CIVICRM_MAIL_LOG` definition. 

 ### Disable forced SSL if applicable 

 TODO: Write this section. Or not, if we move to SSL everywhere using 
 Let's Encrypt. In that case, write a Let's Encrypt section. 

 ## Create a New Site from Scratch 

 ### drush instructions (Drupal only) 

 *Skip drush instructions if a) you're cloning an existing site (e.g. creating a test server from an existing dev/live server) AND b) the site isn't hosted on a server with a shared Drupal install (i.e. on May First).* 

 * While in either `/var/www/dev/` or `/var/www/staging`, run the following command to download the latest version of Drupal 7 or 8: 

 ~~~ shell 
 drush dl drupal-7 
 drush dl drupal-8 
 ~~~ 

 * Rename the Drupal directory to something that makes sense for the new site 

 ~~~ shell 
 mv drupal-7.34/ healtorture/ 
 ~~~ 

 ### wp instructions (WordPress only) 

 *Skip wp instructions if you're cloning an existing site (e.g. creating a test server from an existing dev/live server).* 

 * While in `/home` (or `/var/www`), run the following command to download the latest version of WordPress: 

 ~~~ shell 
 wp core download 
 ~~~ 

 ## All Sites 

 ### MySQL instructions - all sites 
 * Create the MySQL database and associated user as listed in settings.php/wp-config.php/civicrm.settings.php: 

 ~~~ sql 
 #Drupal example 
 CREATE DATABASE nwu_drupal; 
 #WordPress example 
 CREATE DATABASE nwu_wp; 
 #CiviCRM example 
 CREATE DATABASE nwu_civi; 

 CREATE USER 'nwu'@localhost IDENTIFIED BY 'blahblahblahsomepassword'; 

 #Drupal/Wordpress 
 GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, LOCK TABLES, CREATE TEMPORARY TABLES, CREATE VIEW ON nwu_wp.* TO 'nwu'@localhost; 
 #CiviCRM 
 GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, LOCK TABLES, CREATE TEMPORARY TABLES, TRIGGER, CREATE ROUTINE, ALTER ROUTINE, CREATE VIEW, REFERENCES ON nwu_civi.* TO 'nwu'@localhost; 
 ~~~ 

 ### MySQL instructions - cloned sites 

 *These instructions only apply to git cloned sites. Drupal/Civi/WordPress create a blank database on install for brand new sites.* 

 *TODO: Document use of "drush pipe" and similar commands* 

 * On the OLD server, dump a copy of the database(s) you need: 

 ~~~ shell 
 #Drupal  
 drush sql-dump > ~/cpehn_drupal.sql  
 #CiviCRM with Drupal  
 drush civicrm-sql-dump > ~/cpehn_civi.sql  
 #WordPress (note - no ">" redirection)  
 wp db export ~/aclu_wp.sql  
 #CiviCRM with WordPress  
 wp civicrm-sql-dump > ~/aclu_civi.sql  
 #Remove trigger definers from Civi dumps 
 perl -pi -e 's#\/\*\!5001[7|3].*?`[^\*]*\*\/##g' aclu_civi.sql 
 ~~~ 

 * Copy the database(s) to your local machine (and then to another machine, if need be: 

 ~~~ shell 
 scp aclu:~/*sql . 
 ~~~ 

 * Import your database(s): 

 ~~~ shell 
 #Drupal  
 drush sql-cli < ~/cpehn_drupal.sql  
 #CiviCRM with Drupal  
 drush civicrm-sql-cli < ~/cpehn_civi.sql  
 #WordPress (note - no "<" redirection)  
 wp db import ~/aclu_wp.sql  
 #CiviCRM with WordPress  
 wp civicrm-sql-cli < ~/aclu_civi.sql 
 ~~~ 

 * \[WordPress Only\] Run `wp search-replace` to change all instances 
     of the old URL in the database to the new URL.  E.g. 
     `wp search-replace nwu.org nwu.jmaconsulting.biz`. 

 ### Apache instructions 

 * Create an entry in /etc/apache2/sites-available for this site by copying a previous entry, then editing that entry to reflect the new site 
 * In /etc/apache2/sites-enabled, enable the new site: 

 
 ~~~ shell 
 a2ensite healtorture.palantetech.coop 
 ~~~ 
 -     Reload apache: `sudo service apache2 reload` 

 ### DNS instructions 

 If this is a site on the public Internet, create a DNS entry for it. Test sites: Add a CNAME DNS entry by logging into the MFPL control panel 
 ([https://members.mayfirst.org/cp](https://members.mayfirst.org/cp)), going to the "Palante Technology:[palantetech.com](http://palantetech.com)" \ 
 Live sites: Add the DNS entry using the client's DNS system. You'll need 
 the namehost password from the client. You can often figure out the 
 namehost with `whois example.org` and looking for the "Name Server" 
 listing. 

 Local dev sites: You don't create a public DNS entry if the site isn't publicly accessible. Edit the `/etc/hosts` file on any machine that can see the site. 
 Examples if the site is hosted on the same computer you use: 

     127.0.0.1 ajla.local  

 Example if the site is on a virtual machine at IP address 192.168.1.6: 

     192.168.1.6 ajla.local 

 ### Run the installer 

 If this is a new site (not cloned), you can visit the site now to run the installer. You'll need the MySQL database name, MySQL username, and MySQL password. 

 ### Install CiviCRM 

 Follow the [official CiviCRM installation instructions](https://docs.civicrm.org/sysadmin/en/latest/index.html)