PHP 7.2.7 Released

Instalação em sistemas Unix


Essa seção é um guia geral para configuração e instalação do PHP em sistemas Unix. Verifique se existe uma seção específica para usa plataforma ou servidor web antes de começar o processo.

Como nosso manual destaca na seção Considerações Gerais sobre Instalação, nós estamos lidando principalmente com configurações web do PHP nessa seção, embora cobriremos instalação do PHP para uso em linha de comando também.

Existem várias maneiras de instalar o PHP para a plataforma Unix, ou com um processo de compilar e configurar, ou atráves de vários métodos pré-empacotados. Essa documentação é focada principalmente no processo de compilação e configuração do PHP. Muitos sistemas baseados no Unix tem alguma forma de sistema de instalação de pacotes. Isso pode ajudar na instalação de uma configuração padrão, mas se você precisar ter uma série de características diferentes (como um servidor seguro, ou um driver de banco de dados diferente), você pode precisar montar o PHP e/ou servidor web. Se você não estiver familiarizado com o processo de montar e compilar seu próprio software, vale a pena checar se alguém já montou um pacote do PHP com as características que você precisa.

Pré-requisitos de software e de conhecimento para compilar:

  • Conhecimento básico de Unix (ser capaz de operar o "make" e um compilador C)
  • Um compilador ANSI C
  • flex: Versão 2.5.4
  • Quaisquer componentes específicos (como GD, PDF, etc.)

Quando compilando diretamente dos fontes Git ou depois de modificações você também precisará de:

  • autoconf: 2.13+ (para PHP < 5.4.0), 2.59+ (para PHP >= 5.4.0)
  • automake: 1.4+
  • libtool: 1.4.x+ (exceto 1.4.2)
  • re2c: 0.13.4 ou superior
  • flex: 2.5.4 (para PHP <= 5.2)
  • bison:
    • PHP 5.4: 1.28, 1.35, 1.75, 1.875, 2.0, 2.1, 2.2, 2.3, 2.4, 2.4.1, 2.4.2, 2.4.3, 2.5, 2.5.1, 2.6, 2.6.1, 2.6.2, 2.6.4
    • PHP 5.5: 2.4, 2.4.1, 2.4.2, 2.4.3, 2.5, 2.5.1, 2.6, 2.6.1, 2.6.2, 2.6.3, 2.6.4, 2.6.5, 2.7
    • PHP 5.6: 2.4 or later, excluding 3.0 only (3.0.1 and later are OK)
    • PHP 7.0: 2.4 or later

O processo inicial de configuração de instalação do PHP é controlado pelo uso de opções de linha de comando do script configure. Você pode pegar a lista de todas as opções disponíveis junto com uma pequena explicação executando o comando ./configure --help. Nosso manual documenta as diferentes opções separadamente. Você encontrará as opções principais no apêndice, enquanto as opções específicas das diferentes extensões são descritas nas páginas de referência.

Quando o PHP é configurado, você está pronto para montá-lo como módulo e/ou executável. O comando make deve tomar conta disso. Se ele falhar e você não conseguir descobrir a razão, veja a Seção de Problemas.

Nota: Compilação cruzada para ARM através do toolchain Android não é surportado.

add a note add a note

User Contributed Notes 10 notes

cj3 at clifjackson dot net
5 months ago
I recently ran in to a situation where I was building PHP 7.1.13 from source. Configuration & make went fine, however, when I ran make install it hung. It turns out that if you are building PHP with Apache (apxs) the make file calls apxs with the -a flag which tells it to modify the httpd.conf file. If, for whatever reason, the file is not writeable then it fails and you get the hang.

Line 108 in my Makefile looks like this:

INSTALL_IT = $(mkinstalldirs) '$(INSTALL_ROOT)/usr/lib64/httpd/modules' && $(mkinstalldirs) '$(INSTALL_ROOT)/etc/httpd/conf' && /usr/sbin/apxs -S LIBEXECDIR='$(INSTALL_ROOT)/usr/lib64/httpd/modules'      -S SYSCONFDIR='$(INSTALL_ROOT)/etc/httpd/conf' -i -a -n php7

I had to remove the -a flag and then it was fine.
Arjan van Bentem
11 years ago
When using Red Hat Fedora, beware of Security Enhanced Linux, SELinux.

Quoted from Red Hat: "The security goal is to make sure that Apache HTTP is only reading the static Web content, and not doing anything else such as writing to the content, connecting to database sockets, reading user home directories, etc."

These limitations include, among many other things, using mkdir to create directories, using fopen to access files, using fopen or get_headers to read URLs, or using exec to run external applications that happen to use sockets (or maybe access some files, but which will run fine when executed from the command line as Unix user apache or httpd -- such as HylaFAX "faxstat" as invoked from nweb2fax recvq.php and sendq.php).

See /var/log/messages for any denials due to the SELinux policy. To disable it:

- System, Administration, Security Level and Firewall
- open the SELinux tab
- click the Transition tree
- check Disable SELinux protection for Apache HTTP
- execute /etc/init.d/httpd restart

See also and
packard_bell_nec at hotmail dot com
10 years ago
If you install PHP as an Apache module, you can consider the following. Instead of adding:

application/x-httpd-php    php
application/x-httpd-php-source    phps

into Apache mime.types, you can add:

AddType application/x-httpd-php    .php
AddType application/x-httpd-php-source    .phps

into Apache httpd.conf, OR you can add:

AddHandler application/x-httpd-php    .php
AddHandler application/x-httpd-php-source    .phps

into Apache httpd.conf. The last one is the preferred way of configuration, but it does not work in previous Apache versions.
marshalm at ebrd dot com
17 years ago
HP-UX 11.X PA-RISC installation with oracle (oci8). You need to install the HP-UX patch PHSS_22514 patch (updated, otherwise you will get errors with dlopen() and dlclose() not found during the apache integration stage.
roman4e at gmail dot com
7 years ago
Be careful when compiling on system used with apache2 worker MPM (inl. apache-itk). It will be always compiled with ZTS implicitly when you are using --with-apxs2 and no matter how --enable-maintainer-zts configure option is set
doug at NOSPAM dot techie dot net
15 years ago
Users compiling under some versions of Solaris/SunOS may encounter the following error.
   symbol ap_block_alarms: referenced symbol not found

To address this problem, add the following additional flag to the Apache build configure line:

So, adding this to the original instructions, you'd configure your Apache build like so:
   ./configure --prefix=/www --enable-module=so --enable-rule=SHARED_CORE

Alex at GrimMusic dot com
11 years ago
I am new to linux/apache/php (coming from server 2003/IIS/Asp.Net), so i was stumped as to why php/apache could only use static content. Also, it couldn't access some documents that you created somewhere else, and then dragged into the HTML directory.

After some research, i found the problem was the SELinux context of the files. It took me forever to find the Proper command to use to change that, as all the examples on the net were out dated using old commands:
# chcon "user_u:object_r:httpd_sys_content_t" /var/www/html -Rc

This will change the SELinux context of all the documents under the /var/www/html directory (which is the web directory under Fedora), to allow the httpd process to access them, and the '-Rc' flag will make the changes Recursive, and will output it's progress for each file that it sucessfully changes.
phpnet at puellae dot com
10 years ago
Further down in the links it talks about using the fPIC option in the compiler to fix the SElinux error.  I messed around with it and adding --with-pic to the configure will also allow the module to load.  I have not done more testing with it but apache at least starts.  If you have already compiled you will need to do a make clean before recompiling.
thansen at terra dot com dot br
14 years ago
The configure directives --with-apxs2 and --with-apxs2filter are not compatible one with other, even though the configure script will not complain about that. Each one affect the way Apache will call the php parser: If you choose the first one, you must use the traditional include:

AddType application/x-httpd-php php

at httpd.conf, to call the parser. If you use the --with-apxs2filter, the include will be:

<Files *.php>
        SetOutputFilter PHP
        SetInputFilter  PHP

, and php will be called as a filter to .php files.

If you use both together, you will get compilation errors (duplicate symbols while linking libphp4).
aryeh dot friedman at gmail dot com
10 years ago
For all multi-core processors (not just Sun as noted above) you need to add --enable-shared-core to the apache config
To Top