5

Referencing this tutorial: https://www.liquidweb.com/kb/how-to-install-and-configure-phpmyadmin-on-ubuntu-14-04/ for installing PHP-Admin, after installing the package, on "Step 2: Basic Configuration" some questions need to be filled out by the user.

Is it possible to complete these configurations entirely via Shell Script from the command line?

chicks
  • 3,793
  • 10
  • 27
  • 36
Rodrigo
  • 51
  • 1
  • 3
  • I would assume so but just a guess. I wonder if that screen pops up automatically after the install or do you have to run something first? – chackerian Jun 13 '17 at 16:54
  • Thanks for replying! I have created a shell script for that and when I execute this command : apt install apache2 mysql-server php libapache2-mod-php phpmyadmin python python-mysqldb the referred screens show up. I would like to answer these questions via shell script avoiding user input but maybe is not possible. – Rodrigo Jun 13 '17 at 17:15
  • I know you want a shell script. I asked about the screen thing to see if it popped up on its own or if you had to trigger it. Looks like Esa gives a fix for turning off this. – chackerian Jun 13 '17 at 17:31
  • Debian packages tend to be interactive and there are a variety of imperfect methods for working around that. I'd rather work on an `rpm`-based system that can be scripted without worrying about interactive BS. – chicks Jun 13 '17 at 20:50

2 Answers2

6

Basically the first thing to do is skipping any interactive post-install configuration steps.

export DEBIAN_FRONTEND=noninteractive
apt-get -yq install phpmyadmin

This will skip all the questions made by dpkg-preconfigure.

Then, you need to do configuration manually i.e. automate it by yourself by making your script to either create or copy configuration. The local configuration file is in /etc/phpmyadmin/config.inc.php and you can find some configuration examples in /usr/share/doc/phpmyadmin/examples/. For security, passwords should be included from a separate file with permissions -rw-r----- root www-data.

The dpkg-reconfigure phpmyadmin reads and writes from /etc/dbconfig-common/phpmyadmin.conf. Your script could be something like this:

export DEBIAN_FRONTEND=noninteractive
apt-get -yq install phpmyadmin
cp /path/to/preconfigured-phpmyadmin.conf /etc/dbconfig-common/phpmyadmin.conf
dpkg-reconfigure --frontend=noninteractive phpmyadmin
Esa Jokinen
  • 46,944
  • 3
  • 83
  • 129
0

I hope this script helps. I am still working out how to automate apache configuration

export DEBIAN_FRONTEND="noninteractive"
sudo apt update
sudo apt install -yq phpmyadmin

# Set the MySQL administrative user's password
sudo debconf-set-selections <<< "phpmyadmin phpmyadmin/dbconfig-install boolean true"
sudo debconf-set-selections <<< "phpmyadmin phpmyadmin/mysql/admin-user string root"
sudo debconf-set-selections <<< "phpmyadmin phpmyadmin/mysql/admin-pass password $MYSQL_ROOT_PASSWORD"
sudo debconf-set-selections <<< "phpmyadmin phpmyadmin/mysql/app-pass password $MYSQL_ROOT_PASSWORD"
sudo debconf-set-selections <<< "phpmyadmin phpmyadmin/reconfigure-webserver multiselect apache2"

sudo dpkg-reconfigure -f noninteractive phpmyadmin

echo "Include /etc/phpmyadmin/apache.conf" >> /etc/apache2/apache2.conf

sudo service apache2 restart
echo "Apache service restarted"