Skip to content

Instantly share code, notes, and snippets.

@0hsn
Last active June 13, 2018 19:38
Show Gist options
  • Save 0hsn/799c9b1680fb5bdb39de0292775c7284 to your computer and use it in GitHub Desktop.
Save 0hsn/799c9b1680fb5bdb39de0292775c7284 to your computer and use it in GitHub Desktop.
Apache 2.4, PHP 7.2, and Mysql 5.7 on Ubuntu 16.04 install script to be used with vagrant as provision script
# Variables
APPENV=local
DBHOST=localhost
DBNAME=discussion_forum
DBUSER=root
DBPASSWD=root123
apt-get -qq update --fix-missing > /dev/null 2>&1
echo -e "\n--- Install base packages ---\n"
apt-get -y install vim curl mcrypt build-essential python-software-properties git software-properties-common zip > /dev/null 2>&1
echo -e "\n--- Install MySQL specific packages and settings ---\n"
echo "mysql-server mysql-server/root_password password $DBPASSWD" | debconf-set-selections
echo "mysql-server mysql-server/root_password_again password $DBPASSWD" | debconf-set-selections
echo "phpmyadmin phpmyadmin/dbconfig-install boolean true" | debconf-set-selections
echo "phpmyadmin phpmyadmin/app-password-confirm password $DBPASSWD" | debconf-set-selections
echo "phpmyadmin phpmyadmin/mysql/admin-pass password $DBPASSWD" | debconf-set-selections
echo "phpmyadmin phpmyadmin/mysql/app-pass password $DBPASSWD" | debconf-set-selections
echo "phpmyadmin phpmyadmin/reconfigure-webserver multiselect none" | debconf-set-selections
apt-get -y install mysql-server-5.7 phpmyadmin > /dev/null 2>&1
echo -e "\n--- Setting up our MySQL user and db ---\n"
mysql -uroot -p$DBPASSWD -e "CREATE DATABASE $DBNAME"
mysql -uroot -p$DBPASSWD -e "grant all privileges on $DBNAME.* to '$DBUSER'@'$DBHOST' identified by '$DBPASSWD'"
echo -e "\n--- Updating packages list ---\n"
add-apt-repository -y ppa:ondrej/apache2
add-apt-repository -y ppa:ondrej/php
apt-get -qq update > /dev/null 2>&1
echo -e "\n=== Install [email protected] ===\n"
apt-get install -y php7.2 php-pear php7.2-curl php7.2-dev php7.2-gd php7.2-mbstring php7.2-zip php7.2-mysql php7.2-xml > /dev/null 2>&1
update-alternatives --set php /usr/bin/php7.2
echo -e "\n--- Install Apache ---\n"
apt-get install -y apache2 > /dev/null 2>&1
a2enmod rewrite
a2dismod php7.0
a2enmod php7.2
echo -e "\n=== Apache Configuration ===\n"
echo -e "\n--- Allowing Apache override to all ---\n"
sed -i "s/AllowOverride None/AllowOverride All/g" /etc/apache2/apache2.conf
echo -e "\n--- Setting document root to public directory ---\n"
rm -rf /var/www
ln -fs /vagrant /var/www
echo -e "\n--- Configure Apache to use phpmyadmin on port 81---\n"
echo -e "\n\nListen 81\n" >> /etc/apache2/ports.conf
cat > /etc/apache2/conf-available/phpmyadmin.conf << "EOF"
<VirtualHost *:81>
ServerAdmin webmaster@localhost
DocumentRoot /usr/share/phpmyadmin
DirectoryIndex index.php
ErrorLog ${APACHE_LOG_DIR}/phpmyadmin-error.log
CustomLog ${APACHE_LOG_DIR}/phpmyadmin-access.log combined
</VirtualHost>
EOF
a2enconf phpmyadmin > /dev/null 2>&1
echo -e "\n--- Add environment variables to Apache ---\n"
cat > /etc/apache2/sites-enabled/000-default.conf <<EOF
<VirtualHost *:80>
DocumentRoot /var/www/code/public
ErrorLog \${APACHE_LOG_DIR}/error.log
CustomLog \${APACHE_LOG_DIR}/access.log combined
SetEnv APP_ENV $APPENV
SetEnv DB_HOST $DBHOST
SetEnv DB_NAME $DBNAME
SetEnv DB_USER $DBUSER
SetEnv DB_PASS $DBPASSWD
</VirtualHost>
EOF
echo -e "\n--- Changing apache's user to vagrant ---\n"
sed -i -e 's/www-data/vagrant/g' /etc/apache2/envvars
echo -e "\n--- Adding www-data in vagrant group ---\n"
adduser www-data vagrant
grep 'vagrant' /etc/group
echo -e "\n--- Restarting Apache ---\n"
service apache2 restart > /dev/null 2>&1
echo -e "\n--- Installing composer ---\n"
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
apt-get clean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment