Celeb Glow
general | March 21, 2026

How to enable SSL for virtual host on Apache Server in Ubuntu 18.04 Machine

I am struggling from 3-4 days to create virtual host with different PHP version. I want the main website to run on PHP 7 (I used PHP 7.4) and a subdomain on PHP 5.6. The subdomain site is too old and does not support latest version of PHP.

However I have managed to install the both PHP versions(7.4 & 5.6) through fcgi method and able to configure to run two website in both version. I have checked the PHP info and it is working fine.

Now I am struggling to enable SSL for these website. I used the Cloudflare but problem is domain is not responding over https. After googling I have created another virtual host file in /etc/apache2/sites-available for the SSL and put the code like below. But does not work.

After I tried to install self signed certificate and used its certificate in virtual host file. This also does not work. I followed this doc for self signed certificate.

Note: Non-SSL URL is working fine. Issue is with SSL URL.

<IfModule mod_ssl.c> <VirtualHost _default_:443> ServerAdmin ServerName dev.example.com DocumentRoot /var/www/dev.example.com # DirectoryIndex index.php SSLEngine on # default SSL certificate # SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem # SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key # self signed certificate SSLCertificateFile /etc/ssl/certs/apache-selfsigned.crt SSLCertificateKeyFile /etc/ssl/private/apache-selfsigned.key <Directory "/var/www/dev.example.com"> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> <FilesMatch \.php$> # For Apache version 2.4.10 and above, use SetHandler to run PHP as a fastCGI process server SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost" </FilesMatch> ErrorLog ${APACHE_LOG_DIR}/dev.example.com_error.log CustomLog ${APACHE_LOG_DIR}/dev.example.com_access.log combined BrowserMatch "MSIE [2-6]" \ nokeepalive ssl-unclean-shutdown \ downgrade-1.0 force-response-1.0 </VirtualHost>
</IfModule>
12 Reset to default

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy