From HTTP to HTTPS (No loosing data) ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • skynext280
    Junior Member
    • Jun 2024
    • 11

    From HTTP to HTTPS (No loosing data) ?

    How to move espocrm From HTTP to HTTPS (with .crt .key .ca-bundle) ?

    When I installed espocrm I installed it with docker compose, without ssl, what happened is that in the project I was doing I realized that I had bought the domain and I was missing the SSL/TLS certificate and I introduced it to the project

    The first thing we have to do is have these 3 files
    Click image for larger version  Name:	image.png Views:	0 Size:	21.0 KB ID:	108769

    I bought the certificate from an external company but with lets encrypt these files can be generated, what you have to keep in mind that you have to renew them every 90 days.

    Delete all ur containers (dont worry your data is safe on the volumes that u create)

    PHP Code:
    docker rm -f $(docker ps -a -q) 
    
    Now bse sure that ur espocrm container is running on port 443:443

    (docker-compose.yml)

    PHP Code:
    espocrm:
        image: espocrm/espocrm
        container_name: espocrm
        environment:
          ESPOCRM_DATABASE_PLATFORM: Mysql
          ESPOCRM_DATABASE_HOST: mysql
          ESPOCRM_DATABASE_USER: xxxxxxxxxxxxxxxx
          ESPOCRM_DATABASE_PASSWORD: xxxxxxxxxxxxxxxx
          ESPOCRM_ADMIN_USERNAME: xxxxxxxxxxxxxxxx
          ESPOCRM_ADMIN_PASSWORD: xxxxxxxxxxxxxxxx
          ESPOCRM_SITE_URL: xxxxxxxxxxxxxxxx
        volumes:
          - espocrm:/var/www/html
        restart: always
        ports:
          - 443:443​ 
    

    Now execute


    PHP Code:
    docker compose up -d 
    

    Now let's list the containers that are working

    PHP Code:
    docker ps 
    
    Will se something like this

    Click image for larger version  Name:	image.png Views:	0 Size:	198.3 KB ID:	108770

    Now we will joun on the espocrm container so we need to use the container name and use this comand


    PHP Code:
    docker exec -it espocrm bash 
    

    In order to upload the certificates I am going to create a folder, you can create a folder where you want I use this


    PHP Code:
    mkdir /etc/ssl/server 
    

    Now we go to the folder that we just created and we are going to put the certificates using the command

    PHP Code:
    cat >> (YOUR DOMAIN).crt 
    
    We copy the content of the file from our system, press enter and CTRL + D.

    We do the same with the other 2 files, (YOUR DOMAIN).ca-bundle and (YOUR DOMAIN).net.key

    Now we go to the /etc/apache2/sites-enabled/ directory and we will edit the file called 000-default.conf

    We use the command cat >> 000-default.conf and write this

    PHP Code:
    <VirtualHost *:443>
    
        ServerAdmin webmaster@localhost
    
        DocumentRoot /var/www/html
    
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    
        SSLEngine on
    
        SSLCertificateFile /etc/ssl/server/j(YOUR DOMAIN).crt
        SSLCertificateKeyFile /etc/ssl/server/(YOUR DOMAIN).key
        SSLCertificateChainFile /etc/ssl/server/(YOUR DOMAIN).ca-bundle
    
        <FilesMatch "\.(?:cgi|shtml|phtml|php)$">
            SSLOptions +StdEnvVars
        </FilesMatch>
    
        <Directory /usr/lib/cgi-bin>
            SSLOptions +StdEnvVars
        </Directory>
    
    </VirtualHost>
    Now let's use the command

    PHP Code:
    a2enmod ssl 
    


    And finally

    PHP Code:
    service apache2 restart 
    


    and we would already have the certificates​ ?
Working...