Pour installer un serveur web Windows, vous avez plusieurs solution. Soit en installant Apache seul…
Serveur web linux
Serveur web linux
Serveur web linux
Installer et configurer un serveur web Linux sous apache2.
Pré-requis pour un serveur web Linux
Téléchagements
Dans les pré-requis vous avez les informations pour télécharger Apaches 2.4 en ligne de commande.
Installer Apache2
Installer un serveur web Linux avec Apache2
Pour commencer, vous devez ouvrir un terminal. sois sur Debian ou Ubuntu c’est la même chose.
Une fois que le terminal ouvert vérifier que votre système est bien à jour.
utiliser la commande suivante :
root@osnetworking : ~# apt update

root@osnetworking : ~# apt upgrade
Répondre Y et entrer

Maintenant que votre système est à jour. Nous allons télécharger et installer Apache2. Pour cela vous utilisez la commande suivante :
root@osnetworking : ~#apt install apache2
Répondre Y et entrer

Apache2 est bien installé maintenant il reste à configurer le serveur.
Test du serveur web Linux
Pour cela, vous devez connaitre l’adresse IP.
root@osnetworking : ~# ip address
ou
root@osnetworking : ~#hostname -I
L’adresse IP de mon serveur est 192.168.1.114.
Maintenant vous allez ouvrir votre navigateur et taper l’adresse IP dans la barre de recherche. Et vous tapez l’adresse IP de votre serveur.
Si vous voyez marquer It works! ou ça marche! c’est que votre serveur fonctionne bien.
configurer le serveur web Linux avec Apache2
Le répertoire ou nous configurons les logiciels est : /etc.
Vous allez dans le fichier de configuration en tapant la commande ci-dessous.
root@osnetworking : ~# cd /etc/apache2/site-available
Puis vous tapez :
root@osnetworking : /etc/apache2/sites-available# ls -a
Vous pouvez voir que vous avez deux fichiers.
Nous allons créer notre propre fichier que nous nommons site2.conf dans ce dossier.
root@osnetworking : /etc/apache2/sites-available# touch /etc/apache2/site-available/site2.conf
Dès que le fichier est créé, nous pouvons copier les données du fichier 000-default.conf vers site2.conf
root@osnetworking : /etc/apache2/sites-available# cp 000-default.conf site2.conf
Ouvrons le fichier avec vi:
root@osnetworking : /etc/apache2/sites-available#vi site2.conf
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request’s Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
# Available loglevels: trace8, …, trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with “a2disconf”.
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
Nous vérifions que le port est bien le port 80. Puis le répertoire où nous stockerons les données. Nous apercevons que le dossier n’est pas correct “DocumentRoot /var/www/html”
Nous remplaçons le répertoire par “DocumentRoot /var/www/site2“.
Sauvegarder le fichier avec la touche echap :wq!
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request’s Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/site2
# Available loglevels: trace8, …, trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with “a2disconf”.
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
~ :wq!
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request’s Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/site2
# Available loglevels: trace8, …, trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with “a2disconf”.
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
~ :wq!
Pour activer le virtual host nous avons besoin de la commande suivante
root@osnetworking : /etc/apache2# a2ensite site2.conf
Comme nous avons changer le répertoire de stockage, il faut créer un dossier dans /var/www/ que nous appellerons site2.
root@osnetworking : /etc/apache2# cd /var/www/
Puis vous tapez la commande pour créer le dossier
root@osnetworking : /etc/apache2# mkdir /var/www/site2
vous rentrez dans le dossier et nous allons créer un fichier index.html
root@osnetworking : /etc/apache2# touch /var/www/site2/index.html
Nous vous conseillons de faire une copie du fichier index.html qui se trouve dans /var/www/html/index.html.
root@osnetworking : /var/www/site2/# cp /var/www/html/index.html /var/www/site2/index.html
Droits sur le dossier
Une fois que toute la configuration d’Apache2 est faite, nous devons mettre les droits sur le dossier /var/www/site2/.
Nous utilisons comme commande chown + groupe + le répertoire
root@osnetworking : /var/www# chown -R www.data:www.data /var/www/site2
Enfin, pour finir nous devons redémarrer le serveur.
root@osnetworking : //var/www# service apache2 restart
Vous pouvez de nouveau tester le serveur web Linux sous Apache2
Vous pouvez suivre les autres articles sur le serveur web.
Cet article comporte 0 commentaires