Last active
August 24, 2016 07:46
-
-
Save shengyou/644b1ac28fa05e34146369e4bda53176 to your computer and use it in GitHub Desktop.
COSCUP 2016 Laravel 部署工作坊裝機指令集
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
# get startup.sh from gist | |
wget https://gist.githubusercontent.com/shengyou/644b1ac28fa05e34146369e4bda53176/raw/06028bf9e9870aaed0085261bdbdbcc91a6b0128/startup.sh | |
# run startup script | |
bash startup.sh | |
# generate ssh key | |
ssh-keygen -t rsa -b 4096 -C "{your email}" | |
# clone your app | |
git clone {your repo} | |
# install app | |
mv {repo} laravel | |
cd laravel | |
composer install --no-scripts | |
composer run-script post-root-package-install | |
composer run-script post-install-cmd | |
composer run-script post-create-project-cmd | |
# setup .env and run migrations | |
vim .env | |
php artisan migrate | |
# restart services | |
sudo systemctl restart mysql | |
sudo systemctl restart nginx | |
sudo systemctl restart php7.0-fpm |
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 | |
export DEBIAN_FRONTEND=noninteractive | |
# Get Current Account Name | |
PWD=$(pwd) | |
ACCOUNT=${PWD:6} | |
# Update Package List | |
sudo apt-get update | |
# Update System Packages | |
sudo apt-get -y upgrade | |
# Force Locale | |
sudo echo "LC_ALL=en_US.UTF-8" >> /etc/default/locale | |
sudo locale-gen en_US.UTF-8 | |
# Install Some PPAs | |
sudo apt-get install -y software-properties-common curl | |
sudo apt-add-repository ppa:nginx/development -y | |
sudo apt-add-repository ppa:ondrej/php -y | |
# Update Package Lists | |
sudo apt-get update | |
# Install Some Basic Packages | |
sudo apt-get install -y build-essential dos2unix gcc git libmcrypt4 libpcre3-dev \ | |
make python2.7-dev python-pip re2c supervisor unattended-upgrades whois vim libnotify-bin | |
# Set My Timezone | |
sudo ln -sf /usr/share/zoneinfo/UTC /etc/localtime | |
# Install PHP Stuffs | |
sudo apt-get install -y php7.0-cli php7.0-dev \ | |
php-pgsql php-sqlite3 php-gd php-apcu \ | |
php-curl php7.0-mcrypt \ | |
php-imap php-mysql php-memcached php7.0-readline php-xdebug \ | |
php-mbstring php-xml php7.0-zip php7.0-intl php7.0-bcmath php-soap | |
# Install Composer | |
curl -sS https://getcomposer.org/installer | php | |
sudo mv composer.phar /usr/local/bin/composer | |
# Disable XDebug On The CLI | |
sudo phpdismod -s cli xdebug | |
# Set Some PHP CLI Settings | |
sudo sed -i "s/error_reporting = .*/error_reporting = E_ALL/" /etc/php/7.0/cli/php.ini | |
sudo sed -i "s/display_errors = .*/display_errors = On/" /etc/php/7.0/cli/php.ini | |
sudo sed -i "s/memory_limit = .*/memory_limit = 512M/" /etc/php/7.0/cli/php.ini | |
sudo sed -i "s/;date.timezone.*/date.timezone = UTC/" /etc/php/7.0/cli/php.ini | |
# Install Nginx & PHP-FPM | |
sudo apt-get install -y nginx php7.0-fpm | |
# Setup Some PHP-FPM Options | |
echo "xdebug.remote_enable = 1" | sudo tee --append /etc/php/7.0/fpm/conf.d/20-xdebug.ini > /dev/null | |
echo "xdebug.remote_connect_back = 1" | sudo tee --append /etc/php/7.0/fpm/conf.d/20-xdebug.ini > /dev/null | |
echo "xdebug.remote_port = 9000" | sudo tee --append /etc/php/7.0/fpm/conf.d/20-xdebug.ini > /dev/null | |
echo "xdebug.max_nesting_level = 512" | sudo tee --append /etc/php/7.0/fpm/conf.d/20-xdebug.ini > /dev/null | |
sudo sed -i "s/error_reporting = .*/error_reporting = E_ALL/" /etc/php/7.0/fpm/php.ini | |
sudo sed -i "s/display_errors = .*/display_errors = On/" /etc/php/7.0/fpm/php.ini | |
sudo sed -i "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/" /etc/php/7.0/fpm/php.ini | |
sudo sed -i "s/memory_limit = .*/memory_limit = 512M/" /etc/php/7.0/fpm/php.ini | |
sudo sed -i "s/upload_max_filesize = .*/upload_max_filesize = 100M/" /etc/php/7.0/fpm/php.ini | |
sudo sed -i "s/post_max_size = .*/post_max_size = 100M/" /etc/php/7.0/fpm/php.ini | |
sudo sed -i "s/;date.timezone.*/date.timezone = UTC/" /etc/php/7.0/fpm/php.ini | |
# Copy fastcgi_params to Nginx | |
sudo tee /etc/nginx/fastcgi_params > /dev/null << 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 | |
sudo sed -i "s/user www-data;/user $ACCOUNT;/" /etc/nginx/nginx.conf | |
sudo sed -i "s/# server_names_hash_bucket_size.*/server_names_hash_bucket_size 64;/" /etc/nginx/nginx.conf | |
sudo sed -i "s/user = www-data/user = $ACCOUNT/" /etc/php/7.0/fpm/pool.d/www.conf | |
sudo sed -i "s/group = www-data/group = $ACCOUNT/" /etc/php/7.0/fpm/pool.d/www.conf | |
sudo sed -i "s/listen\.owner.*/listen.owner = $ACCOUNT/" /etc/php/7.0/fpm/pool.d/www.conf | |
sudo sed -i "s/listen\.group.*/listen.group = $ACCOUNT/" /etc/php/7.0/fpm/pool.d/www.conf | |
sudo sed -i "s/;listen\.mode.*/listen.mode = 0666/" /etc/php/7.0/fpm/pool.d/www.conf | |
# Add User To WWW-Data | |
sudo usermod -a -G www-data $ACCOUNT | |
id $ACCOUNT | |
groups $ACCOUNT | |
# Get Public External IP | |
IP="$(dig +short myip.opendns.com @resolver1.opendns.com)" | |
# Generate Nginx Site | |
BLOCK="server { | |
listen 80; | |
server_name $IP; | |
root \"/home/$ACCOUNT/laravel/public\"; | |
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; } | |
access_log off; | |
error_log /var/log/nginx/$1-error.log error; | |
sendfile off; | |
client_max_body_size 100m; | |
location ~ \.php$ { | |
fastcgi_split_path_info ^(.+\.php)(/.+)$; | |
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; | |
fastcgi_index index.php; | |
include fastcgi_params; | |
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name; | |
fastcgi_intercept_errors off; | |
fastcgi_buffer_size 16k; | |
fastcgi_buffers 4 16k; | |
fastcgi_connect_timeout 300; | |
fastcgi_send_timeout 300; | |
fastcgi_read_timeout 300; | |
} | |
location ~ /\.ht { | |
deny all; | |
} | |
} | |
" | |
echo "$BLOCK" | sudo tee /etc/nginx/sites-available/default > /dev/null | |
# Install MySQL | |
echo "mysql-server mysql-server/root_password password secret.0821" | sudo debconf-set-selections | |
echo "mysql-server mysql-server/root_password_again password secret.0821" | sudo debconf-set-selections | |
sudo apt-get install -y mysql-server | |
# Configure MySQL Password Lifetime | |
echo "default_password_lifetime = 0" | sudo tee --append /etc/mysql/mysql.conf.d/mysqld.cnf > /dev/null | |
# Configure MySQL Remote Access | |
sudo sed -i '/^bind-address/s/bind-address.*=.*/bind-address = 0.0.0.0/' /etc/mysql/mysql.conf.d/mysqld.cnf | |
mysql --user="root" --password="secret.0821" -e "GRANT ALL ON *.* TO root@'0.0.0.0' IDENTIFIED BY 'secret.0821' WITH GRANT OPTION;" | |
mysql --user="root" --password="secret.0821" -e "CREATE USER 'homestead'@'0.0.0.0' IDENTIFIED BY 'secret.0821';" | |
mysql --user="root" --password="secret.0821" -e "GRANT ALL ON *.* TO 'homestead'@'0.0.0.0' IDENTIFIED BY 'secret.0821' WITH GRANT OPTION;" | |
mysql --user="root" --password="secret.0821" -e "GRANT ALL ON *.* TO 'homestead'@'%' IDENTIFIED BY 'secret.0821' WITH GRANT OPTION;" | |
mysql --user="root" --password="secret.0821" -e "FLUSH PRIVILEGES;" | |
mysql --user="root" --password="secret.0821" -e "CREATE DATABASE homestead;" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment