Skip to content

Instantly share code, notes, and snippets.

@muratgozel
Last active February 28, 2018 23:39
Show Gist options
  • Save muratgozel/6f2c01ca9501467ff05ef961c3d68b48 to your computer and use it in GitHub Desktop.
Save muratgozel/6f2c01ca9501467ff05ef961c3d68b48 to your computer and use it in GitHub Desktop.
Apache, PHP 5.6, Mysql Stack Setup on Ubuntu 16
#!/bin/sh
EXPECTED_SIGNATURE=$(wget -q -O - https://composer.github.io/installer.sig)
sudo php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
ACTUAL_SIGNATURE=$(php -r "echo hash_file('SHA384', 'composer-setup.php');")
if [ "$EXPECTED_SIGNATURE" != "$ACTUAL_SIGNATURE" ]
then
>&2 echo 'ERROR: Invalid installer signature'
sudo rm composer-setup.php
exit 1
fi
sudo php composer-setup.php --quiet
RESULT=$?
sudo rm composer-setup.php
exit $RESULT

Login to the mysql console

mysql -u root -p

Execute the following commands

CREATE USER 'webmaster'@'%' IDENTIFIED BY '{{password}}';
GRANT ALL PRIVILEGES ON *.* TO 'webmaster'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
exit;

Open mysql config and make the following change

sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
bind-address = 0.0.0.0

Restart mysql server sudo systemctl restart mysql.service

Open 3306 port of the server if firewall exist.

<VirtualHost *:80>
ServerAdmin {{email}}
ServerName {{host}}
ServerAlias www.{{host}}
ServerSignature Off
DocumentRoot /var/www/{{host}}/public_html
LogLevel warn
ErrorLog /var/www/{{host}}/logs/error.log
CustomLog /var/www/{{host}}/logs/access.log combined
SetEnv DB_HOST "localhost"
SetEnv DB_USER "{{db_user}}"
SetEnv DB_PASSWORD "{{db_password}}"
SetEnv DB_NAME "{{db_name}}"
SetEnv GOOGLE_APPLICATION_CREDENTIALS "/home/{{user}}/{{credentials.json}}"
SetEnv GOOGLE_APPLICATION_USER "{{user_email}}"
<IfModule mod_rewrite.c>
RewriteEngine On
<Files ~ "^\.ht">
Order allow,deny
Deny from all
</Files>
<Directory /var/www/>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</IfModule>
<IfModule mod_mime.c>
AddType application/font-woff2 .woff2
</IfModule>
<IfModule mod_expires.c>
ExpiresActive on
ExpiresDefault "access plus 1 minute"
ExpiresByType text/css "access plus 1 hour"
ExpiresByType application/javascript "access plus 1 hour"
ExpiresByType application/x-javascript "access plus 1 hour"
ExpiresByType application/x-icon "access plus 1 day"
ExpiresByType image/jpeg "access plus 1 hour"
ExpiresByType image/png "access plus 1 hour"
ExpiresByType image/gif "access plus 1 hour"
ExpiresByType application/font-woff "access plus 1 day"
ExpiresByType application/font-woff2 "access plus 1 day"
</IfModule>
</VirtualHost>
sudo apt-get update
sudo apt-get install apache2 -y
sudo a2enmod rewrite mime expires
sudo apt-get install mysql-server -y # Will ask root password twice.
# Configure to allow remote connections.
sudo apt-get install software-properties-common -y
sudo add-apt-repository ppa:ondrej/php -y
sudo apt-get update
sudo apt-get install php5.6 -y
sudo apt-get install php5.6-mbstring php5.6-mcrypt php5.6-mysql php5.6-xml php5.6-curl php5.6-gd php5.6-pdo-mysql php5.6-xml php5.6-xsl -y
sudo apt-get install zip unzip -y
sudo add-apt-repository ppa:certbot/certbot -y
sudo apt-get update
sudo apt-get install python-certbot-apache -y
# Install and activate mod_pagespeed
wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_amd64.deb
sudo dpkg -i mod-pagespeed-*.deb
sudo apt-get -f install
sudo nano /etc/apache2/mods-enabled/pagespeed.conf
# Change the following parameter as follows in the pagespeed configuration file.
# ModPagespeedDisableFilters extend_cache
sudo service apache2 restart
# Configure permissions.
sudo nano /etc/apache2/envvars
# Add "umask 002" to the end of the file. Save and exit.
sudo usermod -a -G www-data {{user}}
# Setup Composer
sudo bash composer-setup.sh
sudo mv composer.phar /usr/local/bin/composer
# Setup a virtual host. Repeat this section for each virtual host you want to create.
sudo mkdir -p /var/www/example.com/public_html
sudo mkdir -p /var/www/example.com/logs
sudo chgrp -R www-data /var/www/example.com/public_html
sudo chgrp -R www-data /var/www/example.com/logs
sudo chmod 2770 /var/www/example.com/public_html
sudo chmod 2770 /var/www/example.com/logs
# deprecated: find /var/www -type d -exec chmod 2775 {} +
# deprecated: find /var/www -type f -exec chmod 0664 {} +
# deprecated: "sudo nano .bashrc" and add "umask 0002" at the end of the file.
# Upload files...
sudo nano /etc/apache2/sites-available/example.com.conf
sudo a2ensite example.com.conf
sudo service apache2 reload
# Make the DNS change.
# Setup SSL Certificate with Letsencrypt (if you prefer.)
sudo certbot --apache -d example.com -d www.example.com
# Log out and log in if you can not cd into a public_html directory.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment