Outils pour utilisateurs

Outils du site


issue64:tutowebdev

Last month, we installed Apache2 and did a little bit of configuration. This month we will be installing and configuring MySQL, PHP, and CouchDB. MySQL is a relational database, and CouchDB is a non-relational database. We will get familiar with both types of databases over the life of this article. PHP is a server-side language that allows us to do all sorts of amazing things. CouchDB is the starting point of this article. Even though it is not traditionally part of the LAMP stack, installing it now and learning it will be beneficial to your skills as a web developer. We are not going to go over any configurations for this until it is time to start using it. This way, you will know which settings you want to change, and what you want to change the values to. Start by updating and upgrading your software and then apt-get couchdb: sudo apt-get update sudo apt-get upgrade sudo apt-get install couchdb

Le mois dernier, nous avons installé Apache2 et fait un peu de configuration. Ce mois-ci, nous allons installer et configurer MySQL, PHP et CouchDB. MySQL est une base de données relationnelle et CouchDB est une base de données non relationnelle. Nous allons nous familiariser avec les deux types de bases de données tout au long de cet article. PHP est un langage côté serveur qui nous permet de faire toutes sortes de choses étonnantes.

CouchDB est le point de départ de cet article. Même s'il ne fait pas traditionnellement partie du groupe LAMP, l'installer maintenant et apprendre à s'en servir augmentera vos compétences de développeur web. Nous n'allons pas examiner de configurations pour cela avant d'avoir besoin de l'utiliser. De cette façon, vous saurez quels paramètres vous souhaitez modifier et les nouvelles valeurs que vous voudrez avoir. Commencez par mettre à jour et à niveau votre logiciel d'installation, puis apt-get couchdb :

sudo apt-get update

sudo apt-get upgrade

sudo apt-get install couchdb

Yes, it really is that simple to install a lot of things. The next installation is just as easy, and it prompts you only to set a “root” password. Please note, that just because it says root password, this is not referring to the server’s root password. Make a note of this password, as this will identify the user with the ultimate power in the databases. Ok, let’s get to the installing: sudo apt-get install mysql-server The next part asks you a few questions regarding the security of your database. I suggest answering with “Y” to all of them. The question specifically asks about remote access with the root user. This disallows any access to MySQL unless you are on the same server (SSH to the server, and then logging in is still allowed in this scenario).

Oui, c'est vraiment aussi simple d'installer un tas de choses. L'installation suivante est tout aussi facile et on ne vous demande que de donner un mot de passe « root ». Merci de noter que même s'il dit mot de passe root, cela ne fait pas référence au mot de passe root du serveur. Notez ce mot de passe, car il permettra d'identifier l'utilisateur ayant le pouvoir ultime dans les bases de données. Ok, passons à l'installation :

sudo apt-get install mysql-server

La partie suivante vous pose quelques questions sur la sécurité de votre base de données. Je suggère de répondre « Y » (yes) pour chacune d'elles. La question porte spécifiquement sur l'accès à distance avec l'utilisateur root. Cela permet d'empêcher tout accès à MySQL, sauf si vous êtes sur le même serveur (un SSH vers le serveur, puis une connexion, est autorisé avec cette configuration).

mysql_secure_installation Now that you are all done with the installation and basic configuration of MySQL, you need to test it to make sure everything is working fine. To login, simply type in “mysql -u root -p” into the terminal. It will prompt you for the password you just set, and, upon successful entry, you will be greeted with the mysql prompt that usually looks like this: “mysql>”. aliendev@server:~$ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 310 Server version: 5.1.61-0ubuntu0.10.10.1 (Ubuntu) Copyright © 2000, 2011, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>

mysql_secure_installation

Maintenant que l'installation et la configuration de base de MySQL sont terminées, vous devez le tester pour vous assurer que tout fonctionne bien. Pour vous connecter, il suffit de taper « mysql -u root -p » dans le terminal. Il vous demandera d'entrer le mot de passe que vous venez de définir et, dès l'entrée réussie, vous serez accueillis avec l'invite de commande mysql qui ressemble généralement à ceci : « mysql> ».

aliendev@server:~$ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 310 Server version: 5.1.61-0ubuntu0.10.10.1 (Ubuntu)

Copyright © 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

We are almost done, with just one last thing to get set-up. PHP5 is a widely used server-side language that will help you in the long run (even if you don’t use it). To install it is very simple: sudo apt-get install php5 php-pear Going forward, you will want to make sure the following values are set in the php.ini (PHP’s configuration file), and relevant lines are uncommented (the commented lines start with a semicolon, uncommenting them is as easy as removing the semicolon). So, open up the php.ini file with vi (“sudo vi /etc/php5/apache2/php.ini”), and look for these lines – hint: you can type “/” (forward slash) and a term and press enter to search in vi): max_execution_time = 30 memory_limit = 64M error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR display_errors = Off log_errors = On error_log = /var/log/php.log register_globals = Off

Nous avons presque terminé, avec juste une dernière chose à mettre en place. PHP5 est un langage largement utilisé côté serveur qui vous aidera dans le long terme (même si vous ne l'utilisez pas). Pour l'installer, c'est très simple :

sudo apt-get install php5 php-pear

Pour aller plus loin, vous vous assurerez que les valeurs suivantes sont définies dans le php.ini (fichier de configuration de PHP) et que les lignes concernées ne sont pas commentées (les lignes commentées commencent par un point-virgule et, pour les dé-commenter, il suffit de supprimer le point-virgule). Donc, ouvrez le fichier php.ini avec vi (« sudo vi /etc/php5/apache2/php.ini ») et recherchez ces lignes (astuce : vous pouvez taper « / » (slash) et un terme et appuyer sur Entrée pour effectuer une recherche dans vi) :

max_execution_time = 30

memory_limit = 64M

error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR

display_errors = Off

log_errors = On

error_log = /var/log/php.log

register_globals = Off

Any time you make changes to the php.ini file, you will need to restart Apache. You can do this simply by using one of the following commands: sudo /etc/init.d/apache2 restart sudo service apache2 restart The very last thing we are going to do is add MySQL support for PHP, and install a PHP package that will add some additional security. Also note, because we are changing something that Apache will need to know, we need to restart it again. We could have waited, but I wanted to point out that there are a few ways to do this and that it needs to become a habit when making changes to Apache. sudo apt-get install php5-mysql php5-suhosin sudo service apache2 restart Congratulations, you officially have a LAMP stack, and we can start developing next month. Cheers!

À chaque fois que vous apporterez des modifications au fichier php.ini, vous devrez redémarrer Apache. C'est très simple, il suffit d'utiliser l'une des commandes suivantes :

sudo /etc/init.d/apache2 restart

sudo service apache2 restart

La dernière chose que nous allons faire est d'ajouter la prise en charge de MySQL par PHP et d'installer un paquet PHP qui va ajouter de la sécurité supplémentaire. A noter également que, parce que nous changeons quelque chose qu'Apache devra connaître, nous devons le redémarrer à nouveau. Nous aurions pu attendre, mais je tenais à souligner qu'il existe plusieurs façons de le faire et que cela doit devenir une habitude lors de changements dans Apache.

sudo apt-get install php5-mysql php5-suhosin

sudo service apache2 restart

Félicitations, vous avez officiellement une architecture LAMP et nous pourrons commencer à développer le mois prochain. Salut !

issue64/tutowebdev.txt · Dernière modification : 2012/10/07 21:41 de fredphil91