# Procédure Apache: PMA et BDD à distance

Pour les besoin de mon site, je devais séparer la base de donnée des fichiers de mon site. Voici donc un tuto qui explique comment faire.

DEB1: Debian avec apache, PhpMyAdmin  
DEB2: Debian avec My SQL

### <span style="font-weight: 400;">Installation de DEB1</span>

<span style="font-weight: 400;">Après avoir installé le debian et avoir fait les mises à jour, vous pouvez installer Apache2</span>

`<span style="font-weight: 400;">apt-get install apache2</span>`

<span style="font-weight: 400;">Une fois l’installation faite on vérifie si apache à bien mis en place le site par défaut. Pour cela on récupère l’IP de la VM avec la commande </span>

`<span style="font-weight: 400;">ip a</span>`

![](https://doc.ataxya.net/uploads/images/gallery/2019-05/scaled-840-/giWpyLdGrbdSp3tD-image-1558689779149.png)

<span style="font-weight: 400;">On n’a plus qu’à rentrer l’IP dans un navigateur et voila!</span>

![](https://doc.ataxya.net/uploads/images/gallery/2019-05/scaled-840-/V8SGcosXhHrnd2YY-image-1558689808979.png)

<span style="font-weight: 400;">Nous avons bien la page par défaut d’Apache, ce qui signifie que notre serveur Web est en place !</span>

<span style="font-weight: 400;">Nous pouvons donc maintenant installer PhpMyAdmin, qui est une interface de gestion de base de données simplifié. Pour cela:</span>

`<span style="font-weight: 400;">apt-get install phpmyadmin</span>`

![](https://doc.ataxya.net/uploads/images/gallery/2019-05/scaled-840-/DfmUpZeL5vtCZGnK-image-1558689850576.png)

![](https://doc.ataxya.net/uploads/images/gallery/2019-05/scaled-840-/fgT161ZkMWKUyC9A-image-1558689871340.png)

![](https://doc.ataxya.net/uploads/images/gallery/2019-05/scaled-840-/73l8Q94qbqLno69t-image-1558689882543.png)

<span style="font-weight: 400;">Ici nous avons une erreur, ce qui est parfaitement normal puisqu’il n’y a pas de base de données sur ce serveur. On choisi ignorer, et l’installation va se finir</span>

![](https://doc.ataxya.net/uploads/images/gallery/2019-05/scaled-840-/TSjMCFAh9w9kln3J-image-1558689911201.png)

<span style="font-weight: 400;">Pour des raisons de simplicité on va déplacer l’interface phpmyadmin directement dans le dossier www. Pour cela:</span>

`<span style="font-weight: 400;">mv /usr/share/phpmyadmin /var/www/html</span>`

### ![](https://doc.ataxya.net/uploads/images/gallery/2019-05/scaled-840-/6E2aoe12zy8k2psq-image-1558689942898.png)

### <span style="font-weight: 400;">Installation de DEB2</span>

<span style="font-weight: 400;">Une fois l’installation de Debian et les mises à jours faites, installer MySQL à l’aide de la commande suivante</span>

`<span style="font-weight: 400;">apt-get install mysql-server</span>`

<span style="font-weight: 400;">Une fois l’installation faite, on vérifie son fonctionnement avec la commande </span>

<span style="font-weight: 400;">`mysql` </span>

<span style="font-weight: 400;">On arrive dans la console mysql,ce qui prouve le bon fonctionnement !</span>

![](https://doc.ataxya.net/uploads/images/gallery/2019-05/scaled-840-/7HahecO3mWGT12Eb-image-1558689992598.png)

<span style="font-weight: 400;">On va créer une base de données test:</span>

`<span style="font-weight: 400;">mysql<br></br></span><span style="font-weight: 400;">create database bddsite character set utf8;<br></br></span><span style="font-weight: 400;">grant all privileges on *.* to root@’192.168.%.%’ identified by ‘root’<br></br></span><span style="font-weight: 400;">exit</span>`

### <span style="font-weight: 400;">Configuration de DEB1</span>

<span style="font-weight: 400;">Une fois la base de donnees en place, on va pouvoir la mettre dans la configuration de PhpMyAdmin: Pour cela, éditez le fichier de configuration suivant:</span>

`<span style="font-weight: 400;">nano /etc/phpmyadmin/config.inc.php</span>`

<span style="font-weight: 400;">Ajoutez les lignes suivantes en bas de la configuration</span>

![](https://doc.ataxya.net/uploads/images/gallery/2019-05/scaled-840-/RNhaiZCycJZtDXy4-image-1558690103832.png)

<span style="font-weight: 400;">Enregistrez, et redémarrez apache</span>

`<span style="font-weight: 400;">/etc/init.d/apache2 restart</span>`

### <span style="font-weight: 400;">Configuration de DEB2</span>

<span style="font-weight: 400;">Pour pouvoir autoriser la connexion à distance à la BDD, il faut éditer le fichier suivant</span>

`<span style="font-weight: 400;">nano /etc/mysql/mariadb.conf.d/50-server.cnf</span>`

<span style="font-weight: 400;">Et remplacer le bind-address par 0.0.0.0</span>

![](https://doc.ataxya.net/uploads/images/gallery/2019-05/scaled-840-/sDOoNQWslAAcDUn0-image-1558690175233.png)

<span style="font-weight: 400;">Redémarrez mysql à l’aide de la commande:</span>

`<span style="font-weight: 400;">/etc/init.d/mysql restart</span>`

### <span style="font-weight: 400;">Test connexion à la BDD</span>

<span style="font-weight: 400;">Une fois la configuration faite, on peux se connecter à PhpMyAdmin</span>

`<span style="font-weight: 400;">http://ip/phpmyadmin</span>`

<span style="font-weight: 400;">Dans choix du serveur, pensez à mettre le serveur </span><span style="font-weight: 400;">distant</span>

![](https://doc.ataxya.net/uploads/images/gallery/2019-05/scaled-840-/ntsgyZhwgc4lnchV-image-1558690244973.png)

<span style="font-weight: 400;">Et ça fonctionne !</span>

![](https://doc.ataxya.net/uploads/images/gallery/2019-05/scaled-840-/D4K4L4GtqUhDHA56-image-1558690275054.png)