Página 1 de 1
Instalar varias versiones de PHP en un servidor Apache con Debian
Publicado: 14 Feb 2024, 13:55
por gbeltran
How to Install PHP on Debian 12, 11 or 10:
https://www.linuxcapable.com/how-to-ins ... ian-linux/
PHP is a go-to choice if you’re using Debian and looking to set up a dynamic website or web application. This guide will help you install PHP on Debian 12 Bookworm, Debian 11 Bullseye, or Debian 10 Buster. PHP is a server-side programming language that’s widely used for web development. It’s versatile, easy to integrate with databases, and has a strong community backing.
Probarlo (en mi Debian 12) y comentarlo.... FUNCIONA!
Probándolo en un servidor local apache en Ubuntu 20.04 (también funciona):
Pasos:
- Crear una página de PHP para mostrar en el servidor apache local (localhost/phpinfo.php):
Creamos el archivo con nao (por ejemplo:
- Contenido del archivo:
- Cambiamos permisos del archivo:
Lo movemos a la carpeta raíz de nuestro servidor apache, en este caso, html:
- Y ya podremos visualizarlo en esta URL:
http://localhost/phpinfo.php
Re: Instalar varias versiones de PHP en un servidor Apache con Debian
Publicado: 14 Feb 2024, 13:59
por gbeltran
Comprobar la versión de PHP instalada:
Ejemplo:
Código: Seleccionar todo
guillermo@equipo:~$ php -v
PHP 8.3.2-1+0~20240120.16+debian12~1.gbpb43448 (cli) (built: Jan 20 2024 14:14:39) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.2, Copyright (c) Zend Technologies
with Zend OPcache v8.3.2-1+0~20240120.16+debian12~1.gbpb43448, Copyright (c), by Zend Technologies
guillermo@equipo~$ ^C
Y los módulos PHP instalados:
NOTA IMPORTANTE: Solo me ha funcionado PHP en Apache tras este último paso (algo debo haber hecho ma al principio):
Luego he comprobado que me ha mantenido los cambios de la versión PHPH que he dejado por defecto (la 8.2.x). Tras crear el archivo phpinfo.info, darle permisos y ubicarlo en la ruta /var/www/html, ya me ha funcionado! Dejo captura de pantalla:
- phpinfo.jpg (97.71 KiB) Visto 595 veces
Re: Instalar varias versiones de PHP en un servidor Apache con Debian
Publicado: 14 Feb 2024, 14:03
por gbeltran
Cambiar entre versiones de PHP instaladas:
How to Switch between Multiple PHP Version on Debian 12/11/10:
https://tecadmin.net/switch-between-mul ... on-debian/
or Apache:-
Run the following command to disable Apache module for other PHP versions.
sudo a2dismod php7.4 php5.6
Now, enable PHP 8.2 module in Apache server.
sudo a2enmod php8.2
sudo service apache2 restart
For Command Line Interface:-
sudo update-alternatives --set php /usr/bin/php8.2
sudo update-alternatives --set phar /usr/bin/phar8.2
sudo update-alternatives --set phar.phar /usr/bin/phar.phar8.2
sudo update-alternatives --set phpize /usr/bin/phpize8.2
sudo update-alternatives --set php-config /usr/bin/php-config8.2
Note – The phpize8.2 and php-config8.2 command is available in php8.2-dev package. This is more useful for compiling PHP modules using pecl.
Me ha funcionado, aunque algunas alternativas daban error:
Código: Seleccionar todo
sudo a2dismod php8.3 php8.2
sudo a2enmod php8.2
sudo service apache2 restart
sudo update-alternatives --set php /usr/bin/php8.2
sudo update-alternatives --set phar /usr/bin/phar8.2
sudo update-alternatives --set phar.phar /usr/bin/phar.phar8.2
sudo update-alternatives --set phpize /usr/bin/phpize8.2
sudo update-alternatives --set php-config /usr/bin/php-config8.2
Código: Seleccionar todo
root@equipo:~# php -v
PHP 8.2.15 (cli) (built: Jan 20 2024 14:14:18) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.15, Copyright (c) Zend Technologies
with Zend OPcache v8.2.15, Copyright (c), by Zend Technologies
root@equipo:~#
Re: Instalar varias versiones de PHP en un servidor Apache con Debian
Publicado: 21 Feb 2024, 18:54
por gbeltran
Recordar tema permisos:
Código: Seleccionar todo
guillermo@guillermo-HP-ProOne-600-G2-21-5-in-Non-Touch-AiO:~$ sudo chmod -R 775 /var/www/html
guillermo@guillermo-HP-ProOne-600-G2-21-5-in-Non-Touch-AiO:~$ sudo chmod -R g+s /var/www/html
guillermo@guillermo-HP-ProOne-600-G2-21-5-in-Non-Touch-AiO:~$ systemctl restart apache2
Y ahora habilitamos el módulo de PHP (en mi caso la versión 7.4) para el servidor Apache:
Código: Seleccionar todo
guillermo@guillermo-HP-ProOne-600-G2-21-5-in-Non-Touch-AiO:~$ sudo a2enmod php7.4
Considering dependency mpm_prefork for php7.4:
Considering conflict mpm_event for mpm_prefork:
Considering conflict mpm_worker for mpm_prefork:
Module mpm_prefork already enabled
Considering conflict php5 for php7.4:
Enabling module php7.4.
To activate the new configuration, you need to run:
systemctl restart apache2
guillermo@guillermo-HP-ProOne-600-G2-21-5-in-Non-Touch-AiO:~$ systemctl restart apache2
guillermo@guillermo-HP-ProOne-600-G2-21-5-in-Non-Touch-AiO:~$
FUNCIONA!!