Changing default port of litespeed for a specific domain in whm

Dec 27, 2019
10
0
1
doubai
cPanel Access Level
Root Administrator
Hello friends
I have a WHM with Lightspeed and CloudLinux installed on it, with many domains that I want to change default apache port for a specific domain of them on whm and get ssl certificate on new port.

According bellow link:
PHP:
https://docs.cpanel.net/ea4/apache/modify-apache-virtual-hosts-with-include-files/?_ga=2.194081325.1691628398.1655314392-43255118.1653430806

I make an include file on below path:
PHP:
/etc/apache2/conf.d/userdata/ssl/2_4/user/domain/includename.conf


But i dont know what i have to write on it , i dont know the correct stracture as i got error when httprebuild with all of my test configuration on this file.

I use below configs:
PHP:
<VirtualHost 1.2.3.4:8788>
  ServerName test.site.com
    ServerAlias www.test.site.com
  DocumentRoot /home/user/public_html/test
  ServerAdmin [email protected]
  UseCanonicalName Off
</VirtualHost>


And i got below error:
PHP:
# /usr/local/cpanel/scripts/rebuildhttpdconf
Initial configuration generation failed with the following message:

The “/usr/sbin/httpd -DSSL -t -f /etc/apache2/conf/httpd.conf.work.370b5997.cfgcheck -C Include "/etc/apache2/conf.modules.d/*.conf"” command (process 87546) reported error number 1 when it ended.
Configuration problem detected on line 0 of file /etc/apache2/conf.d/userdata/std/2_4/user/test.site.com/test.conf:    Listen cannot occur within <VirtualHost> section


Rebuilding configuration without any local modifications.

Failed to generate a syntactically correct Apache configuration.
Bad configuration file located at /etc/apache2/conf/httpd.conf.work.370b5997
Error:
The “/usr/sbin/httpd -DSSL -t -f /etc/apache2/conf/httpd.conf.work.370b5997.cfgcheck -C Include "/etc/apache2/conf.modules.d/*.conf"” command (process 87548) reported error number 1 when it ended.
Configuration problem detected on line 0 of file /etc/apache2/conf.d/userdata/std/2_4/user/test.test.com/test.conf:    Listen cannot occur within <VirtualHost> section


Can anybody knows exact syntax for this file?!
 

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
11,127
1,755
363
cPanel Access Level
Root Administrator
Hey there! I don't think there will be a way to get this working on a cPanel server easily.

The first thing you'll need to do is to add a Listen directive to the /etc/apache2/conf.d/includes/pre_virtualhost_global.conf file. Apache needs this Listen directive in place so it listens on that port. All you need to place in that file is:

Code:
Listen 1234
where "1234" is the port number you want to use.

The next thing you'll need to do is ensure that port number is open in your server's firewall.

The problem is the virtualhost itself. Since the virtualhost already has the port as the first line, you can't alter it later in an include or else you'll get this error:

Code:
    Jun 15 14:05:50 host.hattmonkey.com restartsrv_httpd[961393]: AH00526: Syntax error on line 1 of /etc/apache2/conf.d/userdata/std/2_4/username/test.com/portchange.conf:
    Jun 15 14:05:50 host.hattmonkey.com restartsrv_httpd[961393]: <VirtualHost> cannot occur within <VirtualHost> section
The only option would be to edit the configuration directly, which isn't supported on a cPanel server.
 
Last edited:
  • Like
Reactions: aria_opensource