Last active
April 9, 2020 12:56
-
-
Save adampiotrowski/950db90454488b52aaf5 to your computer and use it in GitHub Desktop.
LAMP setup for UpCloud.com
This file contains hidden or 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
| #!/usr/bin/env bash | |
| # Usage: | |
| # $ wget https://gist.githubusercontent.com/adampiotrowski/950db90454488b52aaf5/raw/987bbcf1211468db54ff102a19a69ec69627af96/upcloud_lamp.sh | |
| # $ chmod +x upcloud_lamp.sh | |
| # $ ./upcloud.sh domain.com preferred_mysql_root_password | |
| # Setup variables | |
| DOMAIN=$1 | |
| MYSQL_PASSWORD=$2 | |
| SITES_ENABLED='/etc/apache2/sites-enabled/' | |
| SITES_AVAILABLE='/etc/apache2/sites-available/' | |
| USER_DIR='/var/www/domains/' | |
| SITES_AVAILABLE_DOMAIN=$SITES_AVAILABLE$DOMAIN.conf | |
| ADMIN_MAIL='admin@localhost.com' | |
| PHP_FPM_CONF='/etc/apache2/conf-available/php5-fpm.conf' | |
| # Add repositories | |
| echo deb http://apt.newrelic.com/debian/ newrelic non-free >> /etc/apt/sources.list.d/newrelic.list | |
| wget -O- https://download.newrelic.com/548C16BF.gpg | apt-key add - | |
| sudo add-apt-repository ppa:ondrej/php5-5.6 | |
| sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db | |
| sudo add-apt-repository 'deb http://mariadb.kisiek.net//repo/10.0/ubuntu trusty main' | |
| # Update & Upgrade | |
| sudo apt-get update | |
| sudo apt-get -y upgrade | |
| sudo apt-get -y dist-upgrade | |
| # Install Composer globally | |
| curl -s https://getcomposer.org/installer | php | |
| mv composer.phar /usr/local/bin/composer | |
| # Set non-interactive mode | |
| export DEBIAN_FRONTEND="noninteractive" | |
| sudo debconf-set-selections <<< "mariadb-server-10.0 mysql-server/root_password password $MYSQL_PASSWORD" | |
| sudo debconf-set-selections <<< "mariadb-server-10.0 mysql-server/root_password_again password $MYSQL_PASSWORD" | |
| # Install software | |
| sudo apt-get install -y software-properties-common htop ntp rsync unzip mc git mysqltuner newrelic-sysmond mariadb-server | |
| sudo apt-get install -y php5-fpm php5-mysql php5-gd php5-mcrypt php5-intl php5-cli php5-curl libssh2-php | |
| sudo apt-get install -y apache2 libapache2-mod-fastcgi | |
| sudo service apache2 restart | |
| # Create vhost | |
| sudo mkdir -p "${USER_DIR}${DOMAIN}" | |
| sudo chmod -R 755 "${USER_DIR}${DOMAIN}" | |
| sudo chown -R www-data:www-data "${USER_DIR}${DOMAIN}" | |
| if ! echo " | |
| <VirtualHost *:80> | |
| ServerAdmin $ADMIN_MAIL | |
| ServerName $DOMAIN | |
| ServerAlias www.$DOMAIN | |
| DocumentRoot $USER_DIR$DOMAIN | |
| <Directory $USER_DIR$DOMAIN/> | |
| Options Indexes FollowSymLinks MultiViews | |
| AllowOverride All | |
| Order allow,deny | |
| allow from all | |
| </Directory> | |
| ErrorLog /var/log/apache2/$DOMAIN-error.log | |
| LogLevel error | |
| CustomLog /var/log/apache2/$DOMAIN-access.log combined | |
| </VirtualHost>" > $SITES_AVAILABLE_DOMAIN | |
| then | |
| echo -e $"There is an ERROR creating $DOMAIN file" | |
| exit; | |
| else | |
| echo -e $"\nNew Virtual Host Created\n" | |
| fi | |
| sudo a2ensite $DOMAIN | |
| sudo service apache2 restart | |
| # Run MySQL install scripts | |
| sudo mysql_secure_installation | |
| sudo service mysql start | |
| # Configure PHP-FPM | |
| echo "<IfModule mod_fastcgi.c> | |
| AddHandler php5-fcgi .php | |
| Action php5-fcgi /php5-fcgi | |
| Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi | |
| FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -socket /var/run/php5-fpm.sock -pass-header Authorization | |
| <Directory /usr/lib/cgi-bin> | |
| Require all granted | |
| </Directory> | |
| </IfModule>" > $PHP_FPM_CONF | |
| # Tweak PHP settings | |
| sudo sed -i "s/^expose_php = On/expose_php = Off/g" /etc/php5/fpm/php.ini | |
| sudo sed -i "s/^;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g" /etc/php5/fpm/php.ini | |
| sudo sed -i "s/^session.gc_probability = 0/session.gc_probability = 1/g" /etc/php5/fpm/php.ini | |
| sudo sed -i "s/^;display_errors = Off/display_errors = Off/g" /etc/php5/fpm/php.ini | |
| sudo sed -i "s/^max_input_time = -1/max_input_time = 60/g" /etc/php5/fpm/php.ini | |
| sudo sed -i "s/^upload_max_filesize = 2M/upload_max_filesize = 8M/g" /etc/php5/fpm/php.ini | |
| sudo sed -i "s/^disable_functions = /disable_functions = passthru,shell_exec,proc_open,popen,show_source,/g" /etc/php5/fpm/php.ini | |
| sudo service php5-fpm restart | |
| # Enable modules and start Apache | |
| a2enmod actions fastcgi alias rewrite | |
| a2enconf php5-fpm | |
| service apache2 reload | |
| sudo service apache2 restart | |
| # Synchronize clock | |
| sudo dpkg-reconfigure tzdata | |
| sudo ntpdate pool.ntp.org | |
| sudo service ntp start | |
| # Finish | |
| sudo service apache2 restart | |
| echo -e $"Complete! \nYou now have a new Virtual Host \nYour new host is: http://$DOMAIN \nAnd its located at $USER_DIR$DOMAIN" | |
| exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment