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
This textbox defaults to using Markdown to format your 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
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.
