|
| 1 | +# -*- mode: ruby -*- |
| 2 | +# vi: set ft=ruby : |
| 3 | + |
| 4 | +# Use this Vagrant configuration file for local installation of the Oro application. |
| 5 | +# Please, refer to the Oro Applications installation guides for the detailed instructions: |
| 6 | +# https://oroinc.com/b2b-ecommerce/doc/current/install-upgrade/one-step-automated-installation/vagrant |
| 7 | + |
| 8 | +# All Vagrant configuration is done below. The "2" in Vagrant.configure |
| 9 | +# configures the configuration version (we support older styles for |
| 10 | +# backwards compatibility). Please don't change it unless you know what |
| 11 | +# you're doing. |
| 12 | +Vagrant.configure("2") do |config| |
| 13 | + # The most common configuration options are documented and commented below. |
| 14 | + # For a complete reference, please see the online documentation at |
| 15 | + # https://docs.vagrantup.com. |
| 16 | + |
| 17 | + # Every Vagrant development environment requires a box. You can search for |
| 18 | + # boxes at https://vagrantcloud.com/search. |
| 19 | + config.vm.box = "centos/7" |
| 20 | + |
| 21 | + # Disable automatic box update checking. If you disable this, then |
| 22 | + # boxes will only be checked for updates when the user runs |
| 23 | + # `vagrant box outdated`. This is not recommended. |
| 24 | + # config.vm.box_check_update = false |
| 25 | + |
| 26 | + # Create a forwarded port mapping which allows access to a specific port |
| 27 | + # within the machine from a port on the host machine. In the example below, |
| 28 | + # accessing "localhost:8080" will access port 80 on the guest machine. |
| 29 | + # NOTE: This will enable public access to the opened port |
| 30 | + config.vm.network "forwarded_port", guest: 80, host: 8000 |
| 31 | + |
| 32 | + # Create a forwarded port mapping which allows access to a specific port |
| 33 | + # within the machine from a port on the host machine and only allow access |
| 34 | + # via 127.0.0.1 to disable public access |
| 35 | + # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1" |
| 36 | + |
| 37 | + # Create a private network, which allows host-only access to the machine |
| 38 | + # using a specific IP. |
| 39 | + config.vm.network "private_network", ip: "192.168.33.10" |
| 40 | + |
| 41 | + # Create a public network, which generally matched to bridged network. |
| 42 | + # Bridged networks make the machine appear as another physical device on |
| 43 | + # your network. |
| 44 | + # config.vm.network "public_network" |
| 45 | + |
| 46 | + # Share an additional folder to the guest VM. The first argument is |
| 47 | + # the path on the host to the actual folder. The second argument is |
| 48 | + # the path on the guest to mount the folder. And the optional third |
| 49 | + # argument is a set of non-required options. |
| 50 | + # config.vm.synced_folder "../data", "/vagrant_data" |
| 51 | + |
| 52 | + # Provider-specific configuration so you can fine-tune various |
| 53 | + # backing providers for Vagrant. These expose provider-specific options. |
| 54 | + # |
| 55 | + config.vm.provider "virtualbox" do |vb| |
| 56 | + # Display the VirtualBox GUI when booting the machine |
| 57 | + # vb.gui = true |
| 58 | + |
| 59 | + # Customize the amount of memory on the VM: |
| 60 | + vb.memory = 2048 |
| 61 | + vb.cpus = 2 |
| 62 | + end |
| 63 | + # |
| 64 | + # View the documentation for the provider you are using for more |
| 65 | + # information on available options. |
| 66 | + |
| 67 | + # Enable provisioning with a shell script. Additional provisioners such as |
| 68 | + # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the |
| 69 | + # documentation for more information about their specific syntax and use. |
| 70 | + config.vm.provision "shell", inline: <<-SHELL |
| 71 | +
|
| 72 | + echo "\n*****************************************************" |
| 73 | + echo "************* Provision process started *************" |
| 74 | + echo "*****************************************************\n" |
| 75 | +
|
| 76 | + # --------------------- Provision configuration --------------------- |
| 77 | + |
| 78 | + # --- VM settings --- |
| 79 | + |
| 80 | + FORWARDED_PORT=8000 |
| 81 | + |
| 82 | + # --- Database settings --- |
| 83 | +
|
| 84 | + DB_USER="dbuser" |
| 85 | + DB_PASSWORD="DBP@ssword123" |
| 86 | + DB_NAME="oro" |
| 87 | +
|
| 88 | + # --- Oro application settings --- |
| 89 | +
|
| 90 | + APP_HOST="localhost" |
| 91 | + APP_USER="admin" |
| 92 | + APP_PASSWORD="adminpass" |
| 93 | + APP_LOAD_DEMO_DATA="y" # y | n |
| 94 | +
|
| 95 | + echo "\n*******************************************************" |
| 96 | + echo "************** Step 1: Environment Setup **************" |
| 97 | + echo "*******************************************************\n" |
| 98 | +
|
| 99 | + echo "\n~~~~~~~~~~~~~~ Enable Required Package Repositories ~~~~~~~~~~~~~~\n" |
| 100 | + |
| 101 | + yum install -y epel-release |
| 102 | + yum update -y |
| 103 | +
|
| 104 | + echo "\n~~~~~~~~~~~~~~ Install Nginx, NodeJS, Git, Supervisor, and Wget ~~~~~~~~~~~~~~\n" |
| 105 | + |
| 106 | + yum install -y nginx wget git nodejs supervisor yum-utils |
| 107 | + |
| 108 | + echo "\n~~~~~~~~~~~~~~ Install MySQL ~~~~~~~~~~~~~~\n" |
| 109 | + |
| 110 | + wget https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm && rpm -ivh mysql80-community-release-el7-1.noarch.rpm |
| 111 | + yum-config-manager --disable mysql80-community |
| 112 | + yum-config-manager --enable mysql57-community |
| 113 | + |
| 114 | + yum install -y mysql-community-server |
| 115 | + |
| 116 | + echo "\n~~~~~~~~~~~~~~ Install PHP ~~~~~~~~~~~~~~\n" |
| 117 | + |
| 118 | + wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm && rpm -Uvh remi-release-7.rpm |
| 119 | + yum-config-manager --enable remi-php71 |
| 120 | + yum update -y |
| 121 | +
|
| 122 | + yum install -y php-fpm php-cli php-pdo php-mysqlnd php-xml php-soap php-gd php-mbstring php-zip php-intl php-mcrypt php-opcache |
| 123 | + |
| 124 | + echo "\n~~~~~~~~~~~~~~ Install Composer ~~~~~~~~~~~~~~\n" |
| 125 | + |
| 126 | + php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && php composer-setup.php |
| 127 | + php -r "unlink('composer-setup.php');" |
| 128 | + mv composer.phar /usr/bin/composer |
| 129 | + |
| 130 | + echo "\n~~~~~~~~~~~~~~ Enable Installed Services ~~~~~~~~~~~~~~\n" |
| 131 | +
|
| 132 | + systemctl start mysqld php-fpm nginx supervisord |
| 133 | + systemctl enable mysqld php-fpm nginx supervisord |
| 134 | +
|
| 135 | + echo "********************************************************************************" |
| 136 | + echo "************** Step 2: Pre-installation Environment Configuration **************" |
| 137 | + echo "********************************************************************************" |
| 138 | +
|
| 139 | + echo "\n~~~~~~~~~~~~~~ Perform Security Configuration ~~~~~~~~~~~~~~\n" |
| 140 | +
|
| 141 | + sed -i 's/SELINUX=enforcing/SELINUX=permissive/g' /etc/selinux/config |
| 142 | + setenforce permissive |
| 143 | +
|
| 144 | + echo "\n~~~~~~~~~~~~~~ Prepare MySQL Database ~~~~~~~~~~~~~~\n" |
| 145 | +
|
| 146 | + # --- Change the Default MySQL Password for Root User --- |
| 147 | +
|
| 148 | + MYSQL_INSTALLED_TMP_ROOT_PASSWORD=$(grep 'temporary password' /var/log/mysqld.log | awk '{print $NF}') |
| 149 | + mysqladmin --user=root --password=$MYSQL_INSTALLED_TMP_ROOT_PASSWORD password $DB_PASSWORD |
| 150 | +
|
| 151 | + # --- Create a Database for OroPlatform Community Edition Application and a Dedicated Database User --- |
| 152 | + |
| 153 | + mysql -uroot -p$DB_PASSWORD -e "CREATE DATABASE $DB_NAME" |
| 154 | + mysql -uroot -p$DB_PASSWORD -e "GRANT ALL PRIVILEGES ON $DB_NAME.* to '$DB_USER'@'localhost' identified by '$DB_PASSWORD'" |
| 155 | +
|
| 156 | + # --- Change the MySQL Server Configuration --- |
| 157 | +
|
| 158 | + echo "innodb_file_per_table = 0" >> /etc/my.cnf |
| 159 | + echo "wait_timeout = 28800" >> /etc/my.cnf |
| 160 | +
|
| 161 | + systemctl restart mysqld |
| 162 | +
|
| 163 | + echo "\n~~~~~~~~~~~~~~ Configure Web Server ~~~~~~~~~~~~~~\n" |
| 164 | +
|
| 165 | + cat > /etc/nginx/conf.d/default.conf <<____NGINXCONFIGTEMPLATE |
| 166 | +server { |
| 167 | + server_name $APP_HOST www.$APP_HOST; |
| 168 | + root /usr/share/nginx/html/oroapp/web; |
| 169 | +
|
| 170 | + index app.php; |
| 171 | +
|
| 172 | + gzip on; |
| 173 | + gzip_proxied any; |
| 174 | + gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; |
| 175 | + gzip_vary on; |
| 176 | +
|
| 177 | + location / { |
| 178 | + # try to serve file directly, fallback to app.php |
| 179 | + try_files \\$uri /app.php\\$is_args\\$args; |
| 180 | + } |
| 181 | +
|
| 182 | + location ~ ^/(app|app_dev|config|install)\\.php(/|$) { |
| 183 | + fastcgi_pass 127.0.0.1:9000; |
| 184 | + # or |
| 185 | + # fastcgi_pass unix:/var/run/php/php7-fpm.sock; |
| 186 | + fastcgi_split_path_info ^(.+\\.php)(/.*)$; |
| 187 | + include fastcgi_params; |
| 188 | + fastcgi_param SCRIPT_FILENAME \\$document_root\\$fastcgi_script_name; |
| 189 | + fastcgi_param HTTPS off; |
| 190 | + fastcgi_buffers 64 64k; |
| 191 | + fastcgi_buffer_size 128k; |
| 192 | + } |
| 193 | +
|
| 194 | + location ~* ^[^(\\.php)]+\\.(jpg|jpeg|gif|png|ico|css|pdf|ppt|txt|bmp|rtf|js)$ { |
| 195 | + access_log off; |
| 196 | + expires 1h; |
| 197 | + add_header Cache-Control public; |
| 198 | + } |
| 199 | +
|
| 200 | + error_log /var/log/nginx/${APP_HOST}_error.log; |
| 201 | + access_log /var/log/nginx/${APP_HOST}_access.log; |
| 202 | +} |
| 203 | +____NGINXCONFIGTEMPLATE |
| 204 | + |
| 205 | + systemctl restart nginx |
| 206 | +
|
| 207 | + echo "\n~~~~~~~~~~~~~~ Configure PHP ~~~~~~~~~~~~~~\n" |
| 208 | +
|
| 209 | + sed -i 's/user = apache/user = nginx/g' /etc/php-fpm.d/www.conf |
| 210 | + sed -i 's/group = apache/group = nginx/g' /etc/php-fpm.d/www.conf |
| 211 | + sed -i 's/;catch_workers_output/catch_workers_output/g' /etc/php-fpm.d/www.conf |
| 212 | +
|
| 213 | + sed -i 's/memory_limit = [0-9MG]*/memory_limit = 1G/g' /etc/php.ini |
| 214 | + sed -i 's/;realpath_cache_size = [0-9MGk]*/realpath_cache_size = 4M/g' /etc/php.ini |
| 215 | + sed -i 's/;realpath_cache_ttl = [0-9]*/realpath_cache_ttl = 600/g' /etc/php.ini |
| 216 | +
|
| 217 | + sed -i 's/opcache.enable=[0-1]/opcache.enable=1/g' /etc/php.d/10-opcache.ini |
| 218 | + sed -i 's/;opcache.enable_cli=[0-1]/opcache.enable_cli=0/g' /etc/php.d/10-opcache.ini |
| 219 | + sed -i 's/opcache.memory_consumption=[0-9]*/opcache.memory_consumption=512/g' /etc/php.d/10-opcache.ini |
| 220 | + sed -i 's/opcache.interned_strings_buffer=[0-9]*/opcache.interned_strings_buffer=32/g' /etc/php.d/10-opcache.ini |
| 221 | + sed -i 's/opcache.max_accelerated_files=[0-9]*/opcache.max_accelerated_files=32531/g' /etc/php.d/10-opcache.ini |
| 222 | + sed -i 's/;opcache.save_comments=[0-1]/opcache.save_comments=1/g' /etc/php.d/10-opcache.ini |
| 223 | + |
| 224 | + systemctl restart php-fpm |
| 225 | +
|
| 226 | + echo "********************************************************************************************" |
| 227 | + echo "************** Step 3: OroPlatform Community Edition Application Installation **************" |
| 228 | + echo "********************************************************************************************" |
| 229 | +
|
| 230 | + echo "\n~~~~~~~~~~~~~~ Get Application Source Code ~~~~~~~~~~~~~~\n" |
| 231 | +
|
| 232 | + # --- Copy application source code from the current host folder to the nginx web folder --- |
| 233 | +
|
| 234 | + cd /usr/share/nginx/html |
| 235 | + mkdir oroapp && cd oroapp |
| 236 | + cp -r /vagrant/* . |
| 237 | +
|
| 238 | + echo "\n~~~~~~~~~~~~~~ Install Application Dependencies ~~~~~~~~~~~~~~\n" |
| 239 | +
|
| 240 | + # --- Configure app/config/parameters.yml (to prevent composer interactive dialog) --- |
| 241 | + |
| 242 | + cp ./app/config/parameters.yml.dist ./app/config/parameters.yml |
| 243 | + sed -i "s/database_user:[ ]*root/database_user: $DB_USER/g" ./app/config/parameters.yml |
| 244 | + sed -i "s/database_password:[ ]*~/database_password: '$DB_PASSWORD'/g" ./app/config/parameters.yml |
| 245 | + sed -i "s/database_name:[ ]*[a-zA-Z0-9_]*/database_name: $DB_NAME/g" ./app/config/parameters.yml |
| 246 | + |
| 247 | + composer install --prefer-dist --no-dev |
| 248 | +
|
| 249 | + echo "\n~~~~~~~~~~~~~~ Install OroPlatform Community Edition Application ~~~~~~~~~~~~~~\n" |
| 250 | +
|
| 251 | + php ./app/console oro:install --env=prod --timeout=900 --no-debug --application-url="http://$APP_HOST/" --organization-name="Oro Inc" --user-name="$APP_USER" --user-email="[email protected]" --user-firstname="Bob" --user-lastname="Dylan" --user-password="$APP_PASSWORD" --sample-data=$APP_LOAD_DEMO_DATA |
| 252 | +
|
| 253 | + echo "\n~~~~~~~~~~~~~~ Add Required Permissions for the nginx User ~~~~~~~~~~~~~~\n" |
| 254 | +
|
| 255 | + setfacl -b -R ./ |
| 256 | + cd /usr/share/nginx/html/oroapp |
| 257 | + find . -type f -exec chmod 0644 {} \\; |
| 258 | + find . -type d -exec chmod 0755 {} \\; |
| 259 | + chown -R nginx:nginx ./app/{attachment,cache,import_export,logs} |
| 260 | + chown -R nginx:nginx ./web/{media,uploads,js} |
| 261 | +
|
| 262 | + echo "\n*********************************************************************************" |
| 263 | + echo "************** Step 4: Post-installation Environment Configuration **************" |
| 264 | + echo "*********************************************************************************\n" |
| 265 | +
|
| 266 | + echo "\n~~~~~~~~~~~~~~ Schedule Periodical Command Execution ~~~~~~~~~~~~~~\n" |
| 267 | +
|
| 268 | + echo "*/1 * * * * php /usr/share/nginx/html/oroapp/app/console oro:cron --env=prod > /dev/null" > /var/spool/cron/nginx |
| 269 | +
|
| 270 | + echo "\n~~~~~~~~~~~~~~ Configure and Run Required Background Processes ~~~~~~~~~~~~~~\n" |
| 271 | +
|
| 272 | + cat >> /etc/supervisord.conf <<____SUPERVISORDTEMPLATE |
| 273 | +[program:oro_web_socket] |
| 274 | +command=php ./app/console clank:server --env=prod |
| 275 | +numprocs=1 |
| 276 | +autostart=true |
| 277 | +autorestart=true |
| 278 | +directory=/usr/share/nginx/html/oroapp |
| 279 | +user=nginx |
| 280 | +redirect_stderr=true |
| 281 | +
|
| 282 | +[program:oro_message_consumer] |
| 283 | +command=php ./app/console oro:message-queue:consume --env=prod |
| 284 | +process_name=%(program_name)s_%(process_num)02d |
| 285 | +numprocs=5 |
| 286 | +autostart=true |
| 287 | +autorestart=true |
| 288 | +directory=/usr/share/nginx/html/oroapp |
| 289 | +user=nginx |
| 290 | +redirect_stderr=true |
| 291 | +____SUPERVISORDTEMPLATE |
| 292 | + |
| 293 | + systemctl restart supervisord |
| 294 | +
|
| 295 | + echo "\n**********************************************************************************************************************" |
| 296 | + echo "************** Congratulations! You’ve Successfully Installed OroCommerce Application **********************************" |
| 297 | + echo "**********************************************************************************************************************\n" |
| 298 | + echo "\n************** You should now be able to open the homepage http://$APP_HOST:$FORWARDED_PORT/ and use the application. **************\n" |
| 299 | + SHELL |
| 300 | +end |
| 301 | + |
0 commit comments