Last active
May 8, 2018 20:04
-
-
Save anishdcruz/8cfc53aa205c7481bf0412d97b9d72b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# before install create user deployer | |
# adduser deployer | |
# usermod -aG sudo deployer | |
# | |
export DEBIAN_FRONTEND=noninteractive | |
# Update Package List | |
apt-get update | |
# Update System Packages | |
apt-get -y upgrade | |
# Force Locale | |
echo "LC_ALL=en_US.UTF-8" >> /etc/default/locale | |
locale-gen en_US.UTF-8 | |
# Install Some PPAs | |
apt-get install -y software-properties-common curl | |
apt-add-repository ppa:nginx/development -y | |
apt-add-repository ppa:ondrej/php -y | |
add-apt-repository -y ppa:chris-lea/redis-server | |
# Update Package Lists | |
apt-get update | |
# Install Some Basic Packages | |
apt-get install -y git curl wget zip unzip htop | |
# Set My Timezone | |
ln -sf /usr/share/zoneinfo/UTC /etc/localtime | |
# Install PHP 7.1 Stuffs | |
apt-get install -y php7.1-fpm php7.1-cli php7.1-mcrypt php7.1-gd \ | |
php7.1-mysql php7.1-imap php7.1-mbstring php7.1-xml php7.1-curl \ | |
php7.1-bcmath | |
curl -sS https://getcomposer.org/installer | php | |
mv composer.phar /usr/local/bin/composer | |
# Set Some PHP CLI Settings | |
sudo sed -i "s/;date.timezone.*/date.timezone = UTC/" /etc/php/7.1/cli/php.ini | |
# | |
# Install Nginx | |
apt-get install -y nginx | |
# Setup Some PHP-FPM Options | |
sed -i "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/" /etc/php/7.1/fpm/php.ini | |
sed -i "s/upload_max_filesize = .*/upload_max_filesize = 100M/" /etc/php/7.1/fpm/php.ini | |
sed -i "s/post_max_size = .*/post_max_size = 100M/" /etc/php/7.1/fpm/php.ini | |
# Copy fastcgi_params to Nginx because they broke it on the PPA | |
cat > /etc/nginx/fastcgi_params << EOF | |
fastcgi_param QUERY_STRING \$query_string; | |
fastcgi_param REQUEST_METHOD \$request_method; | |
fastcgi_param CONTENT_TYPE \$content_type; | |
fastcgi_param CONTENT_LENGTH \$content_length; | |
fastcgi_param SCRIPT_FILENAME \$request_filename; | |
fastcgi_param SCRIPT_NAME \$fastcgi_script_name; | |
fastcgi_param REQUEST_URI \$request_uri; | |
fastcgi_param DOCUMENT_URI \$document_uri; | |
fastcgi_param DOCUMENT_ROOT \$document_root; | |
fastcgi_param SERVER_PROTOCOL \$server_protocol; | |
fastcgi_param GATEWAY_INTERFACE CGI/1.1; | |
fastcgi_param SERVER_SOFTWARE nginx/\$nginx_version; | |
fastcgi_param REMOTE_ADDR \$remote_addr; | |
fastcgi_param REMOTE_PORT \$remote_port; | |
fastcgi_param SERVER_ADDR \$server_addr; | |
fastcgi_param SERVER_PORT \$server_port; | |
fastcgi_param SERVER_NAME \$server_name; | |
fastcgi_param HTTPS \$https if_not_empty; | |
fastcgi_param REDIRECT_STATUS 200; | |
EOF | |
# Set The Nginx & PHP-FPM User | |
sed -i "s/user www-data;/user deployer;/" /etc/nginx/nginx.conf | |
sed -i "s/# server_names_hash_bucket_size.*/server_names_hash_bucket_size 64;/" /etc/nginx/nginx.conf | |
sed -i "s/user = www-data/user = deployer/" /etc/php/7.1/fpm/pool.d/www.conf | |
sed -i "s/group = www-data/group = deployer/" /etc/php/7.1/fpm/pool.d/www.conf | |
cat > /etc/nginx/sites-available/default << EOL | |
server { | |
listen 80; | |
server_name _; | |
root /home/deployer/www/demo/public; | |
add_header X-Frame-Options "SAMEORIGIN"; | |
add_header X-XSS-Protection "1; mode=block"; | |
add_header X-Content-Type-Options "nosniff"; | |
index index.html index.htm index.php; | |
charset utf-8; | |
location / { | |
try_files \$uri \$uri/ /index.php?\$query_string; | |
} | |
location = /favicon.ico { access_log off; log_not_found off; } | |
location = /robots.txt { access_log off; log_not_found off; } | |
error_page 404 /index.php; | |
location ~ \.php$ { | |
fastcgi_split_path_info ^(.+\.php)(/.+)$; | |
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock; | |
fastcgi_index index.php; | |
include fastcgi_params; | |
} | |
location ~ /\.(?!well-known).* { | |
deny all; | |
} | |
} | |
EOL | |
service nginx restart | |
service php7.1-fpm restart | |
# Install MySQL | |
debconf-set-selections <<< "mysql-server mysql-server/root_password password secret" | |
debconf-set-selections <<< "mysql-server mysql-server/root_password_again password secret" | |
apt-get install -y mysql-server | |
# Configure MySQL Password Lifetime | |
echo "default_password_lifetime = 0" >> /etc/mysql/mysql.conf.d/mysqld.cnf | |
mysql --user="root" --password="secret" -e "DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');" | |
mysql --user="root" --password="secret" -e "DELETE FROM mysql.user WHERE User='';" | |
mysql --user="root" --password="secret" -e "CREATE USER 'deployer'@'0.0.0.0' IDENTIFIED BY 'secret';" | |
mysql --user="root" --password="secret" -e "GRANT ALL ON *.* TO 'deployer'@'0.0.0.0' IDENTIFIED BY 'secret' WITH GRANT OPTION;" | |
mysql --user="root" --password="secret" -e "GRANT ALL ON *.* TO 'deployer'@'%' IDENTIFIED BY 'secret' WITH GRANT OPTION;" | |
mysql --user="root" --password="secret" -e "FLUSH PRIVILEGES;" | |
mysql --user="root" --password="secret" -e "CREATE DATABASE deployer character set UTF8mb4 collate utf8mb4_bin;" | |
service mysql restart | |
# redis | |
apt-get install -y redis-server | |
# Clean Up | |
apt-get -y autoremove | |
apt-get -y clean |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment