Vagrant LAMP

Servidor Vagrant LAMP

22 September, 2014

En un post anterior expliqué cómo empezar iniciarnos en Vagrant. En este post me gustaría ampliar esa explicación por configurar un servidor LAMP.

Nos colocamos en el directorio de trabajo Vagrant. Siguiendo mi última explicación, este debe ser:

$HOME/Development/Box/

Editamos el fichero Vagrantfile y descomentamos o añadimos las líneas:

config.vm.provision :shell, :path => "vagrant-bootstrap.sh" ## provisioning file with instructions
config.vm.network :forwarded_port, host: 8002, guest: 80, auto_correct: true ## port forwarding 80 >> 8002

A continuación creamos/actualizamos el fichero “vagrant-bootstrap.sh” con “vagrant” como contraseña principal para nuestra configuración:

#!/usr/bin/env bash

apt-get update
apt-get -y upgrade

apt-get install -y apache2
rm -rf /var/www
ln -fs /vagrant /var/www

apt-get install -y git subversion curl vim screen puppet
apt-get install -y lynx links links2

apt-get install -y php5-cli php5-curl php5-mcrypt php5-gd
mv -i /etc/php5/conf.d/mcrypt.ini /etc/php5/mods-available/
php5enmod mcrypt

MYSQL_PASSWORD="vagrant"
PHPMYADMIN_PASSWORD="vagrant"

echo "mysql-server-5.5 mysql-server/root_password password $MYSQL_PASSWORD" | debconf-set-selections
echo "mysql-server-5.5 mysql-server/root_password_again password $MYSQL_PASSWORD" | debconf-set-selections

apt-get -y install mysql-client mysql-server

echo 'phpmyadmin phpmyadmin/dbconfig-install boolean false' | debconf-set-selections
echo 'phpmyadmin phpmyadmin/reconfigure-webserver multiselect apache2' | debconf-set-selections

echo 'phpmyadmin phpmyadmin/app-password-confirm password $PHPMYADMIN_PASSWORD' | debconf-set-selections
echo 'phpmyadmin phpmyadmin/mysql/admin-pass password $MYSQL_PASSWORD' | debconf-set-selections
echo 'phpmyadmin phpmyadmin/password-confirm password $PHPMYADMIN_PASSWORD' | debconf-set-selections
echo 'phpmyadmin phpmyadmin/setup-password password $PHPMYADMIN_PASSWORD' | debconf-set-selections
echo 'phpmyadmin phpmyadmin/database-type select mysql' | debconf-set-selections
echo 'phpmyadmin phpmyadmin/mysql/app-pass password $PHPMYADMIN_PASSWORD' | debconf-set-selections

echo 'dbconfig-common dbconfig-common/mysql/app-pass password $PHPMYADMIN_PASSWORD' | debconf-set-selections
echo 'dbconfig-common dbconfig-common/mysql/app-pass password' | debconf-set-selections
echo 'dbconfig-common dbconfig-common/password-confirm password $PHPMYADMIN_PASSWORD' | debconf-set-selections
echo 'dbconfig-common dbconfig-common/app-password-confirm password $PHPMYADMIN_PASSWORD' | debconf-set-selections
echo 'dbconfig-common dbconfig-common/app-password-confirm password $PHPMYADMIN_PASSWORD' | debconf-set-selections
echo 'dbconfig-common dbconfig-common/password-confirm password $PHPMYADMIN_PASSWORD' | debconf-set-selections

apt-get -y install phpmyadmin

Cuando tengamos estos dos ficheros editados, podemos llamar a nuestra Box Vagrant usando el comando:

$ vagrant reload --provision

Veremos activar nuestra Box procesando las instrucciones de “vagrant-bootstrap.sh”. Una vez finalizada la operación podemos ver nuestro servidor web corriendo abriendo un navegador y escribiendo http://localhost:8002. Aquí veremos los archivos de nuestra carpeta de trabajo asignada en el fichero “Vagrantfile”. De esta manera podemos colocar nuestro fichero index.php en la carpeta y empezar nuestro proyecto PHP.

http://localhost:8002 >>>> $HOME/Development/Box/

Recordar que podemos trabajar a nivel local con esa carpeta; se puede “gitear” y editar con nuestra herramienta IDE preferida. Feliz desarrollo!

Podemos añadir estas líneas para crear automáticamente una base de datos (llamada “ado” con la contraseña “ado”):

echo "CREATE DATABASE ado;" | mysql -u root -p$MYSQL_PASSWORD
echo "CREATE USER 'ado'@'localhost' IDENTIFIED BY 'ado';" | mysql -u root -p$MYSQL_PASSWORD
echo "GRANT ALL ON ado.* TO 'ado'@'localhost';" | mysql -u root -p$MYSQL_PASSWORD
echo "GRANT CREATE ON ado.* TO 'ado'@'localhost';" | mysql -u root -p$MYSQL_PASSWORD
echo "FLUSH PRIVILEGES;" | mysql -u root -p$MYSQL_PASSWORD

Chuleta: Configuración Vagrant para aprovisionar un servidor LAMP (Descargar)

#!/usr/bin/env bash

apt-get update
apt-get -y upgrade

apt-get install -y apache2
rm -rf /var/www
ln -fs /vagrant /var/www

apt-get install -y git subversion curl vim screen puppet
apt-get install -y lynx links links2

apt-get install -y php5-cli php5-curl php5-mcrypt php5-gd
mv -i /etc/php5/conf.d/mcrypt.ini /etc/php5/mods-available/
php5enmod mcrypt

MYSQL_PASSWORD="vagrant"
PHPMYADMIN_PASSWORD="vagrant"

echo "mysql-server-5.5 mysql-server/root_password password $MYSQL_PASSWORD" | debconf-set-selections
echo "mysql-server-5.5 mysql-server/root_password_again password $MYSQL_PASSWORD" | debconf-set-selections

apt-get -y install mysql-client mysql-server

echo 'phpmyadmin phpmyadmin/dbconfig-install boolean false' | debconf-set-selections
echo 'phpmyadmin phpmyadmin/reconfigure-webserver multiselect apache2' | debconf-set-selections

echo 'phpmyadmin phpmyadmin/app-password-confirm password $PHPMYADMIN_PASSWORD' | debconf-set-selections
echo 'phpmyadmin phpmyadmin/mysql/admin-pass password $MYSQL_PASSWORD' | debconf-set-selections
echo 'phpmyadmin phpmyadmin/password-confirm password $PHPMYADMIN_PASSWORD' | debconf-set-selections
echo 'phpmyadmin phpmyadmin/setup-password password $PHPMYADMIN_PASSWORD' | debconf-set-selections
echo 'phpmyadmin phpmyadmin/database-type select mysql' | debconf-set-selections
echo 'phpmyadmin phpmyadmin/mysql/app-pass password $PHPMYADMIN_PASSWORD' | debconf-set-selections

echo 'dbconfig-common dbconfig-common/mysql/app-pass password $PHPMYADMIN_PASSWORD' | debconf-set-selections
echo 'dbconfig-common dbconfig-common/mysql/app-pass password' | debconf-set-selections
echo 'dbconfig-common dbconfig-common/password-confirm password $PHPMYADMIN_PASSWORD' | debconf-set-selections
echo 'dbconfig-common dbconfig-common/app-password-confirm password $PHPMYADMIN_PASSWORD' | debconf-set-selections
echo 'dbconfig-common dbconfig-common/app-password-confirm password $PHPMYADMIN_PASSWORD' | debconf-set-selections
echo 'dbconfig-common dbconfig-common/password-confirm password $PHPMYADMIN_PASSWORD' | debconf-set-selections

apt-get -y install phpmyadmin


## creating database ado with password ado
echo "CREATE DATABASE ado;" | mysql -u root -p$MYSQL_PASSWORD
echo "CREATE USER 'ado'@'localhost' IDENTIFIED BY 'ado';" | mysql -u root -p$MYSQL_PASSWORD
echo "GRANT ALL ON ado.* TO 'ado'@'localhost';" | mysql -u root -p$MYSQL_PASSWORD
echo "GRANT CREATE ON ado.* TO 'ado'@'localhost';" | mysql -u root -p$MYSQL_PASSWORD
echo "FLUSH PRIVILEGES;" | mysql -u root -p$MYSQL_PASSWORD

    Etiquetas: , , , , , ,

    Dejar un comentario