2024-11-27 20:28:36 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2024-11-27 21:07:36 +01:00
|
|
|
# Inicializando la base de datos
|
|
|
|
if test -f /var/lib/mysql/mysql; then
|
|
|
|
echo "Base de datos ya inicialiada (se hace nada)."
|
|
|
|
chown -R mysql:mysql /var/lib/mysql
|
|
|
|
else
|
|
|
|
echo "Inicializando la base de datos..."
|
|
|
|
mkdir -p /var/lib/mysql/mysql
|
|
|
|
chown -R mysql:mysql /var/lib/mysql
|
|
|
|
mariadb-install-db
|
|
|
|
fi
|
|
|
|
|
2024-11-27 20:28:36 +01:00
|
|
|
# Definiendo una contraseña vacía para root
|
|
|
|
echo "Definiendo contraseña para root (contraseña en blanco)."
|
|
|
|
systemctl start mariadb
|
|
|
|
mysql -e "SET PASSWORD FOR 'root'@'localhost' = PASSWORD(''); FLUSH PRIVILEGES;"
|
|
|
|
|
2024-11-27 20:43:37 +01:00
|
|
|
# Verificamos si ya está todo configurado
|
|
|
|
if test -f /etc/phpmyadmin/config.inc.php; then
|
|
|
|
echo "Se ha detectado que phpmyadmin ya esta instalado"
|
|
|
|
else
|
|
|
|
echo "Instalando phpmyadmin..."
|
|
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
|
|
apt-get update
|
|
|
|
apt-get -yq install phpmyadmin
|
|
|
|
|
|
|
|
# Permitimos el que se pueda loguear sin contraseña para usar el usuario root en phpmyadmin
|
|
|
|
sed -i "s/ \/\/ \$cfg\['Servers'\]\[\$i\]\['AllowNoPassword'\]/ \$cfg\['Servers'\]\[\$i\]\['AllowNoPassword'\]/" /etc/phpmyadmin/config.inc.php
|
|
|
|
fi
|
2024-11-27 20:28:36 +01:00
|
|
|
|
|
|
|
# Añadimos las reglas nginx para poder ver phpmyadmin en http://localhost/phpmyadmin
|
|
|
|
if grep -e "phpmyadmin" /etc/nginx/sites-available/default >/dev/null
|
|
|
|
then
|
|
|
|
echo "Se detectó que nginx ya tiene una configuración para PHPmyadmin (se hace nada)"
|
|
|
|
else
|
2024-11-27 20:43:37 +01:00
|
|
|
echo "Configurando Nginx para phpmyadmin..."
|
2024-11-27 20:28:36 +01:00
|
|
|
sed -i "s/server_name _;/server_name _;\n\nlocation \/phpmyadmin {\n root \/usr\/share\/;\n index index.php index.html index.htm;\n location ~ \^\/phpmyadmin\/\(.+\.php\)\$ {\n try_files \$uri =404;\n root \/usr\/share\/;\n fastcgi_pass unix:\/var\/run\/php\/php8.2-fpm.sock;\n fastcgi_index index.php;\n fastcgi_param SCRIPT_FILENAME \$request_filename;\n include \/etc\/nginx\/fastcgi_params;\n fastcgi_param PATH_INFO \$fastcgi_script_name;\n fastcgi_buffer_size 128k;\n fastcgi_buffers 256 4k;\n fastcgi_busy_buffers_size 256k;\n fastcgi_temp_file_write_size 256k;\n fastcgi_intercept_errors on;\n }\n location ~* \^\/phpmyadmin\/\(.+\\.\(jpg\|jpeg\|gif\|css\|png\|js\|ico\|html\|xml\|txt\)\)\$ {\n root \/usr\/share\/;\n }\n}\nlocation \/phpMyAdmin {\n rewrite \^\/* \/phpmyadmin last;\n}/g" /etc/nginx/sites-available/default
|
|
|
|
fi
|
|
|
|
|
2024-11-27 20:43:37 +01:00
|
|
|
echo "Recargado configuración de nginx"
|
|
|
|
nginx -t && systemctl reload nginx
|
2024-11-27 20:28:36 +01:00
|
|
|
|
|
|
|
echo "Finalizado :)."
|