Announcement

Collapse
No announcement yet.

How to install EspoCRM on Amazon EC2 and https

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to install EspoCRM on Amazon EC2 and https

    I've been working on this for a while and I thought there may be others who want to know how to do this. I couldn't find any guides online specifically for EspoCRM and there were tons of issues along the way. This should get you running on EC2 with a fresh install of EspoCRM-4.5.0 using only https (all http requests will redirect to https).
    1. Login to AWS and go to the EC2 dashboard
    2. Start a new EC2 instance (there are plenty of guides for this, but here's what I did specifically for a test Espo installation)
      • I'm using 64-bit Amazon Linux AMI 2016.09.1 (HVM), SSD Volume Type. Select your AMI and hit next.
      • Select a machine size/type. I'm using a t2.nano for this.
      • I use all of the defaults on the next page (launch configuration details). Change this stuff to meet your needs.
      • The next page is storage. I bumped up the storage to 20 GB because I'm using this as a sandbox.
      • The following page allows you to add tags. I didn't do this, but it won't hurt anything if you do.
      • The last page is about security. You want to make sure you have the following rules:
        • ssh from <IP> (using 0.0.0.0 is fine, but it's not very secure)
        • http from 0.0.0.0
        • https: from 0.0.0.0
      • Click review and launch
      • Look over the settings and click launch. It will ask you to generate a new ssh key or use an existing one. I generated a new one for this and then saved it.
      • After the instance launches, go to the dashboard and look for the Public DNS (IPv4) value. If you want to use a more readable dns name, now is the time to add a CNAME entry to your zone file, e.g. "crm.mywebsite.com" with a value of "ec2-<some_ip_address>.compute-1.amazonaws.com".
    3. You should be able to ssh to the instance now with whichever DNS name you want to use. Make sure you use ec2-user as the username.
    4. Start the webserver installation/update process:
      • Update the OS: sudo yum update -y
      • Install Apache and PHP 7.0 + extensions: sudo yum install -y httpd24 php70 php70-mysqlnd php70-imap php70-mbstring php70-gd mod24_ssl php70-zip
      • Turn on apache: sudo service httpd start. The site should load the default Apache index.
      • Make sure Apache starts after a reboot: sudo chkconfig httpd on. Verify that run states 2-5 are on with chkconfig --list httpd
    5. ​​​​​​​Configure PHP
      • Edit php.ini: sudo vi /etc/php.ini
      • Change max_execution_time to 180
      • Change max_input_time to 180
      • Enable and change max_input_vars to 2000 (or whatever you want, but 1000 is a little low)
      • Change the memory limit to 256M
      • Change post_max_size to 20M
      • Change upload_max_filesize to 20M
    6. Setup SSL using letsencrypt/certbot
      • cd to your home directory if you aren't there anymore: cd
      • Download certbot: wget https://dl.eff.org/certbot-auto
      • Change the permissions of the file so it will execute: chmod a+x certbot-auto
      • Run/Install certbot: sudo ./certbot-auto certonly --standalone -d your.domain.com --debug
      • You should now have certificates in /etc/letsencrypt/live/your.domain.com
    7. Configure Apache
      • Make changes in httpd.conf: sudo vi /etc/httpd/conf/httpd.conf
        • Find the ServerName directive and change it to your.domain.com:80
        • Add the following lines below ServerName if you want your site to only serve https (all http requests will redirect to https):
          • RewriteEngine on
          • RewriteCond %{HTTPS} off
          • RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
        • Inside the <Directory "/var/www/html"> block, change AllowOverride None to AllowOverride All
      • Edit ssl.conf: sudo vi /etc/httpd/conf.d/ssl.conf
        • Uncomment: DocumentRoot "/var/www/html"
        • Uncomment and change: ServerName your.domain.com:443
        • Modify: SSLProtocol -All +TLSv1 +TLSv1.1 +TLSv1.2
        • Change: SSLCertificateFile /etc/letsencrypt/live/your.domain.com/cert.pem
        • Change: SSLCertificateKeyFile /etc/letsencrypt/live/your.domain.com/privkey.pem
        • Uncomment and change: SSLCertificateChainFile /etc/letsencrypt/live/your.domain.com/fullchain.pem ​​
      • Restart apache to make sure you didn't make any typos: sudo service httpd restart
    8. Set permissions for your user and the document root folder
      • Make a www group: sudo groupadd www
      • Add ec2-user to the www group: sudo usermod -a -G www ec2-user
      • Restart your shell and you should see www in your group list when you run groups
      • Change the owner of /var/www: sudo chown -R root:www /var/www
      • Change the permissions of /var/www: sudo chmod 2775 /var/www
    9. Upload EspoCRM and unzip it in the httpd document root
      • Upload EspoCRM.4.5.0.zip to /home/ec2-user
      • cd /var/www
      • sudo unzip ~ec2-user/EspoCRM-4.5.0.zip
      • The unzipped files should now be in /var/www/EspoCRM-4.5.0
      • Move the files to /var/www/html: sudo mv EspoCRM-4.5.0/* html/
      • Change the ownership of the files in /var/www/html: sudo chown -R apache:apache /var/www/html
      • Make index.php executable: sudo chmod g+x /var/www/html/index.php
    10. Restart httpd one more time (sudo service httpd restart) and try it out. Hopefully, the page will load with a green lock.
    11. Install EspoCRM using the wizard
    12. Add the cron entry
      • Make a new cron file for the root user: sudo crontab -e
      • Paste in the command: * * * * * cd /var/www/html; /usr/bin/php -f cron.php > /dev/null 2>&1
    Last edited by bandtank; 04-26-2017, 03:13 AM.

  • #2
    Here's some more info in case you want to use EC2 as a development machine. All of the instructions shown above apply up to section 9. Instead of unzipping a packaged version of the app, you'll need to clone either EspoCRM or your own git repo to ~ec2-user. Then sudo mv <dir>/* to /var/www/html.

    Now you have to install composer:
    1. sudo curl -sS https://getcomposer.org/installer | sudo php
    2. sudo mv composer.phar /usr/local/bin/composer
    3. sudo ln -s /usr/local/bin/composer /usr/bin/composer
    4. cd /var/www/html
    5. sudo composer install
    Unfortunately, there are several extensions missing, so that won't work, but it was good to try so you can see what happens. There are a few more things to install and build:
    1. sudo yum -y install php7-pear php70-devel gcc php70-ldap.x86_64 gcc-c++ make git
    2. sudo pear7 install pecl/mailparse
    3. sudo vi /etc/php-7.0.d/40-mail-parse.ini
      • ; Enable mailparse extension module
      • extension=mailparse.so
    4. cd
    5. git clone https://github.com/nodejs/node.git
    6. cd node
    7. git checkout <whichever version you want, e.g. v7.9.0>
    8. ./configure
    9. make
    10. sudo make install
    11. Check that node is installed correctly: npm --version
    12. sudo npm install -g npm
    13. sudo npm install -g grunt-cli
    14. sudo service httpd restart

    Now you should be able to:
    1. sudo composer install
    2. npm install
    3. grunt
    Last edited by bandtank; 04-26-2017, 04:12 AM.

    Comment

    Working...
    X