Dans ce tutoriel, nous allons vous montrer comment installer Apache, MariaDB et PHP sur FreeBSD 11. Si vous ne savez pas, FAMP est l'acronyme de FreeBSD, Apache, MySQL/MariaDB, PHP. FreeBSD 11 est la dernière version au moment où cet article a été rédigé.
Prérequis
Avant de commencer avec ce guide, vous devez au moins avoir des connaissances de base sur Linux ou Unix, connaître les commandes shell de base pour Linux ou Unix, vous connecter en tant qu'utilisateur root et, bien sûr, vous avez besoin de FreeBSD 11 installé sur votre PC ou votre serveur.
Étape 1 - Mettez à jour votre FreeBSD
Avant de continuer à installer un logiciel, nous devons d'abord mettre à jour notre système d'exploitation FreeBSD 11.
Exécutez les commandes suivantes sur votre serveur FreeBSD.
$ su # freebsd-update fetch # freebsd-update install
Si vous avez installé une mise à jour tardive, vous devriez obtenir une sortie comme celle-ci
# freebsd-update fetch src component not installed, skipped Looking up update.FreeBSD.org mirrors... 4 mirrors found. Fetching public key from update5.freebsd.org... done. Fetching metadata signature for 11.0-RELEASE from update5.freebsd.org... done. Fetching metadata index... done. Fetching 1 metadata files... done. Inspecting system... done. Preparing to download files... done. No updates needed to update system to 11.0-RELEASE-p0.
# freebsd-update install src component not installed, skipped No updates are available to install. Run '/usr/sbin/freebsd-update fetch' first.
Étape 2 - Installer le serveur Web Apache
Nous allons installer apache 2.4 à l'aide de la commande pkg.
# pkg install apache24
Si vous utilisez la commande pkg pour la première fois dans votre système d'exploitation, vous devriez recevoir une notification pour installer l'outil de gestion des packages, choisissez simplement y
# pkg install apache24 The package management tool is not yet installed on your system. Do you want to fetch and install it now? [y/N]: y
Ensuite, nous permettons à apache de s'exécuter au démarrage à l'aide de ces commandes :
# sysrc apache24_enable=yes
Démarrez le service Apache à l'aide de ces commandes :
# service apache24 start
Tester le service Web apache :
Avant de tester apache, nous devons configurer la configuration d'apache. Modifiez ce fichier en utilisant nano /usr/local/etc/apache24/httpd.conf .
# nano /usr/local/etc/apache24/httpd.conf
Recherchez et modifiez cette variable comme celle-ci en fonction de votre adresse IP ou de votre nom d'hôte. Dans cet exemple, nous utilisons l'adresse IP 192.168.14.126 :
ServerName 192.168.14.126:80
Quittez et enregistrez le fichier. Redémarrez ensuite le service Apache à l'aide de la commande ci-dessous :
# service apache24 restart
Maintenant, ouvrez votre navigateur Web et accédez à :http://IP-address/ ou http://localhost/. Vous devriez voir la page de test Apache.
Étape 3 - Installer MariaDB
MariaDB remplace MySQL. Il a le même nom de processus, la même syntaxe et la même configuration. Pour installer, exécutez ces commandes pkg suivantes :
# pkg install mariadb100-server
Copiez la configuration de l'exemple MariaDB à partir du répertoire '/usr/local/share/mysql/ ‘ à ‘/usr/local/etc/ ' :
# cp /usr/local/share/mysql/my-medium.cnf /usr/local/etc/my.cnf
Activer et démarrer le service MariaDB :
# sysrc mysql_enable=yes # service mysql-server start
Par défaut, le mot de passe root d'installation de MariaDB était vide. Pour des raisons de sécurité, nous allons créer un mot de passe root à l'aide de cette commande :
# mysql_secure_installation
Lorsque vous êtes invité "Entrez le mot de passe actuel pour root", appuyez simplement sur la touche ENTER et définissez le mot de passe deux fois. Appuyez ensuite simplement sur Y pour accepter les valeurs par défaut.
Exemple de sortie :
# mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation. Set root password? [Y/n] Y New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success! By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] ... Success! By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!
Étape 4 - Installer PHP
Nous avons besoin de php pour le contenu dynamique du serveur, pour installer PHP, exécutez ces commandes suivantes :
# pkg install mod_php56 php56-mysql php56-mysqli
Après le succès de l'installation, nous devons copier php.ini exemple de configuration :
# cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini
Mettez à jour les modifications avec cette commande :
# rehash
Nous devons configurer PHP avec le serveur Web apache, nous devons donc modifier le fichier de configuration apache à l'aide de nano :
# nano /usr/local/etc/apache24/httpd.conf
Trouvez la section DirectoryIndex et ajoutez index.php devant l'index.html existant comme indiqué ci-dessous.
[...] <IfModule dir_module> DirectoryIndex index.php index.html </IfModule> [...]
Et ensuite, ajoutez les lignes suivantes au bas du fichier de configuration Apache
<FilesMatch "\.php$"> SetHandler application/x-httpd-php </FilesMatch> <FilesMatch "\.phps$"> SetHandler application/x-httpd-php-source </FilesMatch>
Enregistrez et fermez le fichier. Nous devons redémarrer le serveur Web Apache pour modifier la configuration :
# service apache24 restart
Étape 5 :Tester PHP
Pour tester PHP, nous allons créer un exemple de script PHP en utilisant nano :
# nano /usr/local/www/apache24/data/test.php
Ajoutez la ligne suivante :
<?php phpinfo(); ?>
Enregistrez et fermez le fichier. Ouvrez le navigateur Web et accédez à l'adresse de votre serveur http://IP-Address/test.php.
Étape 6 - Installer les modules PHP (extensions)
Afin d'obtenir un fonctionnement complet de votre script PHP, nous devons parfois installer des modules PHP supplémentaires (extensions), vous pouvez ignorer cette étape si vous n'avez pas besoin d'installer d'extensions. Pour afficher la liste des modules disponibles, lancez simplement :
# pkg search php56
Exemple de sortie :
# pkg search php56 mod_php56-5.6.26 PHP Scripting Language php56-5.6.26 PHP Scripting Language php56-bcmath-5.6.26 The bcmath shared extension for php php56-bz2-5.6.26 The bz2 shared extension for php php56-calendar-5.6.26 The calendar shared extension for php php56-ctype-5.6.26 The ctype shared extension for php php56-curl-5.6.26 The curl shared extension for php php56-dba-5.6.26 The dba shared extension for php php56-dom-5.6.26 The dom shared extension for php php56-exif-5.6.26 The exif shared extension for php php56-extensions-1.0 "meta-port" to install PHP extensions php56-fileinfo-5.6.26 The fileinfo shared extension for php php56-filter-5.6.26 The filter shared extension for php php56-ftp-5.6.26 The ftp shared extension for php php56-gd-5.6.26 The gd shared extension for php php56-gettext-5.6.26 The gettext shared extension for php php56-gmp-5.6.26 The gmp shared extension for php php56-hash-5.6.26 The hash shared extension for php php56-iconv-5.6.26 The iconv shared extension for php php56-imap-5.6.26 The imap shared extension for php php56-interbase-5.6.26 The interbase shared extension for php php56-json-5.6.26 The json shared extension for php php56-ldap-5.6.26 The ldap shared extension for php php56-mbstring-5.6.26 The mbstring shared extension for php php56-mcrypt-5.6.26 The mcrypt shared extension for php php56-mssql-5.6.26 The mssql shared extension for php
Vous pouvez vérifier ce que fait chaque module à partir de la section des commentaires dans la sortie ci-dessus, ou simplement exécuter la commande suivante :
# pkg search -f php56-curl
Exemple de sortie :
# pkg search -f php56-curl php56-curl-5.6.26 Name : php56-curl Version : 5.6.26 Origin : ftp/php56-curl Architecture : freebsd:11:x86:64 Prefix : /usr/local Repository : FreeBSD [pkg+http://pkg.FreeBSD.org/FreeBSD:11:amd64/quarterly] Categories : ftp Licenses : PHP301 Maintainer : [email protected] WWW : http://www.php.net/ Comment : The curl shared extension for php Shared Libs required: libcurl.so.4 Annotations : cpe : cpe:2.3:a:php:php:5.6.26:::::freebsd11:x64 Flat size : 90.1KiB Pkg size : 26.3KiB Description : PHP, which stands for "PHP: Hypertext Preprocessor" is a widely-used Open Source general-purpose scripting language that is especially suited for Web development and can be embedded into HTML. Its syntax draws upon C, Java, and Perl, and is easy to learn. The main goal of the language is to allow web developers to write dynamically generated webpages quickly, but you can do much more with PHP. WWW: http://www.php.net/
Pour installer l'extension php, par exemple nous allons installer php56-curl, exécutez cette commande suivante :
# pkg install php56-curl
Pour prendre le changement après l'installation, le service Web apache doit être redémarré :
# service apache24 restart
Félicitations, vous avez installé avec succès la pile Apache, MariaDB et PHP (FAMP) sur FreeBSD 11, vous êtes maintenant prêt à héberger vos sites Web ou toute application Web.