Skip to content

Instantly share code, notes, and snippets.

@nmcgann
Created March 12, 2017 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nmcgann/24ba859de53c2971f152dcd9d713b953 to your computer and use it in GitHub Desktop.
Save nmcgann/24ba859de53c2971f152dcd9d713b953 to your computer and use it in GitHub Desktop.
Provision and fix the Vultr LAMP stack (Centos 6). Adds PhpMyAdmin and fixes the broken .htaccess files due to fcgi config (as of March 2017)
#!/bin/bash
#Provision the vultr Centos6 LAMP stack as it is a bit broken as standard
#update and fetch missing things
yum update -y
yum install -y php56u-bcmath php56u-imap php56u-intl php56u-pecl-memcache
#disable opcache for development
perl -pi -e 's/^opcache.enable=1/opcache.enable=0/' /etc/php.d/10-opcache.ini
#fix session gc time
perl -pi -e 's/^session.gc_maxlifetime = 1440/session.gc_maxlifetime = 28800/' /etc/php.ini
#get phpmyadmin - can't use package as conflicts with php5.6
wget -N https://files.phpmyadmin.net/phpMyAdmin/4.6.6/phpMyAdmin-4.6.6-english.tar.gz
cd /root
tar -xf phpMyAdmin-4.6.6-english.tar.gz
mv phpMyAdmin-4.6.6-english phpmyadmin
cp -R phpmyadmin/ /usr/share/httpd/
rm -rf phpmyadmin/
rm -f phpMyAdmin-4.6.6-english.tar.gz
cd /usr/share/httpd/phpmyadmin
cp config.sample.inc.php config.inc.php
cat > .htaccess << EOF
#local access only via ssh tunnel
Require local
EOF
#extend phpmyadmin cookie timeout
perl -ni -le 'print; print "\$cfg[\"LoginCookieValidity\"] = 86400;" if /blowfish_secret/' config.inc.php
#alias the phpmyadmin dir into the web root
cat > /etc/httpd/conf.d/phpmyadmin.conf << EOF
#alias phpmyadmin
Alias "/phpmyadmin" "/usr/share/httpd/phpmyadmin"
<Directory "/usr/share/httpd/phpmyadmin">
AllowOverride All
Options -Indexes
Require all granted
<Files ".ht*">
Require all denied
</Files>
</Directory>
EOF
#fix apache as htaccess is broken in local directories
#allow htaccess files
perl -ni -le 'print; print "AllowOverride All" if /<Directory \/usr\/share\/httpd\/html\/>/' /etc/httpd/conf.d/https.conf
perl -ni -le 'print; print "AllowOverride All" if /<Directory \/usr\/share\/httpd\/html\/>/' /etc/httpd/conf.d/http.conf
#change the fcgi config to use FilesMatch: like this
#<FilesMatch \.php$>
# SetHandler "proxy:fcgi://127.0.0.1:9000"
#</FilesMatch>
perl -pi -e 's/\bProxyPassMatch/#ProxyPassMatch/' /etc/httpd/conf.d/http.conf
perl -pi -e 's/\bProxyPassMatch/#ProxyPassMatch/' /etc/httpd/conf.d/https.conf
perl -ni -le 'print; print "<FilesMatch \\.php\$>\nSetHandler \"proxy:fcgi://127.0.0.1:9000\"\n</FilesMatch>" if /#ProxyPassMatch/' /etc/httpd/conf.d/https.conf
perl -ni -le 'print; print "<FilesMatch \\.php\$>\nSetHandler \"proxy:fcgi://127.0.0.1:9000\"\n</FilesMatch>" if /#ProxyPassMatch/' /etc/httpd/conf.d/http.conf
#restart apache and fpm
service httpd restart
service php-fpm reload
echo ""
echo "Vultr LAMP stack: Finished with setup!"
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment