compilar apache2 - compilar mod_wsgi - compilar modsecurity en ubuntu 24.04 .md
# Desisntalar versiones apt
sudo apt autoremove --purge apache2
sudo apt update
sudo apt install -y build-essential libpcre2-dev libxml2-dev libcurl4-openssl-dev libapr1-dev libaprutil1-dev python3-dev libtool automake git pkg-config libnghttp2-dev libssl-dev liblua5.3-dev python3-pip p7zip-full neovim
mkdir apache2-source
cd apache2-source
wget https://dlcdn.apache.org/httpd/httpd-2.4.64.tar.gz
7z x httpd-2.4.63.tar.gz
cd httpd-2.4.63
# Descargar dependencias integradas
mkdir srclib
cd srclib
wget https://dlcdn.apache.org//apr/apr-1.7.6.tar.gz
wget https://dlcdn.apache.org//apr/apr-util-1.6.3.tar.gz
7z x apr-1.7.6.tar.gz
7z x apr-util-1.6.3.tar.gz
mv apr-1.7.6 apr
mv apr-util-1.6.3 apr-util
cd ..
# Configurar Apache con muchas funciones activadas
./configure \
--prefix=/opt/apache2 \
--enable-so \
--enable-ssl \
--enable-proxy \
--enable-proxy-http \
--enable-http2 \
--enable-rewrite \
--enable-deflate \
--enable-expires \
--enable-headers \
--enable-mods-shared=all \
--with-included-apr \
--with-mpm=event
make -j$(nproc)
sudo make install
#!/bin/bash
set -e
echo "🔍 Verificando dependencias..."
sudo apt update
sudo apt install -y python3-dev libtool automake wget p7zip-full
echo "📦 Descargando mod_wsgi ..."
mkdir mod-wsgi-source
cd mod-wsgi-source
wget https://github.com/GrahamDumpleton/mod_wsgi/archive/refs/tags/5.0.2.tar.gz -O mod_wsgi.tar.gz
7z x mod_wsgi.tar.gz
cd mod_wsgi-5.0.2
echo "⚙️ Configurando con APXS=/opt/apache2/bin/apxs y Python=$(which python3)..."
./configure --with-apxs=/opt/apache2/bin/apxs --with-python=$(which python3)
echo "🔨 Compilando mod_wsgi..."
make -j$(nproc)
sudo make install
echo "✅ mod_wsgi instalado correctamente"
echo "LoadModule wsgi_module modules/mod_wsgi.so" | sudo tee -a /opt/apache2/conf/httpd.conf
echo "🚀 Reinicia Apache para aplicar los cambios:"
echo "sudo /opt/apache2/bin/apachectl -k restart"
configuracion minima httpd.conf
ServerRoot "/opt/apache2"
Listen 8080
LoadModule mpm_event_module modules/mod_mpm_event.so
LoadModule dir_module modules/mod_dir.so
LoadModule mime_module modules/mod_mime.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule security2_module modules/mod_security2.so
LoadModule wsgi_module modules/mod_wsgi.so
User www-data
Group www-data
ServerAdmin webmaster@localhost
DocumentRoot "/opt/apache2/htdocs"
<Directory "/opt/apache2/htdocs">
AllowOverride None
Require all granted
</Directory>
# Logging
ErrorLog logs/error.log
CustomLog logs/access.log combined
./httpd -V
sudo /opt/apache2/bin/apachectl start
sudo /opt/apache2/bin/apachectl stop
sudo /opt/apache2/bin/apachectl -k restart
/opt/apache2/bin/httpd -M | grep -E 'wsgi|security2'
#!/bin/bash
set -e
# Instalar dependencias
sudo apt update
sudo apt install -y \
g++ \
make \
automake \
autoconf \
libtool \
pkg-config \
libpcre2-dev \
libxml2-dev \
libcurl4-openssl-dev \
libgeoip-dev \
git \
doxygen \
yajl-tools \
libyajl-dev \
wget \
cmake \
zlib1g-dev \
liblmdb-dev \
libssl-dev
# Descargar y compilar ModSecurity v3.0.14
cd /tmp
wget https://github.com/owasp-modsecurity/ModSecurity/archive/refs/tags/v3.0.14.tar.gz -O ModSecurity-3.0.14.tar.gz
tar -xzf ModSecurity-3.0.14.tar.gz
cd ModSecurity-3.0.14
git submodule init
git submodule update
./build.sh
./configure
make -j$(nproc)
sudo make install
# Descargar y compilar el conector Apache
cd /tmp
git clone --depth 1 https://github.com/SpiderLabs/ModSecurity-apache
cd ModSecurity-apache
./autogen.sh
./configure --with-apxs=/opt/apache2/bin/apxs
make -j$(nproc)
sudo make install
# Agregar LoadModule si no existe
if ! grep -q "mod_security2.so" /opt/apache2/conf/httpd.conf; then
echo "LoadModule security2_module modules/mod_security2.so" | sudo tee -a /opt/apache2/conf/httpd.conf
fi
# Copiar archivo de configuración recomendado
sudo cp /tmp/ModSecurity-3.0.14/modsecurity.conf-recommended /opt/apache2/conf/modsecurity.conf
# Incluirlo en httpd.conf si no está
if ! grep -q "modsecurity.conf" /opt/apache2/conf/httpd.conf; then
echo "Include conf/modsecurity.conf" | sudo tee -a /opt/apache2/conf/httpd.conf
fi
echo "✅ ModSecurity y conector Apache instalados correctamente."
echo "🚀 Reinicia Apache con: sudo /opt/apache2/bin/apachectl -k restart"