# Installation of CiviCRM

### CiviCRM database

We create a separate database to CiviCRM

```sql
$ mysql -u root -p -h 127.0.0.1 --port=3308
mysql> CREATE DATABASE civicrm_db;
```

Then we create an user civicrm that will be use by CiviCRM to access its database

```sql
mysql> CREATE USER 'civicrm'@'127.0.0.1' IDENTIFIED BY 'civicrm_pswd';
```

Then we grant the user civicrm full access to the civicrm\_db&#x20;

```sql
mysql> GRANT ALL ON civicrm_db.* TO civicrm@127.0.0.1 IDENTIFIED BY "civicrm_pswd" WITH GRANT OPTION;
```

{% hint style="info" %}
As we plan to use the Drupal Views module to display CiviCRM data within your Drupal pages, we have to give **SELECT** permissions to Drupal database user on CiviCRM database
{% endhint %}

```sql
mysql> GRANT SELECT ON civicrm_db.* TO drupal@127.0.0.1 IDENTIFIED BY "drupal_pswd" WITH GRANT OPTION;

```

### CiviCRM installation

To install CiviCRM, we follow intructions on <https://docs.civicrm.org/sysadmin/en/latest/install/drupal7/> First we download CiviCRM from <https://civicrm.org/download>

```bash
$ wget https://download.civicrm.org/civicrm-5.7.2-drupal.tar.gz
$ tar -xvzf civicrm-5.7.0-drupal.tar.gz 
$ sudo mv civicrm /var/www/drupal/sites/all/modules
```

Then we run the Installer with the URL <https://task.woezzon.com/sites/all/modules/civicrm/install/index.php> . The Installer shows that one requirement was not fulfill. The folder **/var/www/drupal/sites/default** was not writable to **www-data** so we change the permission by giving ownership of default folder to **www-data**

```bash
$ cd  /var/www/drupal/sites
$ sudo chown -R www-data default/
```

After this, all requirement are green.

We set CiviCRM and Drupal databases settings for the Installer

#### CiviCRM Database Settings

|                    |                |
| ------------------ | -------------- |
| **MySQL serve**r   | 127.0.0.1:3308 |
| **MySQL username** | civicrm        |
| **MySQL password** | civicrm\_pswd  |
| **MySQL database** | civicrm\_db    |

#### Drupal Database Settings

|                    |                |
| ------------------ | -------------- |
| **MySQL server**   | 127.0.0.1:3307 |
| **MySQL username** | drupal         |
| **MySQL password** | drupal\_pswd   |
| **MySQL database** | drupal\_db     |

As we are ready to install, we click on "Check requirements and install CiviCRM"

After this step, everything is sucessfully installed and our CiviCRM is available throught the drupal website <https://task.woezzon.com> or with the link <https://task.woezzon.com/?q=civicrm/dashboard>

### Secure CiviCRM in Nginx

In order to secure CiviCRM we set this in the Nginx conf file

```bash
$ sudo nano  /etc/nginx/sites-enabled/task.woezzon.com.conf

# Protect CiviCRM private files
location ~* ^/sites/(.*)/files/civicrm/(ConfigAndLog|templates_c|upload|custom) {
    deny all;
}

```

### CiviCRM extension directory

We modify CiviCRM settings file so that the CiviCRM extension directory is set using settings variables. We put CiviCRM extension directory to **/var/www/drupal/sites/default/files/civicrm/ext** outside of the **$civicrm\_home** directory as suggested here <https://docs.civicrm.org/sysadmin/en/latest/customize/extensions/>

{% hint style="info" %}
CiviCRM settings file is located at **/var/www/drupal/sites/default/civicrm.settings.php**
{% endhint %}

```
$ sudo nano /var/www/drupal/sites/default/civicrm.settings.php
```

And we put in

```php
$civicrm_setting['Directory Preferences']['extensionsDir'] = '/var/www/drupal/sites/default/files/civicrm/ext';
```

{% embed url="<https://docs.civicrm.org/sysadmin/en/latest>" %}

{% embed url="<https://en.wikipedia.org/wiki/CiviCRM>" %}
