Question

Cloud Init PHP7 w/ PHPMyAdmin

Why doesn’t this work as a cloud init user script for PHP7 and PHPMyAdmin?

#cloud-config
apt_update: true
package_upgrade: true
packages:
  - apache2
  - apache2-utils
  - php7-mysql
  - mysql-server
  - libapache2-mod-php7
  - php7-mcrypt
  - php7-gd
  - php7-curl
  - phpmyadmin
write_files:
  - path: /usr/share/phpmyadmin/.htaccess
    content: |
      AuthType Basic
      AuthName "Restricted Files"
      AuthUserFile /etc/phpmyadmin/.htpasswd
      Require valid-user
runcmd:
  # Configure Apache
  - php7enmod mcrypt
  - sed -i -e "s/index.html index.cgi index.pl index.php/index.php index.html index.cgi index.pl/" /etc/apache2/mods-enabled/dir.conf
  - sed -i -e "s/index.php/index.php\n\tAllowOverride\ All/" /etc/phpmyadmin/apache.conf
  - ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf

  # Generate random passwords for the MySql root user and the .htaccess file
  - PHPMYADMINPASS=`dd if=/dev/urandom bs=1 count=12 2>/dev/null | base64 -w 0 | rev | cut -b 2- | rev`
  - MYSQLPASS=`dd if=/dev/urandom bs=1 count=12 2>/dev/null | base64 -w 0 | rev | cut -b 2- | rev`
  - mysqladmin -u root -h localhost password "$MYSQLPASS"
  - echo "[client]\npassword="$MYSQLPASS"\n" > /root/.my.cnf
  # The .htaccess username defaults to phpmyadmin. Update the line below to change that.
  - echo $PHPMYADMINPASS | htpasswd -c -i /etc/phpmyadmin/.htpasswd phpmyadmin
  - echo "phpMyAdmin Password -    "$PHPMYADMINPASS"" > /root/phpmyadmin
  - echo "MySql Password      -    ""$MYSQLPASS""" >> /root/phpmyadmin

  # Enable the conf and restart Apache.
  - a2enconf phpmyadmin.conf
  - service apache2 restart
Subscribe
Share

What is your distro/version?

One thing I see - I believe you need to set environment variables with:

export PHPMYADMINPASS=`blah`

try prepending any lines where you are setting environment variables with export

Any anomalies show up in the cloud-init-output.log file?


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

This question was answered by @aha:

What is your distro/version?

One thing I see - I believe you need to set environment variables with:

export PHPMYADMINPASS=`blah`

try prepending any lines where you are setting environment variables with export

View the original comment