Diferencia entre revisiones de «Despliegue-de-Aplicaciones-Web/Apache con vagrant»

De WikiEducator
Saltar a: navegación, buscar
(apache)
 
(source)
 
Línea 6: Línea 6:
 
* Crear directorio '''html'''
 
* Crear directorio '''html'''
 
* Dentro del directorio crear '''index.html''':
 
* Dentro del directorio crear '''index.html''':
<code>
+
<source lang="html4strict">
 
   <!DOCTYPE html>
 
   <!DOCTYPE html>
 
   <html>
 
   <html>
 
     <body>
 
     <body>
       &lt;h1>¡Servidor web con Vagrant!</h1>
+
       <h1>¡Servidor web con Vagrant!</h1>
 
     </body>
 
     </body>
 
   </html>
 
   </html>
</code>
+
</source>
 
* Escribir archivo de ''provisión''. En el mismo directorio que '''Vagrantfile'''. Se llamará '''bootstrap.sh'''
 
* Escribir archivo de ''provisión''. En el mismo directorio que '''Vagrantfile'''. Se llamará '''bootstrap.sh'''
<code>
+
<source lang="bash">
 
   #!/usr/bin/env bash
 
   #!/usr/bin/env bash
 
   apt-get update
 
   apt-get update
Línea 23: Línea 23:
 
     ln -fs /vagrant /var/www
 
     ln -fs /vagrant /var/www
 
   fi
 
   fi
</code>
+
</source>
  
 
* Configurar Vagrant
 
* Configurar Vagrant
 
Añadir al Vagrantfile antes del '''end'''
 
Añadir al Vagrantfile antes del '''end'''
  config.vm.provision :shell, path: "bootstrap.sh"
+
<source lang="bash">
 
+
config.vm.provision :shell, path: "bootstrap.sh"
 +
</source>
 
* Generar el servidor
 
* Generar el servidor
  $ vagrant reload --provision
+
<source lang="bash">
 
+
$ vagrant reload --provision
 +
</source>
 
* Comprobar el funcionamiento del servidor
 
* Comprobar el funcionamiento del servidor
  $ vagrant ssh
+
<source lang="bash">
  $ curl 127.0.0.1
+
$ vagrant ssh
 
+
$ curl 127.0.0.1
 +
</source>
 
* Redireccionar el puerto de la máquina con apache
 
* Redireccionar el puerto de la máquina con apache
 
Añade a Vagrantfile:
 
Añade a Vagrantfile:
  config.vm.network :forwarded_port, guest: 80, host: 4567
+
<source lang="bash">
 +
config.vm.network :forwarded_port, guest: 80, host: 4567
 +
</source>
 
Y reinicia el servicio:
 
Y reinicia el servicio:
  $ vagrant reload
+
<source lang="bash">
 +
$ vagrant reload
 +
</source>
  
 
* Compruébalo accediendo con tu navegador a '''localhost:4567'''
 
* Compruébalo accediendo con tu navegador a '''localhost:4567'''

Última revisión de 00:45 29 oct 2021

Documentación

Instalación

En la carteta donde está el Vagrantfile

  • Crear directorio html
  • Dentro del directorio crear index.html:
  <!DOCTYPE html>
  <html>
    <body>
      <h1>¡Servidor web con Vagrant!</h1>
    </body>
  </html>
  • Escribir archivo de provisión. En el mismo directorio que Vagrantfile. Se llamará bootstrap.sh
  #!/usr/bin/env bash
  apt-get update
  apt-get install -y apache2
  if ! [ -L /var/www ]; then
    rm -rf /var/www
    ln -fs /vagrant /var/www
  fi
  • Configurar Vagrant

Añadir al Vagrantfile antes del end

config.vm.provision :shell, path: "bootstrap.sh"
  • Generar el servidor
$ vagrant reload --provision
  • Comprobar el funcionamiento del servidor
$ vagrant ssh
$ curl 127.0.0.1
  • Redireccionar el puerto de la máquina con apache

Añade a Vagrantfile:

config.vm.network :forwarded_port, guest: 80, host: 4567

Y reinicia el servicio:

$ vagrant reload
  • Compruébalo accediendo con tu navegador a localhost:4567

Tarea

Coloca en la carpeta html que has creado una web estática tuya que contenga archivos html y estáticos (css, js o imágenes) y comprueba que funciona correctamente.