Script bash que instala WordPress en VestaCP

Script bash que instala WordPress en VestaCP.

En este articulo te presento un script bash que automatiza la instalación de WordPress desde la consola / terminal, en el panel de control web «VestaCP«.

La instalación es simple, y el propio script te solicitara los datos necesarios para una correcta instalación.

Permite modificar la carpeta donde se alojara el nuevo sitio, que por defecto es «wordpress«.

Script bash que instala Wordpress en VestaCP 1

 

Vamos a crear el script.

nano install-wp.sh

Copia y pega el siguiente código…
#!/bin/bash

read -p "Username : " user
read -p "Domain   : " domain

#------------ ADD DOMAIN IN VESTACP -----------------
/usr/local/vesta/bin/v-add-domain $user $domain

# bash generate random 32 character alphanumeric string (upper and lowercase) an                                                                             d
db_user=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 5 | head -n 1)
db_pass=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 10 | head -n 1)

#------------ ADD DATABASE IN VESTACP -----------------
/usr/local/vesta/bin/v-add-database $user $db_user $db_user $db_pass

username=${user}_${db_user}
echo "DB Username : $username"
echo "DB Password : $db_pass"

cd /home/$user/web/$domain/public_html/
clear
echo "============================================"
echo "WordPress Install Script"
echo "============================================"
echo "============================================"
echo "A robot is now installing WordPress for you."
echo "============================================"
#download wordpress
curl -O https://wordpress.org/latest.tar.gz
#unzip wordpress
tar -zxvf latest.tar.gz
#modifica la carpeta de instalacion wordpress
cd wordpress
#copy file to parent dir
cp -rf . ..
#move back to parent dir
cd ..
#remove files from wordpress folder
rm -R wordpress
#create wp config
cp wp-config-sample.php wp-config.php
#set database details with perl find and replace
perl -pi -e "s/database_name_here/$username/g" wp-config.php
perl -pi -e "s/username_here/$username/g" wp-config.php
perl -pi -e "s/password_here/$db_pass/g" wp-config.php

#set WP salts
perl -i -pe'
  BEGIN {
    @chars = ("a" .. "z", "A" .. "Z", 0 .. 9);
    push @chars, split //, "!@#$%^&*()-_ []{}<>~\`+=,.;:/?|";
    sub salt { join "", map $chars[ rand @chars ], 1 .. 64 }
  }
  s/put your unique phrase here/salt()/ge
' wp-config.php

#create uploads folder and set permissions
mkdir wp-content/uploads
chmod 775 wp-content/uploads
echo "Cleaning..."
#remove zip file
rm latest.tar.gz
#remove bash script
echo "========================="
echo "Installation is complete."
echo "========================="

Guarda el archivo «install-wp.sh», y cierra el editor.

Script bash que instala Wordpress en VestaCP 2

 

Le damos permisos de ejecución:

chmod +x install-wp.sh

Ejecutamos el script de instalación:
bash install-wp.sh

 

Una vez concluya el proceso, puedes acceder a tu instalación de forma convencional.

 

Agregar comentario