Apache mod php enable

How do I enable PHP 7.3 in Apache2

php -v reports PHP 7.3.6-1+ubuntu18.04.1+deb.sury.org+1 (cli) (built: May 31 2019 11:06:48) ( NTS ) However, phpinfo(); reports PHP 7.2: PHP Version 7.2.17-0ubuntu0.18.04.1 What have I missed? Any guidance would be appreciated as I’m totally new to Ubuntu. Thanks

2 Answers 2

You have to disable the older version of PHP (a2dismod [oldversion]) and then enable the new version with

a2dismod php7.2 got rid of 7.2 and 7.3 appeared but ‘a2enmod php7.3’ failed, saying ERROR: Module php7.3 does not exist! . While that means I have a working 7.3 it looks like I have still messed up somewhere. How do I totally remove 7.2 (once I am happy 7.3 is fine)?

Be aware that you’ve got to get 7.3 working in apache, AND mysql (probably 5.7.27 as of this post) working in php 7.3 — so the php7.3-mysql package is very important. When you do phpinfo() from the browser, make sure it’s showing mysql support as well.

In my case I had to do the following

sudo add-apt-repository ppa:ondrej/php sudo apt-get install php7.3 php7.3-cli php7.3-mysql php7.3-gd php7.3-imagick php7.3-recode php7.3-tidy php7.3-xmlrpc php7.3-common php7.3-curl php7.3-mbstring php7.3-xml php7.3-bcmath php7.3-bz2 php7.3-intl php7.3-json php7.3-readline php7.3-zip sudo apt install libapache2-mod-php7.3 sudo a2enmod php7.3 

After install apache still used php7.0, so I had to remove 7.0 configs manually:

cd /etc/apache2/mods-enabled ls -la | grep php sudo rm php7.0.conf 
sudo service apache2 restart 

Источник

Installing PHP Module for Apache on Ubuntu

Apache Web Server is one of the more dominant web servers on the net. Most of those installations are running some form of PHP applications, whether Laravel, WordPress, or some other custom application.

Apache was originally used as a static web server, hosting HTML files, for example, directly the client. However, due to its support for modules the web servers capabilities have grown to run as an application server as well.

Out of the box, a default Apache2 web server installation on Ubuntu 18.04, 18.10, 19.04, and 19.10 will not run a PHP application. The PHP module is not included.

Читайте также:  METANIT.COM

This tutorial will show you how to configure an Apache web server for running PHP applications.

Installing Apache

To install Apache on your Ubuntu server, run the following command.

Installing PHP

Install PHP is simply enough. It can Ben installed using the Apt package manager from Ubuntu’s repositories.

PHP can also be installed from source, if you require a more recent version. That task, unfortunately, is outside of the scope of this tutorial.

To install PHP, run the following command:

Additional PHP modules can be installed with the language itself.

Install Apache PHP Module

The PHP module for Apache is not bundled with Apache. As such, it must be installed in addition to the Apache package.

sudo apt install libapache2-mod-php

Once installed the module will have to be enabled. We accomplish this using the a2enmod command.

Lastly, the Apache web service requires a reboot before the enabled mod will be loaded.

sudo systemctl restart apache2

Источник

Enable PHP in Apache2

Enable PHP in Apache2

  1. Enable PHP in Apache2 Using a2enmod
  2. Enable PHP in Apache2 With LoadModule
  3. Enable PHP in Apache2 by Creating a Symbolic Link

This article will teach you how to enable PHP in Apache2 using a2enmod , LoadModule , and a symbolic link. If you get a module error about PHP, we will teach you how apt-get can fix it.

Enable PHP in Apache2 Using a2enmod

To enable PHP with a2enmod , you will need to type the command:

Here, X.X is the current version of PHP.

  1. Open your terminal.
  2. Type sudo a2enmod php5 to enable PHP5.
  3. Type sudo service apache2 reload .

The last command will reload the Apache2 configuration. However, if you have other PHP versions like PHP7 or PHP8.1, you can use either the following to enable PHP:

sudo a2enmod php7 sudo a2enmod php8.1 

After each command, ensure you reload the Apache2 configuration using sudo service apache2 reload . Meanwhile, if you get an error that the PHP module does not exist, install the module for your current PHP.

The following will do that. Do not forget to replace X.X with your PHP version number.

apt-get install libapache2-mod-phpX.X 

Enable PHP in Apache2 With LoadModule

The LoadModule will allow you to add your PHP to the list of active modules. You can do this by setting the absolute path of your PHP module file in httpd.conf .

Читайте также:  Php открыть с помощью

The following is how you do it for PHP5.x, PHP7.x, and PHP8.x. The X is your PHP version number, and /path/to/mods-available/ is the directory of mods-available .

# For PHP5.x LoadModule php5_module /path/to/mods-available/libphpX.so  # For PHP7.x LoadModule php7_module /path/to/mods-available/libphpX.so  # For PHP8.x LoadModule php_module /path/to/mods-available/libphpX.so 

Enable PHP in Apache2 by Creating a Symbolic Link

With ln -s , you can create a symbolic link from the mods-available directory to mods-enabled . This allows you to use the PHP in the mods-enabled directory.

The following is how you create a symbolic link based on your PHP version. Replace path/to/mods-available/ and path/to/mods-enabled/ based on your system.

# For PHP5.x, PHP7.x, PHP8.x # X is your PHP version number ln -s /path/to/mods-available/libphpX.so /path/to/mods-enabled/libphpX.so 

Habdul Hazeez is a technical writer with amazing research skills. He can connect the dots, and make sense of data that are scattered across different media.

Источник

Активация PHP в Apache2

Это я так, предположил. Вообще невероятно, чтоб php на дебианподобном дистре не встал как влитой. Давай логи.

Просто формат .php в браузерах не открывается и неотображается а только скачивается, а в формате .html не читается. Знакомый посоветовал активировать php в apache2

В этом формате выводит : С этим можно что-то сделать

.haccess настрой. апач не считает твои пхпшки исполняемыми.

Тогда не очень умный вопрос : Как это сделать ?

В простейшем случае просто удали подобные файлы. Тогда апач будет запускать php из любого каталога.

Но это если ты тренируешься на локалхосте.

подобные файлы это .haccess ?

Ну да. Их читает апач для каждого каталога. Так не объяснищь, но считай что они регулируют его поведение. Что запускать и т.д. Типа локального конфига.

А что с локалхостом? Простоя я в нем как раз и пытаюсь работать

С локалхостом всё в порядке. А вот если бы ты настоящим серверком управлял. Лучше поизучай матчасть.

Просто хочу уже настроить все. Изучая php хочется попробовать сделать примеры, но не получается(((.А вообще где можно найти инфу про LAMP?

Говорят где-то есть места, где нет инфы про LAMP. Для того, чтобы туда попасть нужно обладать незаурядными способностями. Нужно целенаправленно игнорировать гугл, маны, info, справку по php, в конце концов.

Если ты всё поставил правильно, и если .htaccess не создавал, то проверь логи апача наконец-то.

Читайте также:  Php include html file header

но если все вышеперечисленные пакеты поставлены, то должен работать. Перезапустите и смотрите /var/log/*

В простейшем случае просто удали подобные файлы. Тогда апач будет запускать php из любого каталога.

ещё в конфиге апача надо прописать.

# Uncomment the following line to enable PHP: # Include /etc/httpd/mod_php.conf . # # mod_php - PHP Hypertext Preprocessor module # # Load the PHP module: LoadModule php5_module lib/httpd/modules/libphp5.so # Tell Apache to feed all *.php files through PHP. If you'd like to # parse PHP embedded in files with different extensions, comment out # these lines and see the example below. SetHandler application/x-httpd-php 

это в слаке, в дебе как-то типа того.

Глянь наличие файлов:
/etc/apache2/mods-enabled/php5.load
/etc/apache2/mods-enabled/php5.conf
Если нет в mods-enabled, посмотри в mods-available
Ну и покажи их содержимое.

Телепатия подсказывает, что ТС пытается открыть php файлы браузером.

php5.load: LoadModule php5_module /usr/lib/apache2/modules/libphp5.so

php5.conf: SetHandler application/x-httpd-php SetHandler application/x-httpd-php-source # To re-enable php in user directories comment the following lines # (from to .) Do NOT set it to On as it # prevents .htaccess files from disabling it. php_admin_value engine Off

Ну вроде все верно.
Если файл брал из mods-enabled, то должно работать. Вспоминай, что правил руками и откуда, может быть, копировал конфиги взамен дефолтных.

thesis ★★★★★ ( 17.11.13 02:47:46 MSK )
Последнее исправление: thesis 17.11.13 02:48:00 MSK (всего исправлений: 1)

0) Внимательно прочитай access.log и error.log твоего виртуалхоста, твоего сайта/php-фреймворка/самого php, возможно это натолкнет на какие-то мысли. Например, какая-нибудь строчка «не могу запустить интерпретатор php потому что. »

1) Удали нафиг всю директорию conf, все пакеты, которые ты поставил. Конфиги php и модулей посмотри где лежат и убей их все тоже.

2) Потом действуй строго по инструкции по установке LAMP на официальном сайте Ubuntu

Чтобы в будущем не натыкаться на такие грабли, имей хотя бы одну виртуалку Убунты (VirtualBox, VMWare). Всегда вначале делаешь снапшот, к которому можно вернуться при возникновении проблем. Потом накатываешь изменения и проверяешь, работают ли. И только потом проверяешь на компе для разработки. И только после проверки на девелоперском компе — накатываешь на тестовый и боевой сервера. Эта практика может показаться странной и геморройной, но пока что она — лучшая при выкате апдейтов серверов.

stevejobs ★★★★☆ ( 17.11.13 03:48:02 MSK )
Последнее исправление: stevejobs 17.11.13 03:49:52 MSK (всего исправлений: 1)

Источник

Оцените статью