How to set Mod_Sed in cPanel

cPanelTristan

Quality Assurance Analyst
Staff member
Oct 2, 2010
7,607
40
248
somewhere over the rainbow
cPanel Access Level
Root Administrator
Hello Sergio,

In WHM > Software > EasyApache (Apache Update) > 5. Short Options List and selecting Mod Security, then choosing "Save and Build" in that area.

Otherwise, in root SSH running /scripts/easyapache and selecting Mod Security in the Short Options list, then again choosing "Save and Build" in command line.

Thanks!
 

Secmas

Well-Known Member
Feb 18, 2005
357
10
168
Hello Sergio,

In WHM > Software > EasyApache (Apache Update) > 5. Short Options List and selecting Mod Security, then choosing "Save and Build" in that area.

Otherwise, in root SSH running /scripts/easyapache and selecting Mod Security in the Short Options list, then again choosing "Save and Build" in command line.

Thanks!
Hello cPanelTristan,
do you mean that Mod_Sed is part of Mod Security and it is already installed if mod security is?
 

cPanelTristan

Quality Assurance Analyst
Staff member
Oct 2, 2010
7,607
40
248
somewhere over the rainbow
cPanel Access Level
Root Administrator
Sorry, it's early yet. I was reading it as Mod_Sec not Mod_Sed. I apologize for the erroneous information there. I'm trying to determine how precisely mod_sed would be installed. Please provide your OS version and architecture type:

Code:
uname -a
cat /etc/redhat-release
 

Secmas

Well-Known Member
Feb 18, 2005
357
10
168
Sorry, it's early yet. I was reading it as Mod_Sec not Mod_Sed. I apologize for the erroneous information there. I'm trying to determine how precisely mod_sed would be installed. Please provide your OS version and architecture type:

Code:
uname -a
cat /etc/redhat-release
# uname -a
Linux myserver.com 2.6.18-274.el5PAE #1 SMP Fri Jul 8 17:59:09 EDT 2011 i686 i686 i386 GNU/Linux
# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 5.7 (Tikanga)
#
 

cPanelTristan

Quality Assurance Analyst
Staff member
Oct 2, 2010
7,607
40
248
somewhere over the rainbow
cPanel Access Level
Root Administrator
All right, I got it to baseline install, although I don't know if it actually works:

Code:
cd /root
wget wget http://src.opensolaris.org/source/raw/webstack/apache-modules/sed/mod_sed.tar.gz
tar xzf mod_sed.tar.gz
cd mod_sed
apxs -c mod_sed.c sed0.c sed1.c regexp.c
apxs -i -a mod_sed.la
If you have any issues with the first apxs command, shorten it to "apxs -c mod_sed.c" initially, run the second apxs, then re-run the commands above after that. This will put the following LoadModule into /usr/local/apache/conf/httpd.conf file:

Code:
LoadModule sed_module         modules/mod_sed.so
At that point, I suggest removing the module from httpd.conf and putting it as an include with these steps:

Code:
echo "LoadModule sed_module modules/mod_sed.so" >> /usr/local/apache/conf/includes/pre_main_global.conf
cp /usr/local/apache/conf/httpd/conf /usr/local/apache/conf/httpd.conf.bak110818
/usr/local/cpanel/bin/apache_conf_distiller --update
/scripts/rebuildhttpdconf
/etc/init.d/httpd restart
Copy the mod_sed.so file to /root to save a copy of it, since future /scripts/easyapache recompiles will move the file out of /usr/local/apache/modules folder:

Code:
cp /usr/local/apache/modules/mod_sed.so /root
Now, before you run /scripts/easyapache in the future, create these files:

Code:
vi /scripts/preeasyapache
Place the following content into the file:

Code:
#!/bin/bash

sed -i 's/LoadModule sed_module/#LoadModule sed_module/g' /usr/local/apache/conf/includes/pre_main_global.conf
Next, create this file:

Code:
vi /scripts/posteasyapache
Place the following content into the file:

Code:
#!/bin/bash

cp /root/mod_sed.so /usr/local/apache/modules/
sed -i 's/#LoadModule sed_module/LoadModule sed_module/g' /usr/local/apache/conf/includes/pre_main_global.conf
/etc/init.d/httpd restart
The first script comments out the LoadModule in /usr/local/apache/conf/includes/pre_main_global.conf at the beginning of the Apache build. The second script copies mod_sed.so back into /usr/local/apache/modules folder, uncomments the LoadModule, and restarts Apache at the end of the build.

After saving these files, ensure they can execute:

Code:
chmod +x /scripts/preeasyapache
chmod +x /scripts/posteasyapache
 

Secmas

Well-Known Member
Feb 18, 2005
357
10
168
Thank you cPanelTristan,
wonderful job on the instructions. I still in doubt if that is not too risky to set in a production server and not know if it will work.

Any way I will try on the weekend just in case I do something wrong I will not affect anyone on the server.

Best Regards,

Sergio