Skip to content

Instantly share code, notes, and snippets.

@nullx5
Last active May 25, 2025 00:43
Show Gist options
  • Save nullx5/b02dd9d7e019351dbdf81afe0beb3047 to your computer and use it in GitHub Desktop.
Save nullx5/b02dd9d7e019351dbdf81afe0beb3047 to your computer and use it in GitHub Desktop.

Compilar php manualmente y agregarlo a una instalacion de apache por repositorio APT

Desinstalar cualquier version instalada con apt o dara conflictos.


sudo apt update; sudo apt upgrade -y

sudo apt install -y build-essential autoconf bison re2c libxml2-dev \
  libsqlite3-dev libssl-dev libcurl4-openssl-dev libjpeg-dev libpng-dev \
  libwebp-dev libxpm-dev libzip-dev libonig-dev libreadline-dev \
  libtidy-dev libxslt1-dev libffi-dev pkg-config git perl apache2 apache2-dev


mkdir php-latest
cd php-latest

wget https://www.php.net/distributions/php-8.4.7.tar.gz
7z x php-8.3.21.tar.gz
cd php-8.3.21

sudo chmod u+x configure
sudo chmod u+x build/shtool

./configure --with-apxs2=/usr/bin/apxs \
  --enable-mbstring --with-curl --with-openssl --enable-soap \
  --enable-intl --with-zip --with-zlib --enable-bcmath --with-readline \
  --with-xsl --with-tidy --enable-pcntl --enable-opcache --with-mysqli \
  --with-pdo-mysql --enable-fpm --enable-zts 

make -j$(nproc)
make test
sudo make install


#Verificamos que se haya creado el módulo de php
ls /usr/lib/apache2/modules/libphp*.so

#verificamos que se haya Cargado el módulo php en Apache
sudo nvim /etc/apache2/mods-available/php.load
LoadModule php_module /usr/lib/apache2/modules/libphp.so

#copiamos el binario a /usr/bin
sudo cp /usr/local/bin/php /usr/bin/

#verificamos la ultima version
php --version

#habilitamos el modulo php en apache
sudo a2enmod php
a2query -m

#configuramos apache para que reconozca los archvios php
sudo nvim /etc/apache2/apache2.conf
<FilesMatch "\.php$">
    SetHandler application/x-httpd-php
</FilesMatch>

DirectoryIndex index.php

#agregamos la funcion phpinfo
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php

#reinciamos apache
sudo systemctl restart apache2

#verificamos que apache reconosza php
http://localhost/info.php



@nullx5
Copy link
Author

nullx5 commented May 12, 2025

sudo systemctl restart apache2

Apache is running a threaded MPM, but your PHP Module is not compiled to be threadsafe. You need to recompile PHP.

❌ ¿QUÉ SIGNIFICA ESTE ERROR?
Apache está usando un MPM (Multi-Processing Module) de tipo threaded (probablemente event), pero tu PHP compilado no es threadsafe (es decir, no fue compilado con --enable-maintainer-zts).

mod_php no es compatible con MPM threaded si no está compilado con ZTS (Zend Thread Safety).

SOLUCION

Recompilar PHP con soporte ZTS (hilos seguros)

./configure --enable-zts --with-apxs2=/usr/bin/apxs 

Recomendación moderna
En lugar de usar mod_php, se suele usar PHP-FPM (FastCGI), que es más rápido y no tiene este problema, y funciona bien con mpm_event.

@nullx5
Copy link
Author

nullx5 commented May 13, 2025

sudo make install

Installing PHP CLI binary:        /usr/local/bin/
Installing PHP CLI man page:      /usr/local/php/man/man1/
Installing PHP FPM binary:        /usr/local/sbin/
Installing PHP FPM defconfig:     /usr/local/etc/
Installing PHP FPM man page:      /usr/local/php/man/man8/
Installing PHP FPM status page:   /usr/local/php/php/fpm/
Installing phpdbg binary:         /usr/local/bin/
Installing phpdbg man page:       /usr/local/php/man/man1/
Installing PHP CGI binary:        /usr/local/bin/
Installing PHP CGI man page:      /usr/local/php/man/man1/
Installing build environment:     /usr/local/lib/php/build/
Installing header files:          /usr/local/include/php/
Installing helper programs:       /usr/local/bin/
  program: phpize
  program: php-config
Installing man pages:             /usr/local/php/man/man1/
  page: phpize.1
  page: php-config.1

@nullx5
Copy link
Author

nullx5 commented May 24, 2025

Script compilar-php.sh

#!/usr/bin/bash

#sudo chmod u+x compilar-php.sh
#sudo ./compilar-php.sh

sudo apt update; sudo apt upgrade -y

sudo apt autoremove --purge php -y
sudo apt autoremove --purge apache2 -y
sudo apt install p7zip-full -y

sudo apt install -y build-essential autoconf bison re2c libxml2-dev \
  libsqlite3-dev libssl-dev libcurl4-openssl-dev libjpeg-dev libpng-dev \
  libwebp-dev libxpm-dev libzip-dev libonig-dev libreadline-dev \
  libtidy-dev libxslt1-dev libffi-dev pkg-config git perl apache2 apache2-dev
  
  
mkdir php-latest
cd php-latest

wget https://www.php.net/distributions/php-8.4.7.tar.gz
7z x php-8.4.7.tar.gz
7z x php-8.4.7.tar
cd php-8.4.7

sudo chmod u+x configure
sudo chmod u+x build/shtool

./configure --with-apxs2=/usr/bin/apxs \
  --enable-mbstring --with-curl --with-openssl --enable-soap \
  --enable-intl --with-zip --with-zlib --enable-bcmath --with-readline \
  --with-xsl --with-tidy --enable-pcntl --enable-opcache --with-mysqli \
  --with-pdo-mysql --enable-fpm --enable-zts
  
make -j$(nproc)
make test
sudo make install

sudo cp /usr/local/bin/php /usr/bin/

sudo a2enmod php

echo -e '\n<FilesMatch "\\.php$">\n    SetHandler application/x-httpd-php\n</FilesMatch>\n\nDirectoryIndex index.php' | sudo tee -a /etc/apache2/apache2.conf > /dev/null

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php

sudo systemctl restart apache2
sudo systemctl status apache2

@nullx5
Copy link
Author

nullx5 commented May 24, 2025

sudo rm -rf /etc/apache2
sudo rm -rf /usr/lib/apache2/modules/libphp*.so
sudo rm -rf /usr/local/bin/php 
sudo rm -rf /usr/bin/php
sudo rm -rf /var/www/html/*
sudo rm -rf ~/php-latest
sudo apt autoremove --purge apache2 -y
sudo apt update; sudo apt upgrade -y

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment