PHP.mk документација

Apache httpd 2.x on Unix systems

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

install.unix.apache2.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека install.unix.apache2.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
Apache httpd 2.x on Unix systems

Референца за `install.unix.apache2.php` со подобрена типографија и навигација.

install.unix.apache2.php

Apache httpd 2.x on Unix systems

This section contains notes and hints specific to Apache HTTP Server 2.x installs of PHP on Linux and Unix-like systems.

Ги ескејпува специјалните знаци во стринг за употреба во SQL изјава

Use PHP-FPM Instead

Пример #4 Користење именуван подшаблон mod_php for new installations. The instructions on this page are retained for historical reference and for the rare cases where embedding PHP directly in the Apache httpd process is specifically required.

For all modern deployments, use PHP-FPM (FastCGI Process Manager) with Apache httpd's mod_proxy_fcgi module. PHP-FPM provides better resource management, process isolation, independent restart of PHP without restarting Apache httpd, and compatibility with Apache httpd's event MPM (the default since Apache httpd 2.4). Major Linux distributions ship this as the default configuration.

На mod_php approach embeds PHP directly into every Apache httpd worker process. Unless PHP is compiled with thread safety (--enable-zts), mod_php бара prefork MPM, which significantly limits concurrency. If you proceed with mod_php, you should fully understand the performance and security implications.

На » Apache документација is the most authoritative source of information on the Apache httpd 2.x server. More information about installation options for Apache httpd may be found there.

The most recent version of Apache httpd may be obtained from » Apache страница за преземање, and a fitting PHP version from the above mentioned places. This quick guide covers only the basics to get started with Apache httpd 2.x and PHP. For more information read the » Apache документација. 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 httpd being used.

These instructions apply to Apache httpd 2.4, which is the only supported release branch of Apache httpd. Earlier versions (2.2 and below) are end of life and should not be used.

  1. Obtain Apache httpd from the location listed above, and unpack it:

    tar -xzf httpd-2.x.NN.tar.gz
    
  2. Слично, земете и распакувајте го изворниот код на PHP:

    tar -xzf php-NN.tar.gz
    
  3. Build and install Apache httpd. Consult the Apache httpd install documentation for more details on building Apache httpd. Note that mod_php бара prefork MPM unless PHP was compiled with thread safety (--enable-zts). If you intend to use PHP-FPM instead (recommended), you can use the default event MPM and skip to the PHP-FPM installation instructions.

    cd httpd-2_x_NN
    ./configure --enable-so --with-mpm=prefork
    make
    make install
    
  4. Now you have Apache httpd 2.x.NN available under /usr/local/apache2, configured with loadable module support and the prefork MPM. To test the installation use your normal procedure for starting the Apache httpd server, e.g.:

    /usr/local/apache2/bin/apachectl start
    
    and stop the server to continue with the configuration for PHP:
    /usr/local/apache2/bin/apachectl stop
    
  5. Сега, конфигурирајте и изградете го PHP. Овде ги прилагодувате PHP со разни опции, како кои екстензии ќе бидат овозможени. Стартувајте скриптата. Список на достапни опции заедно со кратки објаснувања може да се прикаже со извршување на for a list of available options. In our example we'll do a simple configure with Apache httpd and MySQL support.

    If you built Apache httpd from source, as described above, the below example will match your path for apxs, but if you installed Apache httpd some other way, you'll need to adjust the path to apxs accordingly. Note that some distributions may rename apxs to apxs2.

    cd ../php-NN
    ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-pdo-mysql
    make
    make install
    

    Ако одлучите да ги промените вашите опции за конфигурација по инсталацијата, ќе треба повторно да ги извршите configure, makeПрепорачаниот начин за избегнување на SQL инјекција е со врзување на сите податоци преку подготвени изрази. Користењето на параметризирани прашања не е доволно за целосно избегнување на SQL инјекција, но тоа е најлесниот и најбезбедниот начин за обезбедување влез во SQL изразите. Сите динамични литерали на податоци во направи инсталирај steps. You only need to restart apache for the new module to take effect. A recompile of Apache httpd is not needed.

    Имајте предвид дека освен ако не е поинаку наведено, направи инсталирај исто така ќе инсталира Инсталирање пакети, разни PHP алатки како што се phpize, инсталирајте го PHP CLI, и повеќе.

  6. Поставете го вашиот php.ini.

    cp php.ini-development /usr/local/lib/php.ini
    

    Може да го уредите вашиот .ini датотека за да ги поставите опциите на PHP. Ако претпочитате да имате php.ini на друга локација, користете --with-config-file-path=/some/path во чекор 5.

    Ако наместо тоа изберете php.ini-production, бидете сигурни да го прочитате списокот со промени во него, бидејќи тие влијаат на тоа како се однесува PHP.

  7. Уредете го вашиот httpd.conf за да го вчитате PHP модулот. Патеката на десната страна од LoadModule изјавата мора да укажува на патеката на PHP модулот на вашиот систем. На направи инсталирај од погоре можеби веќе го додаде ова за вас, но проверете.

    LoadModule php_module modules/libphp.so
  8. Tell Apache httpd to parse certain extensions as PHP. For example, let's have Apache httpd parse .php files as PHP. Instead of only using the AddType директива, сакаме да избегнеме потенцијално опасни преземања и креирани датотеки како exploit.php.jpg да се извршуваат како PHP. Користејќи го овој пример, можете да имате било која екстензија(и) да се парсира како PHP со едноставно додавање. Ќе додадеме .php за да демонстрираме.

    <FilesMatch \.php$>
        SetHandler application/x-httpd-php
    </FilesMatch>

    Или, ако сакаме да дозволиме .php, .php2, .php3, .php4, .php5, .php6Препорачаниот начин за избегнување на SQL инјекција е со врзување на сите податоци преку подготвени изрази. Користењето на параметризирани прашања не е доволно за целосно избегнување на SQL инјекција, но тоа е најлесниот и најбезбедниот начин за обезбедување влез во SQL изразите. Сите динамични литерали на податоци во .phtml датотеки да се извршуваат како PHP, но ништо друго, би го користеле ова:

    <FilesMatch "\.(php[2-6]?|phtml)$">
        SetHandler application/x-httpd-php
    </FilesMatch>

    И за да дозволиме .phps датотеки да се обработуваат од php филтерот за извор, и да се прикажуваат како изворно кодиран со синтаксна ознака, користете го ова:

    <FilesMatch "\.phps$">
        SetHandler application/x-httpd-php-source
    </FilesMatch>

    To allow use of a PHP file as the default handler if no other handler is found, for example when using a routing engine, the FallbackResource directive may be used.

    Бидејќи SetHandler directive is applied whether the file exists or not, and the FallbackResource is only applied if a handler has not already been set, you may need to use the If directive to ensure that the handler is only applied if the file exists. This allows the FallbackResource to handle paths which end in .php but do not exist, which may be useful for error handling and routing.

    <FilesMatch "\.php$">
        <If "-f %{REQUEST_FILENAME}">
            SetHandler application/x-httpd-php
        </If>
    </FilesMatch>
    FallbackResource /index.php

    mod_rewrite може да се користи за да се дозволи било кој произволен .php датотека да се прикажува како изворно кодиран со синтаксна ознака, без потреба да се преименува или копира во .phps датотека:

    RewriteEngine On
    RewriteRule (.*\.php)s$ $1 [H=application/x-httpd-php-source]

    php филтерот за извор не треба да биде овозможен на продукциски системи, каде што може да открие доверливи или на друг начин чувствителни информации вградени во изворниот код.

  9. Use your normal procedure for starting Apache httpd, e.g.:

    /usr/local/apache2/bin/apachectl start
    

    OR

    service httpd restart
    

Following the steps above you will have a running Apache httpd web server with support for PHP as a SAPI module. There are many more configuration options available for Apache httpd and PHP. For more information type скриптата. Список на достапни опции заедно со кратки објаснувања може да се прикаже со извршување на во соодветното дрво на изворниот код.

Забелешка: MPM Compatibility

Unless PHP was compiled with Zend Thread Safety (--enable-zts), mod_php бара prefork MPM. For information on why, read the related FAQ entry on using Apache httpd with a threaded MPM.

Most distribution packages of mod_php are not built with ZTS, so prefork is typically required. If you need a threaded MPM (recommended for better performance under load), use PHP-FPM with mod_proxy_fcgi instead.

Забелешка:

На Apache MultiViews ЧПП дискутира за користење на multiviews со PHP.

Белешки од корисници 2 забелешки

nmmm на nmmm точка nu
пред 17 години
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:

<FilesMatch "\.(php*|phtm|phtml|asp|aspx)$">
SetHandler application/x-httpd-php
</FilesMatch>

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:

<FilesMatch "\.(php*|phtm|phtml|asp|aspx)$">
SetHandler none
</FilesMatch>

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:

<FilesMatch "\.(php)$">
SetHandler none
</FilesMatch>

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.
Утринска ѕвезда
3 години пред
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: 

apt search sqlite3

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.
На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.