How to enable php apache2

How to enable php apache2

This section contains notes and hints specific to Apache 2.x installs of PHP on Unix systems.

We do not recommend using a threaded MPM in production with Apache 2. Use the prefork MPM, which is the default MPM with Apache 2.0 and 2.2. For information on why, read the related FAQ entry on using Apache2 with a threaded MPM

The » Apache Documentation is the most authoritative source of information on the Apache 2.x server. More information about installation options for Apache may be found there.

The most recent version of Apache HTTP Server may be obtained from » Apache download site, and a fitting PHP version from the above mentioned places. This quick guide covers only the basics to get started with Apache 2.x and PHP. For more information read the » Apache Documentation. The version numbers have been omitted here, to ensure the instructions are not incorrect. In the examples below, ‘NN’ should be replaced with the specific version of Apache being used.

There are currently two versions of Apache 2.x — there’s 2.4 and 2.2. While there are various reasons for choosing each, 2.4 is the current latest version, and the one that is recommended, if that option is available to you. However, the instructions here will work for either 2.4 or 2.2. Note that Apache httpd 2.2 is officially End Of Life, and no new development or patches are being issued for it.

Читайте также:  Php ini отключить функции

    Obtain the Apache HTTP server from the location listed above, and unpack it:

cd httpd-2_x_NN ./configure --enable-so make make install
/usr/local/apache2/bin/apachectl start
/usr/local/apache2/bin/apachectl stop
cd ../php-NN ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-pdo-mysql make make install
cp php.ini-development /usr/local/lib/php.ini
LoadModule php_module modules/libphp.so
LoadModule php7_module modules/libphp7.so
 SetHandler application/x-httpd-php 

Or, if we wanted to allow .php, .php2, .php3, .php4, .php5, .php6, and .phtml files to be executed as PHP, but nothing else, we’d use this:

 SetHandler application/x-httpd-php 

And to allow .phps files to be handled by the php source filter, and displayed as syntax-highlighted source code, use this:

 SetHandler application/x-httpd-php-source 

mod_rewrite may be used To allow any arbitrary .php file to be displayed as syntax-highlighted source code, without having to rename or copy it to a .phps file:

RewriteEngine On RewriteRule (.*\.php)s$ $1 [H=application/x-httpd-php-source]
/usr/local/apache2/bin/apachectl start

Following the steps above you will have a running Apache2 web server with support for PHP as a SAPI module. Of course there are many more configuration options available Apache and PHP. For more information type ./configure —help in the corresponding source tree.

Apache may be built multithreaded by selecting the worker MPM, rather than the standard prefork MPM, when Apache is built. This is done by adding the following option to the argument passed to ./configure, in step 3 above:

This should not be undertaken without being aware of the consequences of this decision, and having at least a fair understanding of the implications. The Apache documentation regarding » MPM-Modules discusses MPMs in a great deal more detail.

Note:

The Apache MultiViews FAQ discusses using multiviews with PHP.

Note:

To build a multithreaded version of Apache, the target system must support threads. In this case, PHP should also be built with Zend Thread Safety (ZTS). Under this configuration, not all extensions will be available. The recommended setup is to build Apache with the default prefork MPM-Module.

User Contributed Notes 16 notes

I had just installed php8.1.12 on a machine used for writing C code.

Below are some libraries that I needed to download on a debian-based OS.

apt-get install libpcre3 libpcre3-dev
apt-get install apache2-dev
apt-get install libxml2-dev
apt-get install libsqlite3-dev

These were the missing packages that I required.
If you get an error regarding a missing package or library, for example when I needed sqlite3, run the command:

And you’ll be able to see if there’s any dev or lib packages.

The apache2 instructions worked flawlessly at the time of php8.1.12; and in order to get certain requirements for an application, I had to run the php configure file like so:

./configure —with-apxs2=/usr/local/apache2/bin/apxs —with-pdo-mysql —with-mysqli —with-zip —enable-gd

The extra flags allowed me to use both types of mysql, allowed me to utilize PHP zip archiving, and allowed me to use Gnatt stuff.

When I upgrade to apache 2.2, this:

AddType application/x-httpd-php .php5
AddType application/x-httpd-php .php42
AddType application/x-httpd-php .php4
AddType application/x-httpd-php .php3
AddType application/x-httpd-php .php
AddType application/x-httpd-php .phtm
AddType application/x-httpd-php .phtml
AddType application/x-httpd-php .asp

. does not worked for me, so I did this:

Another interesting point with Apache 2.2 is following.
Let suppose we installed PHP as module. But for some directory, we need to use PHP as CGI (probably because of custom configuration). This can be done using:

AddType application/x-httpd-php-custom .php
Action application/x-httpd-php-custom /cgi-bin/php-huge

Note type must be different than «application/x-httpd-php» and also you need to deactivate the handler on sertain extention. You can do mixed configuration:

AddType application/x-httpd-php-custom .php
Action application/x-httpd-php-custom /cgi-bin/php-huge

in such case files like *.php5 and so on will be parsed via module, but *.php will go to php-huge executable.

Building php 7.1.3 with mysql 5.7.17 and httpd 2.4.25 on Debian 8, step 5 failed for me. Instead of

I’ve (painfully) discovered that installing PHP5 with «make install» under SuSe 9.2 is NOT a good idea.
http://www.aditus.nu/jpgraph/apache2suse.php
This page explains how to install it without breaking everything that’s php-related in the Apache2 configuration. Its first purpose, though, is to show how to have php 4 and 5 to cohabit properly.

I have successfully installed Apache 2.2.11 and PHP 5.2.8 under Red Hat 9.0 on a Pentium 166 with 32 MB of RAM.

While I used RH9, the worst possible case, these notes are probably good for RH-based distributions too (Red Hat Enterprise, Fedora, CentOS. )

If you want to install MySQL, it needs to be installed before PHP because PHP requires some libraries be available.

One think important when picking up a binary distribution of MySQL is to download all four packages: MySQL-server, MySQL-devel, MySQL-client and MySQL-shared. Note: The MySQL was bundled with PHP 4 but is not anymore in PHP 5.

Then you need to install Apache before PHP, because again PHP needs some libraries be available. I installed Apache 2 from source, using the very last version available, which is 2.2.11.

I installed PHP 5.2.8 from source. Here, I had a number of problems, but none which I could not resolve easily, some of them with a little help from different forums I found through Google.

Rembember: When it says you need a package named xyz and you notice there is also one named xyz-devel, grab it.

Most of the packages I got from:
http://legacy.redhat.com/pub/redhat/linux/9/en/os/i386/RedHat/RPMS/
A similar page exists for other versions of Red Hat
and:
http://rpmfind.net/
This site has an updated version of some of the packages. Make sure to use only the one labeled for you version (in my case, Red Hat 9.0) or it will not likely work.

You already have glibc and glibc-common installed, but you need to get glibc-devel and glibc-kernheaders. Make sure to match glibc’s version (rpm -q glibc). Note: When it says kernel-header is a required dependency, that’s glibc-kernheader (not kernel-source). You will also need binutils (no need to match the version), and gcc and cpp (version must match).

You need zlib-devel (zlib is probably already installed, match the version you have).

If you install the GD extension, the actual library is already bundled with PHP 5 (use that one, they have done some changes in there, so don’t upgrade), but you will need to install libpng and libpng-devel (match version, or disable in configure if you don’t want) and libjpeg (no -devel with that one).

You will also need libxml2. Now there were a problem, because PHP requires libxml2 be 2.6 or greater, but Red Hat only supplied 2.5.4-1 for RH9 (if you have a more recent distro, you might be more lucky). After looking for a while, I decided to grab the source code for the most recent distribution at the official website (http://xmlsoft.org/) and compiled.

Hope my post is useful to someone. Please, share your experience when compiling/installing for your particular platform and setup. Remember how hard it’s been for you the very first time. I confess, my very first server installation took me nearly a week and I was glad others helped me.

Источник

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 .

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.

Источник

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 

Источник

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