├── ubuntu18.04_update_app.sh ├── ubuntu18.04_configure_deploy_env.sh ├── macos10.15_configure_dev_env.sh ├── ubuntu18.04_configure_dev_env.sh ├── windows10_configure_dev_env.ps1 ├── ubuntu18.04_create_app.sh └── README.md /ubuntu18.04_update_app.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Get app name from parameter or ask user for it (copy and paste all code between "if" and "fi" in your terminal) 4 | if [[ -z ${1} ]] && [[ -z "${appname}" ]]; then 5 | read -p "Enter the name of your app without hyphens (eg. myawesomeapp):" appname 6 | else 7 | appname=${1:-${appname}} 8 | fi 9 | 10 | # Go inside the app directory 11 | cd /var/www/${appname} 12 | if [ ! $? = 0 ]; then 13 | exit 1 14 | fi 15 | 16 | # Pull the latest changes 17 | git pull 18 | if [ ! $? = 0 ]; then 19 | exit 1 20 | fi 21 | 22 | # Install PHP dependencies 23 | composer install 24 | if [ ! $? = 0 ]; then 25 | exit 1 26 | fi 27 | 28 | # Install JS dependencies 29 | yarn install 30 | if [ ! $? = 0 ]; then 31 | exit 1 32 | fi 33 | 34 | # Build assets 35 | yarn build 36 | if [ ! $? = 0 ]; then 37 | exit 1 38 | fi 39 | 40 | # Execute database migrations 41 | php bin/console doctrine:migrations:diff 42 | if [ ! $? = 0 ]; then 43 | exit 1 44 | fi 45 | php bin/console doctrine:migrations:migrate -n 46 | if [ ! $? = 0 ]; then 47 | exit 1 48 | fi 49 | 50 | # Clear the cache 51 | php bin/console cache:clear 52 | if [ ! $? = 0 ]; then 53 | exit 1 54 | fi 55 | -------------------------------------------------------------------------------- /ubuntu18.04_configure_deploy_env.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Update packages list 4 | sudo apt update 5 | if [ ! $? = 0 ]; then 6 | exit 1 7 | fi 8 | 9 | # Install 10 | sudo apt install apache2 -y 11 | if [ ! $? = 0 ]; then 12 | exit 1 13 | fi 14 | 15 | # Enable modules 16 | sudo a2enmod ssl 17 | if [ ! $? = 0 ]; then 18 | exit 1 19 | fi 20 | sudo a2enmod rewrite 21 | if [ ! $? = 0 ]; then 22 | exit 1 23 | fi 24 | 25 | # Copy php.ini CLI configuration 26 | sudo mv $(php -r "echo php_ini_loaded_file();") /etc/php/7.3/apache2/php.ini 27 | if [ ! $? = 0 ]; then 28 | exit 1 29 | fi 30 | apache2 -v 31 | if [ ! $? = 0 ]; then 32 | exit 1 33 | fi 34 | 35 | # Add Certbot official repositories 36 | sudo add-apt-repository universe 37 | if [ ! $? = 0 ]; then 38 | exit 1 39 | fi 40 | sudo add-apt-repository ppa:certbot/certbot -y 41 | if [ ! $? = 0 ]; then 42 | exit 1 43 | fi 44 | 45 | # Install 46 | sudo apt install certbot -y 47 | if [ ! $? = 0 ]; then 48 | exit 1 49 | fi 50 | 51 | # Add rules and activate firewall 52 | sudo ufw allow OpenSSH 53 | if [ ! $? = 0 ]; then 54 | exit 1 55 | fi 56 | sudo ufw allow in "Apache Full" 57 | if [ ! $? = 0 ]; then 58 | exit 1 59 | fi 60 | echo 'y' | sudo ufw enable 61 | if [ ! $? = 0 ]; then 62 | exit 1 63 | fi 64 | -------------------------------------------------------------------------------- /macos10.15_configure_dev_env.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Install 4 | /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 5 | if [ ! $? = 0 ]; then 6 | exit 1 7 | fi 8 | brew -v 9 | if [ ! $? = 0 ]; then 10 | exit 1 11 | fi 12 | 13 | # Install 14 | brew install git 15 | if [ ! $? = 0 ]; then 16 | exit 1 17 | fi 18 | # Reload $PATH 19 | export PATH="/usr/local/bin:$PATH" 20 | if [ ! $? = 0 ]; then 21 | exit 1 22 | fi 23 | git --version 24 | if [ ! $? = 0 ]; then 25 | exit 1 26 | fi 27 | 28 | # Download executable in local user folder 29 | curl -sS https://get.symfony.com/cli/installer | bash 30 | if [ ! $? = 0 ]; then 31 | exit 1 32 | fi 33 | 34 | # Move the executable in global bin directory in order to use it globally 35 | sudo mv ~/.symfony/bin/symfony /usr/local/bin/symfony 36 | if [ ! $? = 0 ]; then 37 | exit 1 38 | fi 39 | symfony -V 40 | if [ ! $? = 0 ]; then 41 | exit 1 42 | fi 43 | 44 | # Install 45 | brew install php@7.3 46 | if [ ! $? = 0 ]; then 47 | exit 1 48 | fi 49 | 50 | # Replace default macOS PHP installation in $PATH 51 | brew link php@7.3 --force 52 | if [ ! $? = 0 ]; then 53 | exit 1 54 | fi 55 | 56 | # Reload $PATH 57 | export PATH="/usr/local/opt/php@7.3/bin:$PATH" 58 | if [ ! $? = 0 ]; then 59 | exit 1 60 | fi 61 | 62 | # Install extensions 63 | pecl install xdebug 64 | if [ ! $? = 0 ]; then 65 | exit 1 66 | fi 67 | 68 | # Update some configuration in php.ini 69 | phpinipath=$(php -r "echo php_ini_loaded_file();") 70 | if [ ! $? = 0 ]; then 71 | exit 1 72 | fi 73 | sudo sed -i '' -e 's/post_max_size = 8M/post_max_size = 64M/g' ${phpinipath} > ./php.ini.tmp 74 | if [ ! $? = 0 ]; then 75 | exit 1 76 | fi 77 | sudo mv ./php.ini.tmp ${phpinipath} 78 | if [ ! $? = 0 ]; then 79 | exit 1 80 | fi 81 | sudo sed -i '' -e 's/upload_max_filesize = 8M/upload_max_filesize = 64M/g' ${phpinipath} > ./php.ini.tmp 82 | if [ ! $? = 0 ]; then 83 | exit 1 84 | fi 85 | sudo mv ./php.ini.tmp ${phpinipath} 86 | if [ ! $? = 0 ]; then 87 | exit 1 88 | fi 89 | sudo sed -i '' -e 's/memory_limit = 128M/memory_limit = -1/g' ${phpinipath} > ./php.ini.tmp 90 | if [ ! $? = 0 ]; then 91 | exit 1 92 | fi 93 | sudo mv ./php.ini.tmp ${phpinipath} 94 | if [ ! $? = 0 ]; then 95 | exit 1 96 | fi 97 | php -v 98 | if [ ! $? = 0 ]; then 99 | exit 1 100 | fi 101 | 102 | # Download installer 103 | sudo php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" 104 | if [ ! $? = 0 ]; then 105 | exit 1 106 | fi 107 | 108 | # Install 109 | sudo php composer-setup.php --version=1.9.1 --install-dir=/usr/local/bin/ 110 | if [ ! $? = 0 ]; then 111 | exit 1 112 | fi 113 | 114 | # Remove installer 115 | sudo php -r "unlink('composer-setup.php');" 116 | if [ ! $? = 0 ]; then 117 | exit 1 118 | fi 119 | 120 | # Make it executable globally 121 | sudo mv /usr/local/bin/composer.phar /usr/local/bin/composer 122 | if [ ! $? = 0 ]; then 123 | exit 1 124 | fi 125 | composer -V 126 | if [ ! $? = 0 ]; then 127 | exit 1 128 | fi 129 | 130 | # Install 131 | brew install mariadb@10.4 132 | if [ ! $? = 0 ]; then 133 | exit 1 134 | fi 135 | 136 | # Install 137 | brew install node@12 138 | if [ ! $? = 0 ]; then 139 | exit 1 140 | fi 141 | # Add node to $PATH 142 | brew link node@12 --force 143 | if [ ! $? = 0 ]; then 144 | exit 1 145 | fi 146 | node -v 147 | if [ ! $? = 0 ]; then 148 | exit 1 149 | fi 150 | npm -v 151 | if [ ! $? = 0 ]; then 152 | exit 1 153 | fi 154 | 155 | # Install 156 | curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 1.21.1 157 | if [ ! $? = 0 ]; then 158 | exit 1 159 | fi 160 | 161 | # Reload $PATH 162 | export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH" 163 | if [ ! $? = 0 ]; then 164 | exit 1 165 | fi 166 | yarn -v 167 | if [ ! $? = 0 ]; then 168 | exit 1 169 | fi 170 | -------------------------------------------------------------------------------- /ubuntu18.04_configure_dev_env.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Update packages list 4 | sudo apt update 5 | if [ ! $? = 0 ]; then 6 | exit 1 7 | fi 8 | 9 | # Install 10 | sudo apt install software-properties-common curl -y 11 | if [ ! $? = 0 ]; then 12 | exit 1 13 | fi 14 | curl --version 15 | if [ ! $? = 0 ]; then 16 | exit 1 17 | fi 18 | 19 | # Install 20 | sudo apt install git -y 21 | if [ ! $? = 0 ]; then 22 | exit 1 23 | fi 24 | git --version 25 | if [ ! $? = 0 ]; then 26 | exit 1 27 | fi 28 | 29 | # Download executable in local user folder 30 | curl -sS https://get.symfony.com/cli/installer | bash 31 | if [ ! $? = 0 ]; then 32 | exit 1 33 | fi 34 | 35 | # Move the executable in global bin directory in order to use it globally 36 | sudo mv ~/.symfony/bin/symfony /usr/local/bin/symfony 37 | if [ ! $? = 0 ]; then 38 | exit 1 39 | fi 40 | symfony -V 41 | if [ ! $? = 0 ]; then 42 | exit 1 43 | fi 44 | 45 | # Add PHP official repository 46 | sudo add-apt-repository ppa:ondrej/php -y 47 | if [ ! $? = 0 ]; then 48 | exit 1 49 | fi 50 | 51 | # Update packages list 52 | sudo apt update 53 | if [ ! $? = 0 ]; then 54 | exit 1 55 | fi 56 | 57 | # Install 58 | sudo apt install php7.3 -y 59 | if [ ! $? = 0 ]; then 60 | exit 1 61 | fi 62 | 63 | # Install extensions 64 | sudo apt install php7.3-mbstring php7.3-mysql php7.3-xml php7.3-curl php7.3-zip php7.3-intl php7.3-gd php-xdebug -y 65 | if [ ! $? = 0 ]; then 66 | exit 1 67 | fi 68 | 69 | # Update some configuration in php.ini 70 | phpinipath=$(php -r "echo php_ini_loaded_file();") 71 | if [ ! $? = 0 ]; then 72 | exit 1 73 | fi 74 | sudo bash -c "sed -e 's/post_max_size = 8M/post_max_size = 64M/g' ${phpinipath} > ./php.ini.tmp" 75 | if [ ! $? = 0 ]; then 76 | exit 1 77 | fi 78 | sudo mv ./php.ini.tmp ${phpinipath} 79 | if [ ! $? = 0 ]; then 80 | exit 1 81 | fi 82 | sudo bash -c "sed -e 's/upload_max_filesize = 8M/upload_max_filesize = 64M/g' ${phpinipath} > ./php.ini.tmp" 83 | if [ ! $? = 0 ]; then 84 | exit 1 85 | fi 86 | sudo mv ./php.ini.tmp ${phpinipath} 87 | if [ ! $? = 0 ]; then 88 | exit 1 89 | fi 90 | sudo bash -c "sed -e 's/memory_limit = 128M/memory_limit = -1/g' ${phpinipath} > ./php.ini.tmp" 91 | if [ ! $? = 0 ]; then 92 | exit 1 93 | fi 94 | sudo mv ./php.ini.tmp ${phpinipath} 95 | if [ ! $? = 0 ]; then 96 | exit 1 97 | fi 98 | 99 | # Replace default PHP installation in $PATH 100 | sudo update-alternatives --set php /usr/bin/php7.3 101 | if [ ! $? = 0 ]; then 102 | exit 1 103 | fi 104 | php -v 105 | if [ ! $? = 0 ]; then 106 | exit 1 107 | fi 108 | 109 | # Download installer 110 | sudo php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" 111 | if [ ! $? = 0 ]; then 112 | exit 1 113 | fi 114 | 115 | # Install 116 | sudo php composer-setup.php --version=1.9.1 --install-dir=/usr/local/bin/ 117 | if [ ! $? = 0 ]; then 118 | exit 1 119 | fi 120 | 121 | # Remove installer 122 | sudo php -r "unlink('composer-setup.php');" 123 | if [ ! $? = 0 ]; then 124 | exit 1 125 | fi 126 | 127 | # Make it executable globally 128 | sudo mv /usr/local/bin/composer.phar /usr/local/bin/composer 129 | if [ ! $? = 0 ]; then 130 | exit 1 131 | fi 132 | composer -V 133 | if [ ! $? = 0 ]; then 134 | exit 1 135 | fi 136 | 137 | # Add MariaDB official repository 138 | curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo -E bash 139 | if [ ! $? = 0 ]; then 140 | exit 1 141 | fi 142 | 143 | # Update packages list 144 | sudo apt update 145 | if [ ! $? = 0 ]; then 146 | exit 1 147 | fi 148 | 149 | # Install 150 | sudo apt install mariadb-server-10.4 -y 151 | if [ ! $? = 0 ]; then 152 | exit 1 153 | fi 154 | 155 | # Add NodeJS official repository and update packages list 156 | curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash - 157 | if [ ! $? = 0 ]; then 158 | exit 1 159 | fi 160 | 161 | # Install 162 | sudo apt install nodejs -y 163 | if [ ! $? = 0 ]; then 164 | exit 1 165 | fi 166 | node -v 167 | if [ ! $? = 0 ]; then 168 | exit 1 169 | fi 170 | npm -v 171 | if [ ! $? = 0 ]; then 172 | exit 1 173 | fi 174 | 175 | # Add Yarn official repository 176 | curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - 177 | if [ ! $? = 0 ]; then 178 | exit 1 179 | fi 180 | echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list 181 | if [ ! $? = 0 ]; then 182 | exit 1 183 | fi 184 | 185 | # Update packages list 186 | sudo apt update 187 | if [ ! $? = 0 ]; then 188 | exit 1 189 | fi 190 | 191 | # Install 192 | sudo apt install yarn=1.21* -y 193 | if [ ! $? = 0 ]; then 194 | exit 1 195 | fi 196 | yarn -v 197 | if [ ! $? = 0 ]; then 198 | exit 1 199 | fi 200 | -------------------------------------------------------------------------------- /windows10_configure_dev_env.ps1: -------------------------------------------------------------------------------- 1 | # Install 2 | Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) 3 | 4 | # Reload your $PATH 5 | $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") 6 | 7 | choco -v 8 | 9 | # Install 10 | choco install git -y 11 | 12 | # Reload $PATH 13 | $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") 14 | 15 | git --version 16 | 17 | # Create a new folder 18 | New-Item -ItemType Directory -Force -Path C:\tools 19 | New-Item -ItemType Directory -Force -Path C:\tools\symfony 20 | 21 | # Add this folder to $PATH 22 | [Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\tools\symfony", "Machine") 23 | 24 | # Determine computer architecture 25 | IF ((Get-WmiObject -class Win32_Processor) -like '*Intel*'){$arch="386"} Else {$arch="amd64"} 26 | 27 | # Enable TLS 1.2 (in order to connect correctly to Github) 28 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; 29 | 30 | # Download executable from Github depending on computer architecture 31 | (New-Object System.Net.WebClient).DownloadFile("https://github.com/symfony/cli/releases/latest/download/symfony_windows_$arch.exe", "C:\tools\symfony\symfony.exe"); 32 | 33 | # Reload $PATH 34 | $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") 35 | 36 | symfony -V 37 | 38 | # Install 39 | choco install php --version=7.3.12 -y 40 | 41 | # Install extensions 42 | iwr -outf C:\tools\php73\ext\php_xdebug.dll http://xdebug.org/files/php_xdebug-2.9.0-7.3-vc15-nts-x86_64.dll 43 | 44 | # Activate extensions in php.ini 45 | Add-Content c:\tools\php73\php.ini "extension_dir = ext" 46 | Add-Content c:\tools\php73\php.ini "zend_extension = C:\tools\php73\ext\php_xdebug.dll" 47 | Add-Content c:\tools\php73\php.ini "zend_extension = C:\tools\php73\ext\php_opcache.dll" 48 | ((Get-Content -path C:\tools\php73\php.ini -Raw) -replace ';extension=mbstring','extension=mbstring') | Set-Content -Path C:\tools\php73\php.ini 49 | ((Get-Content -path C:\tools\php73\php.ini -Raw) -replace ';extension=openssl','extension=openssl') | Set-Content -Path C:\tools\php73\php.ini 50 | ((Get-Content -path C:\tools\php73\php.ini -Raw) -replace ';extension=curl','extension=curl') | Set-Content -Path C:\tools\php73\php.ini 51 | ((Get-Content -path C:\tools\php73\php.ini -Raw) -replace ';extension=pdo_mysql','extension=pdo_mysql') | Set-Content -Path C:\tools\php73\php.ini 52 | ((Get-Content -path C:\tools\php73\php.ini -Raw) -replace ';extension=gd2','extension=gd2') | Set-Content -Path C:\tools\php73\php.ini 53 | ((Get-Content -path C:\tools\php73\php.ini -Raw) -replace ';extension=intl','extension=intl') | Set-Content -Path C:\tools\php73\php.ini 54 | 55 | # Update some configuration in php.ini 56 | ((Get-Content -path C:\tools\php73\php.ini -Raw) -replace 'post_max_size = 8M','post_max_size = 64M') | Set-Content -Path C:\tools\php73\php.ini 57 | ((Get-Content -path C:\tools\php73\php.ini -Raw) -replace 'upload_max_filesize = 2M','upload_max_filesize = 64M') | Set-Content -Path C:\tools\php73\php.ini 58 | ((Get-Content -path C:\tools\php73\php.ini -Raw) -replace 'memory_limit = 128M','memory_limit = -1') | Set-Content -Path C:\tools\php73\php.ini 59 | 60 | # Reload $PATH 61 | $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") 62 | 63 | php -v 64 | 65 | # Download installer 66 | php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" 67 | 68 | # Create a new folder 69 | New-Item -ItemType Directory -Force -Path C:\tools 70 | New-Item -ItemType Directory -Force -Path C:\tools\composer 71 | 72 | # Add this folder to $PATH 73 | [Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\tools\composer", "Machine") 74 | 75 | # Install 76 | php composer-setup.php --version=1.9.1 --install-dir=C:\tools\composer 77 | 78 | # Remove installer 79 | php -r "unlink('composer-setup.php');" 80 | 81 | # Make it executable globally 82 | New-Item -ItemType File -Path C:\tools\composer\composer.bat 83 | Add-Content C:\tools\composer\composer.bat "@php %~dp0composer.phar" 84 | 85 | # Reload $PATH 86 | $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") 87 | 88 | composer -V 89 | 90 | # Install 91 | choco install mariadb --version=10.4.8 -y 92 | 93 | # Reload $PATH 94 | $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") 95 | 96 | # Install 97 | choco install nodejs --version=12.13.1 -y 98 | 99 | # Reload $PATH 100 | $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") 101 | 102 | node -v 103 | npm -v 104 | 105 | # Install 106 | choco install yarn --version=1.21.1 -y 107 | 108 | # Reload $PATH 109 | $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") 110 | 111 | yarn -v 112 | -------------------------------------------------------------------------------- /ubuntu18.04_create_app.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Get app name from parameter or ask user for it (copy and paste all stuffs between "if" and "fi" in your terminal) 4 | if [[ -z ${1} ]] && [[ -z "${appname}" ]]; then 5 | read -p "Enter the name of your app without hyphens (eg. myawesomeapp):" appname 6 | else 7 | appname=${1:-${appname}} 8 | fi 9 | 10 | # Get app domain name from parameter or ask user for it (copy and paste all stuffs between "if" and "fi" in your terminal) 11 | if [[ -z ${2} ]] && [[ -z "${appdomain}" ]]; then 12 | read -p "Enter the domain name on which you want your app to be served (eg. example.com or test.example.com):" appdomain 13 | else 14 | appdomain=${2:-${appdomain}} 15 | fi 16 | 17 | # Get app Git repository URL from parameter or ask user for it (copy and paste all stuffs from "if" to "fi" in your terminal) 18 | if [[ -z ${3} ]] && [[ -z "${apprepositoryurl}" ]]; then 19 | read -p "Enter the Git repository URL of your app:" apprepositoryurl 20 | else 21 | apprepositoryurl=${3:-${apprepositoryurl}} 22 | fi 23 | 24 | # Clone app repository 25 | git clone ${apprepositoryurl} /var/www/${appname} 26 | if [ ! $? = 0 ]; then 27 | exit 1 28 | fi 29 | 30 | # Go inside the app directory 31 | cd /var/www/${appname} 32 | if [ ! $? = 0 ]; then 33 | exit 1 34 | fi 35 | 36 | # Generate a random password for the new mysql user 37 | mysqlpassword=$(openssl rand -hex 15) 38 | if [ ! $? = 0 ]; then 39 | exit 1 40 | fi 41 | 42 | # Create database and related user for the app and grant permissions (copy and paste all stuffs from "sudo mysql" to "EOF" in your terminal) 43 | sudo mysql < ./.env.local.tmp 60 | if [ ! $? = 0 ]; then 61 | exit 1 62 | fi 63 | mv ./.env.local.tmp ./.env.local 64 | if [ ! $? = 0 ]; then 65 | exit 1 66 | fi 67 | 68 | # Set mysql credentials 69 | sed -e 's,DATABASE_URL=mysql://db_user:db_password@127.0.0.1:3306/db_name,DATABASE_URL=mysql://'${appname}':'${mysqlpassword}'@127.0.0.1:3306/'${appname}',g' ./.env.local > ./.env.local.tmp 70 | if [ ! $? = 0 ]; then 71 | exit 1 72 | fi 73 | mv ./.env.local.tmp ./.env.local 74 | if [ ! $? = 0 ]; then 75 | exit 1 76 | fi 77 | 78 | # Set ownership to Apache 79 | sudo chown -R www-data:www-data /var/www/${appname} 80 | if [ ! $? = 0 ]; then 81 | exit 1 82 | fi 83 | 84 | # Set files permissions to 644 85 | sudo find /var/www/${appname} -type f -exec chmod 644 {} \; 86 | if [ ! $? = 0 ]; then 87 | exit 1 88 | fi 89 | 90 | # Set folders permissions to 755 91 | sudo find /var/www/${appname} -type d -exec chmod 755 {} \; 92 | if [ ! $? = 0 ]; then 93 | exit 1 94 | fi 95 | 96 | # Install PHP dependencies 97 | composer install 98 | if [ ! $? = 0 ]; then 99 | exit 1 100 | fi 101 | 102 | # Install JS dependencies 103 | yarn install 104 | if [ ! $? = 0 ]; then 105 | exit 1 106 | fi 107 | 108 | # Build assets 109 | yarn build 110 | if [ ! $? = 0 ]; then 111 | exit 1 112 | fi 113 | 114 | # Execute database migrations 115 | php bin/console doctrine:migrations:diff 116 | php bin/console doctrine:migrations:migrate -n 117 | 118 | # Create an Apache conf file for the app (copy and paste all stuffs from "cat" to "EOF" in your terminal) 119 | cat > /etc/apache2/sites-available/${appname}.conf < 122 | # Set up server name 123 | ServerName ${appdomain} 124 | 125 | # Set up document root 126 | DocumentRoot /var/www/${appname}/public 127 | 128 | # Configure separate log files 129 | ErrorLog /var/log/apache2/error.${appname}.log 130 | CustomLog /var/log/apache2/access.${appname}.log combined 131 | 132 | EOF 133 | if [ ! $? = 0 ]; then 134 | exit 1 135 | fi 136 | 137 | # Activate Apache conf 138 | sudo a2ensite ${appname}.conf 139 | if [ ! $? = 0 ]; then 140 | exit 1 141 | fi 142 | 143 | # Restart Apache to make changes available 144 | sudo service apache2 restart 145 | if [ ! $? = 0 ]; then 146 | exit 1 147 | fi 148 | 149 | # Get a new HTTPS certficate 150 | sudo certbot certonly --webroot -w /var/www/${appname}/public -d ${appdomain} 151 | if [ ! $? = 0 ]; then 152 | exit 1 153 | fi 154 | 155 | # Replace existing conf (copy and paste all stuffs from "cat" to last "EOF" in your terminal) 156 | cat > /etc/apache2/sites-available/${appname}.conf < 159 | # All we need to do here is redirect to HTTPS 160 | RewriteEngine on 161 | RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent] 162 | 163 | 164 | # Listen for the app domain on port 443 (HTTPS) 165 | 166 | # Set up server name 167 | ServerName ${appdomain} 168 | 169 | # Set up document root 170 | DocumentRoot /var/www/${appname}/public 171 | DirectoryIndex /index.php 172 | 173 | # Set up Symfony specific configuration 174 | 175 | AllowOverride None 176 | Order Allow,Deny 177 | Allow from All 178 | FallbackResource /index.php 179 | 180 | 181 | FallbackResource disabled 182 | 183 | 184 | # Configure separate log files 185 | ErrorLog /var/log/apache2/error.${appname}.log 186 | CustomLog /var/log/apache2/access.${appname}.log combined 187 | 188 | # Configure HTTPS 189 | SSLEngine on 190 | SSLCertificateFile /etc/letsencrypt/live/${appdomain}/fullchain.pem 191 | SSLCertificateKeyFile /etc/letsencrypt/live/${appdomain}/privkey.pem 192 | 193 | EOF 194 | if [ ! $? = 0 ]; then 195 | exit 1 196 | fi 197 | 198 | # Restart Apache to make changes available 199 | sudo service apache2 restart 200 | if [ ! $? = 0 ]; then 201 | exit 1 202 | fi 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # The Symfony dev & deploy instructions kit 2 | 3 | Welcome! Here is what this repository can do for you: 4 | 5 | * Provide instructions to configure a similar Symfony development environment on each platform (Ubuntu 18.04 Desktop, macOS 10.15 and Windows 10). 6 | 7 | * Provide instructions to configure a deploy environment on an Ubuntu 18.04 Server machine and automate the update process of a Symfony app created with our [starter kit](https://github.com/WildCodeSchool/sf4-pjt3-starter-kit) with Github Actions. 8 | 9 | The goal is to provide an opinionated, fully tested environment, that just work. 10 | 11 | **This means no headaches trying to configure an environment or a specific tool and no more versions conflicts!** 12 | 13 | ![tenor](https://user-images.githubusercontent.com/6952638/72103402-6b97af00-3329-11ea-980d-63242df89644.gif) 14 | 15 | ## Table of contents 16 | 17 | * [Important notice](#important-notice) 18 | * [Quickstart](#quickstart) 19 | 1. [Configure dev environment](#configure-dev-environment) 20 | 2. [Configure deploy environment](#configure-deploy-environment) 21 | 3. [Deploy a new app](#deploy-a-new-app) 22 | 4. [Deploy updates of an existing app](#deploy-updates-of-an-existing-app) 23 | 5. [Deploy updates automatically with GitHub Actions](#deploy-updates-automatically-with-github-actions) 24 | * [Manual configuration: dev environment](#manual-configuration-dev-environment) 25 | 1. [Prerequisites](#prerequisites) 26 | 2. [Git](#git) 27 | 3. [Symfony CLI](#symfony-cli) 28 | 4. [PHP 7.3](#php-73) 29 | 5. [Composer 1.9](#composer-19) 30 | 6. [MariaDB 10.4](#mariadb-104) 31 | 7. [NodeJS 12](#nodejs-12) 32 | 8. [Yarn 1.21](#yarn-121) 33 | * [Manual configuration: deploy environment](#manual-configuration-deploy-environment) 34 | 1. [Apache 2](#apache-2) 35 | 2. [Certbot](#certbot) 36 | 3. [Firewall](#firewall) 37 | * [Manual configuration: deploy a new app](#manual-configuration-deploy-a-new-app) 38 | 1. [Set up variables](#set-up-variables) 39 | 2. [Download our app](#download-our-app) 40 | 3. [Set up the database and the production mode](#set-up-the-database-and-the-production-mode) 41 | 4. [Set permissions](#set-permissions) 42 | 5. [Install dependencies and build assets](#install-dependencies-and-build-assets) 43 | 6. [Execute database migrations](#execute-database-migrations) 44 | 7. [Set up the web server](#set-up-the-web-server) 45 | 8. [Enabling HTTPS & configure for Symfony](#enabling-https--configure-for-symfony) 46 | * [Manual configuration: deploy updates of an existing app](#manual-configuration-deploy-updates-of-an-existing-app) 47 | 1. [Set up variable](#set-up-variable) 48 | 2. [Download updates of our app](#download-updates-of-our-app) 49 | 3. [Update dependencies and rebuild assets](#update-dependencies-and-rebuild-assets) 50 | 4. [Update database structure & clearing cache](#update-database-structure--clearing-cache) 51 | 52 | ## Important notice 53 | 54 | Configuration scripts for dev & deploy environments are meant to be executed after fresh installation of each OS. 55 | 56 | Their purpose in not to be bullet-proof neither to handle all cases (we will not build a new MAMP/XAMPP). They are just here to get started quickly as they just execute the exact same commands listed in "manual configuration" sections. 57 | 58 | **So, if you have any trouble a non fresh-installed machine, please use "manual configuration" sections to complete your installation environment process.** 59 | 60 | ## Quickstart 61 | 62 | ### Configure dev environment 63 | 64 | [Back to top ↑](#table-of-contents) 65 | 66 | Ubuntu 18.04: 67 | 68 | ```bash 69 | # Get and execute script directly 70 | bash <(wget --no-cache -o /dev/null -O- https://raw.githubusercontent.com/WildCodeSchool/symfony-dev-deploy/master/ubuntu18.04_configure_dev_env.sh) 71 | ``` 72 | 73 | MacOS 10.15: 74 | 75 | ```bash 76 | # Get and execute script directly 77 | bash <(curl -L -H 'Cache-Control: no-cache' https://raw.githubusercontent.com/WildCodeSchool/symfony-dev-deploy/master/macos10.15_configure_dev_env.sh) 78 | ``` 79 | 80 | Windows 10: 81 | 82 | ```powershell 83 | # Get and execute script directly 84 | Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/WildCodeSchool/symfony-dev-deploy/master/windows10_configure_dev_env.ps1')) 85 | ``` 86 | 87 | *See [manual instructions](#manual-configuration-dev-environment) for details.* 88 | 89 | ### Configure deploy environment 90 | 91 | [Back to top ↑](#table-of-contents) 92 | 93 | *Note: you first need to install everything from [dev environment](#configure-dev-environment).* 94 | 95 | Ubuntu 18.04 Server: 96 | 97 | ```bash 98 | # Get and execute script directly 99 | bash <(wget --no-cache -o /dev/null -O- https://raw.githubusercontent.com/WildCodeSchool/symfony-dev-deploy/master/ubuntu18.04_configure_deploy_env.sh) 100 | ``` 101 | 102 | *See [manual instructions](#manual-configuration-deploy-a-new-app) for details.* 103 | 104 | ### Deploy a new app 105 | 106 | [Back to top ↑](#table-of-contents) 107 | 108 | *Note: you first need to add a A or AAAA record on your domain name poiting to this machine IP address.* 109 | 110 | Ubuntu 18.04 Server: 111 | 112 | ```bash 113 | # Get and execute script directly 114 | bash <(wget --no-cache -o /dev/null -O- https://raw.githubusercontent.com/WildCodeSchool/symfony-dev-deploy/master/ubuntu18.04_create_app.sh) 115 | ``` 116 | 117 | *Note: just after the "bash" command, you can pass the app name, the domain name and the repository URL as arguments in order to make the script non-interactive (eg. … bash myawesameapp example.com ).* 118 | 119 | *See [manual instructions](#manual-configuration-deploy-a-new-app) for details.* 120 | 121 | ### Deploy updates of an existing app 122 | 123 | [Back to top ↑](#table-of-contents) 124 | 125 | Ubuntu 18.04 Server: 126 | 127 | ```bash 128 | # Get and execute script directly 129 | bash <(wget --no-cache -o /dev/null -O- https://raw.githubusercontent.com/WildCodeSchool/symfony-dev-deploy/master/ubuntu18.04_update_app.sh) 130 | ``` 131 | 132 | *Note: just after the "bash" command, you can pass the app name as an argument in order to make the script non-interactive (eg. … bash myawesameapp).* 133 | 134 | *See [manual instructions](#manual-configuration-deploy-updates-of-an-existing-app) for details.* 135 | 136 | ### Deploy updates automatically with GitHub Actions 137 | 138 | To do that you simply have to add a basic Github Actions configuration in your repository and execute the update commands through SSH. 139 | 140 | Create a file in ".github/workflows/deploy.yml" at the root of your project containing: 141 | 142 | ```yaml 143 | name: Deploy updates 144 | 145 | on: 146 | push: 147 | branches: master 148 | 149 | jobs: 150 | deploy: 151 | 152 | runs-on: ubuntu-18.04 153 | 154 | steps: 155 | - name: Deploy through SSH 156 | run: | 157 | sshpass -p "${{ secrets.SSH_PASS }}" ssh \ 158 | -tt ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} \ 159 | -o StrictHostKeyChecking=no \ 160 | "appname=${{ secrets.APP_NAME }} && $(wget --no-cache -o /dev/null -O- https://raw.githubusercontent.com/WildCodeSchool/symfony-dev-deploy/master/ubuntu18.04_update_app.sh)" 161 | ``` 162 | 163 | *Note: you must define SSH_PASS, SSH_USER, SSH_HOST and APP_NAME variables in the "Settings > Secrets" section of your GitHub repository. The APP_NAME value must match the one used to deploy the app initially.* 164 | 165 | ## Manual configuration: dev environment 166 | 167 | ### Prerequisites 168 | 169 | [Back to top ↑](#table-of-contents) 170 | 171 | Ubuntu 18.04 Desktop: 172 | 173 | ![curl](https://user-images.githubusercontent.com/6952638/70372369-31785f00-18de-11ea-9835-2946537372ea.jpg) 174 | 175 | On Ubuntu, CURL is needed in order to install some packages with the default package manager. 176 | 177 | ```bash 178 | # Update packages list 179 | sudo apt update 180 | 181 | # Install 182 | sudo apt install software-properties-common curl -y 183 | ``` 184 | 185 | MacOS 10.15: 186 | 187 | ![homebrew](https://user-images.githubusercontent.com/6952638/70372309-a0a18380-18dd-11ea-8280-e86e84f51043.png) 188 | 189 | On MacOS, there is no package manager by default. We need to install the Homebrew package manager in order to install our packages. 190 | 191 | Open the Terminal app and type: 192 | 193 | ```bash 194 | # Install 195 | /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 196 | ``` 197 | 198 | Windows 10: 199 | 200 | ![chocolatey](https://user-images.githubusercontent.com/6952638/70372307-a008ed00-18dd-11ea-8288-97a9fbc7fb46.png) 201 | 202 | On Windows 10, there is no package manager by default. We need to install the Chocolatey package manager in order to install our packages. 203 | 204 | Open the PowerShell command prompt in administrator mode and type: 205 | 206 | ```powershell 207 | # Install 208 | Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) 209 | 210 | # Reload your $PATH 211 | $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") 212 | ``` 213 | 214 | **On Windows, after each installation, you must start a new PowerShell or reload your \$PATH** in order to use the installed packages. All command listed here must only be used inside the PowerShell in **administrator mode** (not the default command prompt). 215 | 216 | ### Git 217 | 218 | [Back to top ↑](#table-of-contents) 219 | 220 | ![git](https://user-images.githubusercontent.com/6952638/71176962-3a1c4e00-226b-11ea-83a1-5a66bd37a68b.png) 221 | 222 | Ubuntu 18.04 Desktop: 223 | 224 | ```bash 225 | # Install 226 | sudo apt install git -y 227 | ``` 228 | 229 | MacOS 10.15: 230 | 231 | ```bash 232 | # Install 233 | brew install git 234 | 235 | # Reload $PATH 236 | export PATH="/usr/local/bin:$PATH" 237 | ``` 238 | 239 | Windows 10: 240 | 241 | ```powershell 242 | # Install 243 | choco install git -y 244 | 245 | # Reload $PATH 246 | $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") 247 | ``` 248 | 249 | ### Symfony CLI 250 | 251 | [Back to top ↑](#table-of-contents) 252 | 253 | ![symfony](https://user-images.githubusercontent.com/6952638/71176964-3ab4e480-226b-11ea-8522-081106cbff50.png) 254 | 255 | Ubuntu 18.04 Desktop: 256 | 257 | ```bash 258 | # Download executable in local user folder 259 | curl -sS https://get.symfony.com/cli/installer | bash 260 | 261 | # Move the executable in global bin directory in order to use it globally 262 | sudo mv ~/.symfony/bin/symfony /usr/local/bin/symfony 263 | ``` 264 | 265 | MacOS 10.15: 266 | 267 | ```bash 268 | # Download executable in local user folder 269 | curl -sS https://get.symfony.com/cli/installer | bash 270 | 271 | # Move the executable in global bin directory in order to use it globally 272 | sudo mv ~/.symfony/bin/symfony /usr/local/bin/symfony 273 | ``` 274 | 275 | Windows 10: 276 | 277 | ```powershell 278 | # Create a new folder 279 | New-Item -ItemType Directory -Force -Path C:\tools 280 | New-Item -ItemType Directory -Force -Path C:\tools\symfony 281 | 282 | # Add this folder to $PATH 283 | [Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\tools\symfony", "Machine") 284 | 285 | # Determine computer architecture 286 | IF ((Get-WmiObject -class Win32_Processor) -like '*Intel*'){$arch="386"} Else {$arch="amd64"} 287 | 288 | # Enable TLS 1.2 (in order to connect correctly to Github) 289 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; 290 | 291 | # Download executable from Github depending on computer architecture 292 | (New-Object System.Net.WebClient).DownloadFile("https://github.com/symfony/cli/releases/latest/download/symfony_windows_$arch.exe", "C:\tools\symfony\symfony.exe"); 293 | 294 | # Reload $PATH 295 | $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") 296 | ``` 297 | 298 | ### PHP 7.3 299 | 300 | [Back to top ↑](#table-of-contents) 301 | 302 | ![php](https://user-images.githubusercontent.com/6952638/70372327-bca52500-18dd-11ea-8638-7cdab7c5d6e0.png) 303 | 304 | Ubuntu 18.04 Desktop: 305 | 306 | ```bash 307 | # Add PHP official repository 308 | sudo add-apt-repository ppa:ondrej/php -y 309 | 310 | # Update packages list 311 | sudo apt update 312 | 313 | # Install 314 | sudo apt install php7.3 -y 315 | 316 | # Install extensions 317 | sudo apt install php7.3-mbstring php7.3-mysql php7.3-xml php7.3-curl php7.3-zip php7.3-intl php7.3-gd php-xdebug -y 318 | 319 | # Update some configuration in php.ini 320 | phpinipath=$(php -r "echo php_ini_loaded_file();") 321 | sudo bash -c "sed -e 's/post_max_size = 8M/post_max_size = 64M/g' ${phpinipath} > ./php.ini.tmp" 322 | sudo mv ./php.ini.tmp ${phpinipath} 323 | sudo bash -c "sed -e 's/upload_max_filesize = 8M/upload_max_filesize = 64M/g' ${phpinipath} > ./php.ini.tmp" 324 | sudo mv ./php.ini.tmp ${phpinipath} 325 | sudo bash -c "sed -e 's/memory_limit = 128M/memory_limit = -1/g' ${phpinipath} > ./php.ini.tmp" 326 | sudo mv ./php.ini.tmp ${phpinipath} 327 | 328 | # Replace default PHP installation in $PATH 329 | sudo update-alternatives --set php /usr/bin/php7.3 330 | ``` 331 | 332 | **Installed PHP Modules:** calendar, Core, ctype, curl, date, dom, exif, fileinfo, filter, ftp, gettext, hash, iconv, json, libxml, mbstring, mysqli, mysqlnd, openssl, pcntl, pcre, PDO, pdo_mysql, Phar, posix, readline, Reflection, session, shmop, SimpleXML, sockets, sodium, SPL, standard, sysvmsg, sysvsem, sysvshm, tokenizer, wddx, xdebug, xml, xmlreader, xmlwriter, xsl, Zend OPcache, zip, zlib 333 | 334 | **Installed Zend Modules:** Xdebug, Zend OPcache 335 | 336 | MacOS 10.15: 337 | 338 | ```bash 339 | # Install 340 | brew install php@7.3 341 | 342 | # Replace default macOS PHP installation in $PATH 343 | brew link php@7.3 --force 344 | 345 | # Reload $PATH 346 | export PATH="/usr/local/opt/php@7.3/bin:$PATH" 347 | 348 | # Install extensions 349 | pecl install xdebug 350 | 351 | # Update some configuration in php.ini 352 | phpinipath=$(php -r "echo php_ini_loaded_file();") 353 | sudo sed -i '' -e 's/post_max_size = 8M/post_max_size = 64M/g' ${phpinipath} > ./php.ini.tmp 354 | sudo mv ./php.ini.tmp ${phpinipath} 355 | sudo sed -i '' -e 's/upload_max_filesize = 8M/upload_max_filesize = 64M/g' ${phpinipath} > ./php.ini.tmp 356 | sudo mv ./php.ini.tmp ${phpinipath} 357 | sudo sed -i '' -e 's/memory_limit = 128M/memory_limit = -1/g' ${phpinipath} > ./php.ini.tmp 358 | sudo ./php.ini.tmp ${phpinipath} 359 | ``` 360 | 361 | **Installed PHP Modules:** bcmath, bz2, calendar, Core, ctype, curl, date, dba, dom, exif, fileinfo, filter, ftp, gd, gettext, gmp, hash, iconv, intl, json, ldap, libxml, mbstring, mysqli, mysqlnd, odbc, openssl, pcntl, pcre, PDO, pdo_dblib, pdo_mysql, PDO_ODBC, pdo_pgsql, pdo_sqlite, pgsql, Phar, phpdbg_webhelper, posix, pspell, readline, Reflection, session, shmop, SimpleXML, soap, sockets, sodium, SPL, sqlite3, standard, sysvmsg, sysvsem, sysvshm, tidy, tokenizer, wddx, xdebug, xml, xmlreader, xmlrpc, xmlwriter, xsl, Zend OPcache, zip, zlib 362 | 363 | **Installed Zend Modules:** Xdebug, Zend OPcache 364 | 365 | Windows 10: 366 | 367 | ```powershell 368 | # Install 369 | choco install php --version=7.3.12 -y 370 | 371 | # Install extensions 372 | iwr -outf C:\tools\php73\ext\php_xdebug.dll http://xdebug.org/files/php_xdebug-2.9.0-7.3-vc15-nts-x86_64.dll 373 | 374 | # Activate extensions in php.ini 375 | Add-Content c:\tools\php73\php.ini "extension_dir = ext" 376 | Add-Content c:\tools\php73\php.ini "zend_extension = C:\tools\php73\ext\php_xdebug.dll" 377 | Add-Content c:\tools\php73\php.ini "zend_extension = C:\tools\php73\ext\php_opcache.dll" 378 | ((Get-Content -path C:\tools\php73\php.ini -Raw) -replace ';extension=mbstring','extension=mbstring') | Set-Content -Path C:\tools\php73\php.ini 379 | ((Get-Content -path C:\tools\php73\php.ini -Raw) -replace ';extension=openssl','extension=openssl') | Set-Content -Path C:\tools\php73\php.ini 380 | ((Get-Content -path C:\tools\php73\php.ini -Raw) -replace ';extension=curl','extension=curl') | Set-Content -Path C:\tools\php73\php.ini 381 | ((Get-Content -path C:\tools\php73\php.ini -Raw) -replace ';extension=pdo_mysql','extension=pdo_mysql') | Set-Content -Path C:\tools\php73\php.ini 382 | ((Get-Content -path C:\tools\php73\php.ini -Raw) -replace ';extension=gd2','extension=gd2') | Set-Content -Path C:\tools\php73\php.ini 383 | ((Get-Content -path C:\tools\php73\php.ini -Raw) -replace ';extension=intl','extension=intl') | Set-Content -Path C:\tools\php73\php.ini 384 | 385 | # Update some configuration in php.ini 386 | ((Get-Content -path C:\tools\php73\php.ini -Raw) -replace 'post_max_size = 8M','post_max_size = 64M') | Set-Content -Path C:\tools\php73\php.ini 387 | ((Get-Content -path C:\tools\php73\php.ini -Raw) -replace 'upload_max_filesize = 2M','upload_max_filesize = 64M') | Set-Content -Path C:\tools\php73\php.ini 388 | ((Get-Content -path C:\tools\php73\php.ini -Raw) -replace 'memory_limit = 128M','memory_limit = -1') | Set-Content -Path C:\tools\php73\php.ini 389 | 390 | # Reload $PATH 391 | $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") 392 | ``` 393 | 394 | **Installed PHP Modules:** bcmath, calendar, Core, ctype, curl, date, dom, filter, gd, hash, iconv, intl, json, libxml, mbstring, mysqlnd, openssl, pcre, PDO, pdo_mysql, Phar, readline, Reflection, session, SimpleXML, SPL, standard, tokenizer, wddx, xdebug, xml, xmlreader, xmlwriter, Zend OPcache, zip, zlib 395 | 396 | **Installed Zend Modules:** Xdebug, Zend OPcache 397 | 398 | ### Composer 1.9 399 | 400 | [Back to top ↑](#table-of-contents) 401 | 402 | ![composer](https://user-images.githubusercontent.com/6952638/70372308-a008ed00-18dd-11ea-9ee0-61d017dfa488.png) 403 | 404 | Ubuntu 18.04 Desktop: 405 | 406 | ```bash 407 | # Download installer 408 | sudo php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" 409 | 410 | # Install 411 | sudo php composer-setup.php --version=1.9.1 --install-dir=/usr/local/bin/ 412 | 413 | # Remove installer 414 | sudo php -r "unlink('composer-setup.php');" 415 | 416 | # Make it executable globally 417 | sudo mv /usr/local/bin/composer.phar /usr/local/bin/composer 418 | ``` 419 | 420 | MacOS 10.15: 421 | 422 | ```bash 423 | # Download installer 424 | sudo php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" 425 | 426 | # Install 427 | sudo php composer-setup.php --version=1.9.1 --install-dir=/usr/local/bin/ 428 | 429 | # Remove installer 430 | sudo php -r "unlink('composer-setup.php');" 431 | 432 | # Make it executable globally 433 | sudo mv /usr/local/bin/composer.phar /usr/local/bin/composer 434 | ``` 435 | 436 | Windows 10: 437 | 438 | ```powershell 439 | # Download installer 440 | php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" 441 | 442 | # Create a new folder 443 | New-Item -ItemType Directory -Force -Path C:\tools 444 | New-Item -ItemType Directory -Force -Path C:\tools\composer 445 | 446 | # Add this folder to $PATH 447 | [Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\tools\composer", "Machine") 448 | 449 | # Install 450 | php composer-setup.php --version=1.9.1 --install-dir=C:\tools\composer 451 | 452 | # Remove installer 453 | php -r "unlink('composer-setup.php');" 454 | 455 | # Make it executable globally 456 | New-Item -ItemType File -Path C:\tools\composer\composer.bat 457 | Add-Content C:\tools\composer\composer.bat "@php %~dp0composer.phar" 458 | 459 | # Reload $PATH 460 | $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") 461 | ``` 462 | 463 | ### MariaDB 10.4 464 | 465 | [Back to top ↑](#table-of-contents) 466 | 467 | ![mariadb](https://user-images.githubusercontent.com/6952638/71176963-3a1c4e00-226b-11ea-9627-e64caabef009.png) 468 | 469 | Ubuntu 18.04: 470 | 471 | ```bash 472 | # Add MariaDB official repository 473 | curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo -E bash 474 | 475 | # Update packages list 476 | sudo apt update 477 | 478 | # Install 479 | sudo apt install mariadb-server-10.4 -y 480 | ``` 481 | 482 | MacOS 10.15: 483 | 484 | ```bash 485 | # Install 486 | brew install mariadb@10.4 487 | ``` 488 | 489 | Windows 10: 490 | 491 | ```powershell 492 | # Install 493 | choco install mariadb --version=10.4.8 -y 494 | 495 | # Reload $PATH 496 | $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") 497 | ``` 498 | 499 | ### NodeJS 12 500 | 501 | [Back to top ↑](#table-of-contents) 502 | 503 | ![node](https://user-images.githubusercontent.com/6952638/71177167-a4cd8980-226b-11ea-9095-c96d5b96faa7.png) 504 | 505 | Ubuntu 18.04 Desktop: 506 | 507 | ```bash 508 | # Add NodeJS official repository and update packages list 509 | curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash - 510 | 511 | # Install 512 | sudo apt install nodejs -y 513 | ``` 514 | 515 | MacOS 10.15: 516 | 517 | ```bash 518 | # Install 519 | brew install node@12 520 | 521 | # Add node to $PATH 522 | brew link node@12 --force 523 | ``` 524 | 525 | Windows 10: 526 | 527 | ```powershell 528 | # Install 529 | choco install nodejs --version=12.13.1 -y 530 | 531 | # Reload $PATH 532 | $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") 533 | ``` 534 | 535 | ### Yarn 1.21 536 | 537 | [Back to top ↑](#table-of-contents) 538 | 539 | ![yarn](https://user-images.githubusercontent.com/6952638/70372314-a13a1a00-18dd-11ea-9cdb-7b976c2beab8.png) 540 | 541 | Ubuntu 18.04 Desktop: 542 | 543 | ```bash 544 | # Add Yarn official repository 545 | curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - 546 | echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list 547 | 548 | # Update packages list 549 | sudo apt update 550 | 551 | # Install 552 | sudo apt install yarn=1.21* -y 553 | ``` 554 | 555 | MacOS 10.15: 556 | 557 | ```bash 558 | # Install 559 | curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 1.21.1 560 | 561 | # Reload $PATH 562 | export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH" 563 | ``` 564 | 565 | Windows 10: 566 | 567 | ```powershell 568 | # Install 569 | choco install yarn --version=1.21.1 -y 570 | 571 | # Reload $PATH 572 | $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") 573 | ``` 574 | 575 | ## Deploy environment: Quick configuration 576 | 577 | [Back to top ↑](#table-of-contents) 578 | 579 | *Note: you first need to install everything from [dev environment](#dev-environment-quick-configuration).* 580 | 581 | Ubuntu 18.04 Server: 582 | 583 | ```bash 584 | # Get and execute configuration script directly 585 | wget --no-cache -o /dev/null -O- https://raw.githubusercontent.com/WildCodeSchool/symfony-dev-deploy/master/ubuntu18.04_configure_deploy_env.sh | bash 586 | ``` 587 | 588 | ## Manual configuration: deploy environment 589 | 590 | *Note: you first need to install everything from [dev environment](#dev-environment-quick-configuration).* 591 | 592 | ### Apache 2 593 | 594 | [Back to top ↑](#table-of-contents) 595 | 596 | Ubuntu 18.04 Server: 597 | 598 | ```bash 599 | # Update packages list 600 | sudo apt update 601 | 602 | # Install 603 | sudo apt install apache2 -y 604 | 605 | # Enable modules 606 | sudo a2enmod ssl 607 | sudo a2enmod rewrite 608 | 609 | # Copy php.ini CLI configuration 610 | sudo mv $(php -r "echo php_ini_loaded_file();") /etc/php/7.3/apache2/php.ini 611 | ``` 612 | 613 | **Installed Apache Modules:** core_module, so_module, watchdog_module, http_module, log_config_module, logio_module, version_module, unixd_module, access_compat_module, alias_module, auth_basic_module, authn_core_module, authn_file_module, authz_core_module, authz_host_module, authz_user_module, autoindex_module, deflate_module, dir_module, env_module, filter_module, mime_module, mpm_prefork_module, negotiation_module, php7_module, reqtimeout_module, rewrite_module, setenvif_module, socache_shmcb_module, ssl_module, status_module 614 | 615 | ### Certbot 616 | 617 | [Back to top ↑](#table-of-contents) 618 | 619 | In order to get SSL certifications, we need certbot. 620 | 621 | Ubuntu 18.04 Server: 622 | 623 | ```bash 624 | # Add Certbot official repositories 625 | sudo add-apt-repository universe 626 | sudo add-apt-repository ppa:certbot/certbot -y 627 | 628 | # Install 629 | sudo apt install certbot -y 630 | ``` 631 | 632 | ### Firewall 633 | 634 | [Back to top ↑](#table-of-contents) 635 | 636 | We will enable Ubuntu firewall in order to prevent remote access to our machine. We will only allow SSH (for remote SSH access) and Apache2 (for remote web access). **Careful, you need to allow SSH before enabling the firewall, if not, you may lose access to your machine.** 637 | 638 | Ubuntu 18.04 Server: 639 | 640 | ```bash 641 | # Add rules and activate firewall 642 | sudo ufw allow OpenSSH 643 | sudo ufw allow in "Apache Full" 644 | echo 'y' | sudo ufw enable 645 | ``` 646 | 647 | ## Manual configuration: deploy a new app 648 | 649 | *Note: you first need to add a A or AAAA record on your domain name poiting to this machine IP address.* 650 | 651 | ### Set up variables 652 | 653 | [Back to top ↑](#table-of-contents) 654 | 655 | We need to configure some variables in order to reduce repetitions/replacements in the next commands. 656 | 657 | Ubuntu 18.04 Server: 658 | 659 | ```bash 660 | # Get app name from parameter or ask user for it (copy and paste all stuffs between "if" and "fi" in your terminal) 661 | if [[ -z ${1} ]] && [[ -z "${appname}" ]]; then 662 | read -p "Enter the name of your app without hyphens (eg. myawesomeapp):" appname 663 | else 664 | appname=${1:-${appname}} 665 | fi 666 | 667 | # Get app domain name from parameter or ask user for it (copy and paste all stuffs between "if" and "fi" in your terminal) 668 | if [[ -z ${2} ]] && [[ -z "${appdomain}" ]]; then 669 | read -p "Enter the domain name on which you want your app to be served (eg. example.com or test.example.com):" appdomain 670 | else 671 | appdomain=${2:-${appdomain}} 672 | fi 673 | 674 | # Get app Git repository URL from parameter or ask user for it (copy and paste all stuffs from "if" to "fi" in your terminal) 675 | if [[ -z ${3} ]] && [[ -z "${apprepositoryurl}" ]]; then 676 | read -p "Enter the Git repository URL of your app:" apprepositoryurl 677 | else 678 | apprepositoryurl=${3:-${apprepositoryurl}} 679 | fi 680 | ``` 681 | 682 | ### Download our app 683 | 684 | [Back to top ↑](#table-of-contents) 685 | 686 | Ubuntu 18.04 Server: 687 | 688 | ```bash 689 | # Clone app repository 690 | git clone ${apprepositoryurl} /var/www/${appname} 691 | 692 | # Go inside the app directory 693 | cd /var/www/${appname} 694 | ``` 695 | 696 | ### Set up the database and the production mode 697 | 698 | [Back to top ↑](#table-of-contents) 699 | 700 | Ubuntu 18.04 Server: 701 | 702 | ```bash 703 | # Generate a random password for the new mysql user 704 | mysqlpassword=$(openssl rand -hex 15) 705 | 706 | # Create database and related user for the app and grant permissions (copy and paste all stuffs from "sudo mysql" to "EOF" in your terminal) 707 | sudo mysql < ./.env.local.tmp 718 | mv ./.env.local.tmp ./.env.local 719 | 720 | # Set mysql credentials 721 | sed -e 's,DATABASE_URL=mysql://db_user:db_password@127.0.0.1:3306/db_name,DATABASE_URL=mysql://'${appname}':'${mysqlpassword}'@127.0.0.1:3306/'${appname}',g' ./.env.local > ./.env.local.tmp 722 | mv ./.env.local.tmp ./.env.local 723 | ``` 724 | 725 | ### Set permissions 726 | 727 | [Back to top ↑](#table-of-contents) 728 | 729 | Ubuntu 18.04 Server: 730 | 731 | ```bash 732 | # Set ownership to Apache 733 | sudo chown -R www-data:www-data /var/www/${appname} 734 | 735 | # Set files permissions to 644 736 | sudo find /var/www/${appname} -type f -exec chmod 644 {} \; 737 | 738 | # Set folders permissions to 755 739 | sudo find /var/www/${appname} -type d -exec chmod 755 {} \; 740 | ``` 741 | 742 | ### Install dependencies and build assets 743 | 744 | [Back to top ↑](#table-of-contents) 745 | 746 | Ubuntu 18.04 Server: 747 | 748 | ```bash 749 | # Install PHP dependencies 750 | composer install 751 | 752 | # Install JS dependencies 753 | yarn install 754 | 755 | # Build assets 756 | yarn build 757 | ``` 758 | 759 | ### Execute database migrations 760 | 761 | [Back to top ↑](#table-of-contents) 762 | 763 | ```bash 764 | # Execute database migrations 765 | php bin/console doctrine:migrations:diff 766 | php bin/console doctrine:migrations:migrate -n 767 | ``` 768 | 769 | ### Set up the web server 770 | 771 | [Back to top ↑](#table-of-contents) 772 | 773 | Ubuntu 18.04 Server: 774 | 775 | ```bash 776 | # Create an Apache conf file for the app (copy and paste all stuffs from "cat" to "EOF" in your terminal) 777 | cat > /etc/apache2/sites-available/${appname}.conf < 780 | # Set up server name 781 | ServerName ${appdomain} 782 | 783 | # Set up document root 784 | DocumentRoot /var/www/${appname}/public 785 | 786 | # Configure separate log files 787 | ErrorLog /var/log/apache2/error.${appname}.log 788 | CustomLog /var/log/apache2/access.${appname}.log combined 789 | 790 | EOF 791 | 792 | # Activate Apache conf 793 | sudo a2ensite ${appname}.conf 794 | 795 | # Restart Apache to make changes available 796 | sudo service apache2 restart 797 | ``` 798 | 799 | ### Enabling HTTPS & configure for Symfony 800 | 801 | [Back to top ↑](#table-of-contents) 802 | 803 | Ubuntu 18.04 Server: 804 | 805 | ```bash 806 | # Get a new HTTPS certficate 807 | sudo certbot certonly --webroot -w /var/www/${appname}/public -d ${appdomain} 808 | 809 | # Replace existing conf (copy and paste all stuffs from "cat" to last "EOF" in your terminal) 810 | cat > /etc/apache2/sites-available/${appname}.conf < 813 | # All we need to do here is redirect to HTTPS 814 | RewriteEngine on 815 | RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent] 816 | 817 | 818 | # Listen for the app domain on port 443 (HTTPS) 819 | 820 | # Set up server name 821 | ServerName ${appdomain} 822 | 823 | # Set up document root 824 | DocumentRoot /var/www/${appname}/public 825 | DirectoryIndex /index.php 826 | 827 | # Set up Symfony specific configuration 828 | 829 | AllowOverride None 830 | Order Allow,Deny 831 | Allow from All 832 | FallbackResource /index.php 833 | 834 | 835 | FallbackResource disabled 836 | 837 | 838 | # Configure separate log files 839 | ErrorLog /var/log/apache2/error.${appname}.log 840 | CustomLog /var/log/apache2/access.${appname}.log combined 841 | 842 | # Configure HTTPS 843 | SSLEngine on 844 | SSLCertificateFile /etc/letsencrypt/live/${appdomain}/fullchain.pem 845 | SSLCertificateKeyFile /etc/letsencrypt/live/${appdomain}/privkey.pem 846 | 847 | EOF 848 | 849 | # Restart Apache to make changes available 850 | sudo service apache2 restart 851 | ``` 852 | 853 | ## Manual configuration: deploy updates of an existing app 854 | 855 | [Back to top ↑](#table-of-contents) 856 | 857 | ### Set up variable 858 | 859 | Ubuntu 18.04 Server: 860 | 861 | ```bash 862 | # Get app name from parameter or ask user for it (copy and paste all code between "if" and "fi" in your terminal) 863 | if [[ -z ${1} ]] && [[ -z "${appname}" ]]; then 864 | read -p "Enter the name of your app without hyphens (eg. myawesomeapp):" appname 865 | else 866 | appname=${1:-${appname}} 867 | fi 868 | ``` 869 | 870 | ### Download updates of our app 871 | 872 | [Back to top ↑](#table-of-contents) 873 | 874 | Ubuntu 18.04 Server: 875 | 876 | ```bash 877 | # Go inside the app directory 878 | cd /var/www/${appname} 879 | 880 | # Pull the latest changes 881 | git pull 882 | ``` 883 | 884 | ### Update dependencies and rebuild assets 885 | 886 | [Back to top ↑](#table-of-contents) 887 | 888 | Ubuntu 18.04 Server: 889 | 890 | ```bash 891 | # Install PHP dependencies 892 | composer install 893 | 894 | # Install JS dependencies 895 | yarn install 896 | 897 | # Build assets 898 | yarn build 899 | ``` 900 | 901 | ### Update database structure & clear cache 902 | 903 | [Back to top ↑](#table-of-contents) 904 | 905 | Ubuntu 18.04 Server: 906 | 907 | ```bash 908 | # Execute database migrations 909 | php bin/console doctrine:migrations:diff 910 | php bin/console doctrine:migrations:migrate -n 911 | 912 | # Clear the cache 913 | php bin/console cache:clear 914 | ``` 915 | --------------------------------------------------------------------------------