# DSM 6



### Dossiers utilisateurs:

```bash
bruno@DS916:~ $ pwd
/var/services/homes/bruno
```

```bash
root@DS916:~# pwd
/root
```



### Se connecter en root:

```bash
bruno@DS916:~ $ sudo -su root
Password:
sh-4.3#
```

```bash
bruno@DS916:~ $ sudo -i
root@DS916:~#
```



### Services:

#### Afficher la liste des services

```bash
root@DS916:~# synoservicecfg --list
DSM
apparmor
atalk
avahi
bluetoothd
bonjour
btacd
```

#### Gérer les services de DSM

```bash
synoservicecfg --list

synoservice --status

synoservicecfg --stop <service>

synoservicecfg --hard-stop <service>

synoservicecfg --start <service>

synoservicecfg --hard-start <service>

synoservice --restart <service>

synoservicectl --restart <service>
```

#### Redémarrer un service

```bash
/usr/syno/sbin/synoservicecfg -restart  syslog-acc
```



### Afficher les logs de connection ssh dans /var/log/message:

- Créer en tant que root le fichier /usr/local/etc/syslog-ng/patterndb.d/sshd.conf comme suit :

```bash
filter f_messages {
        level(info..emerg)
        and not facility( mail, news, cron)
        and not program(syslog-ng)
        and not filter(f_local)
        and not filter(f_synology);
};
```

- Faire un chmod 644 sur le fichier /usr/local/etc/syslog-ng/patterndb.d/sshd.conf créé.

```bash
DS414> cd /usr/local/etc/syslog-ng/patterndb.d/
-rw-rw-rw- 1 root root  454 Jul 16 19:15 sshd.conf
-rw-r--r-- 1 root root  454 Jul 11 15:15 VideoStation.conf
DS414> chmod 644 sshd.conf
-rw-r--r-- 1 root root  454 Jul 16 19:15 sshd.conf
-rw-r--r-- 1 root root  454 Jul 11 15:15 VideoStation.conf
```

- Relancer le syslog pour prise en compte du fichier (sinon un reboot du NAS) :

```bash
DS414> synoservicecfg --restart syslog-acc
```



### Installer un paquet .deb

```bash
# echec pour un problème de signature
$ sudo dpkg -i nano_2.7.4-1_i386.deb
Password:
Authenticating nano_2.7.4-1_i386.deb ...
debsig: Origin Signature check failed. This deb might not be signed.

dpkg: error processing nano_2.7.4-1_i386.deb (--install):
 verification on package nano_2.7.4-1_i386.deb failed!
Errors were encountered while processing:
 nano_2.7.4-1_i386.deb
 
# option --force-bad-verify
$ sudo dpkg -i --force-bad-verify nano_2.7.4-1_amd64.deb
Authenticating nano_2.7.4-1_amd64.deb ...
debsig: Origin Signature check failed. This deb might not be signed.

dpkg: verification on package nano_2.7.4-1_amd64.deb failed; but installing anyway as you requested
Selecting previously unselected package nano.
(Reading database ... 118 files and directories currently installed.)
Unpacking nano (from nano_2.7.4-1_amd64.deb) ...

# supprimer le paquet debsig-verify
$ dpkg --purge dpkg-verify
```



### Apache:

#### Configuration:

Les fichiers .conf se trouvent dans `/usr/local/etc/apache22 `ou `/usr/local/etc/apache24`

Editer le Le fichier de conf principal:  `nano /usr/local/etc/apache22/conf/httpd22.conf`

Il est conseillé de faire les modifications dans `/usr/local/etc/apache22/sites-enabled`

#### Logs:

Ils sont dans `/var/log/httpd`

```bash
/var/log/httpd $ ls -la
total 540
drwxr-xr-x  2 root   root   4096 Nov 16 03:07 .
drwxr-xr-x 17 root   root   4096 Mar  9 01:15 ..
-rw-r--r--  1 root   root    176 Oct  9 10:10 access_log
-rw-rw----  1 system log  146142 Mar 13 09:50 apache22-error_log
-rw-rw----  1 system log   58824 Nov 16 02:05 apache22-error_log.1.xz
-rw-rw----  1 system log   25992 Dec 11  2016 apache22-error_log.2.xz
-rw-rw----  1 system log    2106 Jan  9  2017 apache24-error_log
-rw-r--r--  1 root   root    363 Oct  9 10:09 error_log
-rw-rw----  1 system log  283282 Nov  2  2016 user-error_log
```

#### Redémarrer Apache:

`synoservice --restart pkgctl-WebStation`

`synoservice --restart pkgctl-Apache2.2`

service [pkgctl-Apache2.2] restart failed, synoerr=[0x2000]

#### Liste des modules Apache:

```bash
$ httpd22 -M
Loaded Modules:
 core_module (static)
 mpm_worker_module (static)
 ...
```



### php7.0

```bash
$ php70 --ini
Configuration File (php.ini) Path: /usr/local/etc/php70
Loaded Configuration File:         /usr/local/etc/php70/php.ini
Scan for additional .ini files in: /usr/local/etc/php70/conf.d
Additional .ini files parsed:      /usr/local/etc/php70/conf.d/SYNO.SDS.PhotoStation.ini
```

#### open_basedir

`/tmp:/var/services/tmp:/var/services/web:/var/services/homes:/dev/urandom:/volume1/dokuwiki:/volume1/Repositories:/volume1/nextcloud`

#### php.ini

`extension_dir = "/usr/local/lib/php70/modules"`

#### logs

Web Station -> Paramètres PHP-> Paramètres Avancés -> Coeur -> error_log

#### Connaitre les extensions chargées par PHP CLI:

```bash
$ php -m
[PHP Modules]
apcu
bz2
calendar
Core
ctype
curl
date
dom
exif
fileinfo
filter
gd
hash
iconv
json
libxml
mbstring
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_pgsql
pdo_sqlite
pgsql
readline
Reflection
session
SimpleXML
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
Zend OPcache
zip
zlib

[Zend Modules]
Zend OPcache
```



#### PHP 7.0.13: curl n'est pas activé:

- Ouvrir /volume1/@appstore/PHP7.0/misc/extension_list.json

```bash
root@DS916:/volume1/@appstore/PHP7.0/misc# ls -la
total 24
drwxr-xr-x 1 root root  134 Jan  7 09:08 .
drwxrwxrwx 1 root root   46 Jan  5 17:22 ..
-rw-r--r-- 1 root root 5082 Dec 19 12:20 extension_list.json
-rw-r--r-- 1 root root 5082 Jan  7 09:08 extension_list.json.bak
-rw-r--r-- 1 root root  147 Dec 19 12:20 logrotate.conf
-rw-r--r-- 1 root root  174 Dec 19 12:20 syslog.conf
root@DS916:/volume1/@appstore/PHP7.0/misc# nano extension_list.json
```

- Ajouter

```bash
       "curl": {
               "enable_default": true,
               "desc": "The curl extension allows you to connect and communicate to many different types of servers wih many different types of protocols."
       },
```

- Aller dans Web Station → Paramètres PHP → version 7.0
- Cocher, décocher et recocher pour activer l'extension (en appliquant à chaque fois)

[:fa-link: Source](https://forum.synology.com/enu/viewtopic.php?f=20&t=104368&p=464772#p464534)



### Les 3 versions de PHP:

- PHP 5.6 (BusyBox)
  /bin/php
- PHP 5.6 (Package PHP 5)
  /usr/local/bin/php56
- PHP 7.0 (Package PHP 7)
  /usr/local/bin/php70

Pour Apache, c'est la version choisie dans WebStation qui est active.

<u>En ligne de commande, par défaut, c'est la version Busybox qui est active:</u>

```bash
$ which php
/bin/php

$ php -v
PHP 5.6.11 (cli) (built: Jun  8 2018 15:13:30)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies

$ php --ini
Configuration File (php.ini) Path: /etc/php
Loaded Configuration File:         /etc/php/php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed:      (none)
```

Les 2 autres versions sont néanmoins disponibles:

```bash
$ which php56
/usr/local/bin/php56

$ php56 -v
PHP 5.6.36 (cli) (built: May  2 2018 16:13:10)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies

$ php56 --ini
Configuration File (php.ini) Path: /usr/local/etc/php56
Loaded Configuration File:         /usr/local/etc/php56/php.ini
Scan for additional .ini files in: /usr/local/etc/php56/conf.d
Additional .ini files parsed:      /usr/local/etc/php56/conf.d/phpMyAdmin.ini,
/usr/local/etc/php56/conf.d/webstation-extensions.ini


$ which php70
/usr/local/bin/php70

$ php70 -v
PHP 7.0.30 (cli) (built: May  2 2018 16:29:25) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.30, Copyright (c) 1999-2017, by Zend Technologies
    
$ php70 --ini
Configuration File (php.ini) Path: /usr/local/etc/php70
Loaded Configuration File:         /usr/local/etc/php70/php.ini
Scan for additional .ini files in: /usr/local/etc/php70/conf.d
Additional .ini files parsed:      /usr/local/etc/php70/conf.d/SYNO.SDS.PhotoStation.ini
```

Mettre PHP70 par défaut en CLI:

```bash
# On renomme PHP Busybox
$ cd /bin
$ mv php php_5.6.11
$ ls -la
-rwxr-xr-x  1 root   root 6600840 Jun  8 10:31 php_5.6.11

# On crée un lien symbolique 
$ cd /usr/local/bin
$ ln -s /var/packages/PHP7.0/target/usr/local/bin/php70 php

$ which php
/usr/local/bin/php

$ php --ini
Configuration File (php.ini) Path: /usr/local/etc/php70
Loaded Configuration File:         /usr/local/etc/php70/php.ini
Scan for additional .ini files in: /usr/local/etc/php70/conf.d
Additional .ini files parsed:      /usr/local/etc/php70/conf.d/SYNO.SDS.PhotoStation.ini
```



### Composer:

<u>Installation:</u>

```bash
root@DS916:/usr/local/bin# curl -s http://getcomposer.org/installer | php70
All settings correct for using Composer
Downloading...

Composer (version 1.6.3) successfully installed to: /usr/local/bin/composer.phar
Use it: php composer.phar
```

<u>Installation des dépendances de l'application (ici Gitlist):</u>

```bash
bruno@DS916:/volume1/web/gitlist $ php70 /usr/local/bin/composer.phar install
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 62 installs, 0 updates, 0 removals

- Installing symfony/process (v3.4.6): Downloading (100%)
```

<u>Pour simplifier l'utilisation:</u>

- Créer un script **composer.sh** dans `/usr/local/bin`
- Ajouter le contenu suivant:

```bash
#!/bin/bash
php70 -d extension=phar.so /usr/local/bin/composer.phar $*
```

- Rendre le script exécutable et le renommer:

```bash
$ chmod +X composer.sh

$ mv composer.sh composer
```

- Utilisation:

```bash
$ composer about
Composer - Package Management for PHP
Composer is a dependency manager tracking local dependencies of your projects and libraries.
See https://getcomposer.org/ for more information.
```

- Mise à jour:

```bash
$ sudo composer self-update 
You are already using composer version 1.7.1 (stable channel).
```



### Erreurs:

/bin/nano

nano: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory

```bash
sudo ln -s /lib/libncurses.so.5.9 /lib/libtinfo.so.5
```

