Manual Installation PHP5.3 und PHP5.4/en

Aus EUserv Wiki

(Unterschied zwischen Versionen)
Wechseln zu: Navigation, Suche
(Die Seite wurde neu angelegt: „{{Languages|Manual_Installation PHP5.3 und PHP5.4}} '''''Installation of PHP 5.3 and PHP 5.4 on a dedicated server''''' __TOC__ <div style= "font-size: 1.571em;"…“)
 
(Der Versionsvergleich bezieht 1 dazwischenliegende Version mit ein.)
Zeile 1: Zeile 1:
{{Languages|Manual_Installation PHP5.3 und PHP5.4}}
{{Languages|Manual_Installation PHP5.3 und PHP5.4}}
 +
[[Kategorie:Operation Systems and Software]]
'''''Installation of PHP 5.3 and PHP 5.4 on a dedicated server'''''
'''''Installation of PHP 5.3 and PHP 5.4 on a dedicated server'''''

Aktuelle Version vom 10:51, 25. Feb. 2013

Installation of PHP 5.3 and PHP 5.4 on a dedicated server

Inhaltsverzeichnis

Installation of PHP 5.3 and PHP 5.4 on a dedicated server

General

The appearance of PHP 5.4 revealed problems with some older PHP projects by unsupported features and other behaviors. This guide is provided for those who want to keep such projects up to date or to use PHP 5.3 parallel to PHP 5.4. without getting in trouble with any revealed problems. It shows, how to achieve this through the use of PHP starter scripts.

The advantages of fcgid
The main advantage of the use of fcgid is, next to the higher speed, the fact that scripts can be run with adjustable users. This provides security and administrative advantages. So for each user a separate 'php.ini' file can be used.

In this manual, the virtual host name www.mein.test is used. The operation system which is used is Debain 6 (Squeeze). The hostname must be assigned to its IP in the file /etc/hosts, too. The user/owner is web1 and the root directory is in /var/www/web1/web.

These settings differ from host to host and have to be replaced. All steps need root privileges. Therefore, it has been logged in as ROOT with the following command:

su

Preparing the web server

First the apache web server must be installed with the following command:

apt-get install apache2 apache2-suexec

Installation of PHP 5.3

The operation system Debian provides a PHP5 package with FastCGI for the user. PHP is now installed with the following commands:

apt-get install php5-cgi libapache2-mod-fcgid

Here PHP 5.3 is integrated as FastCGI into the web server.

If the Apache server was already installed with the PHP5 module, this module has to be deactivated with the following command:

a2dismod php5

Now, the following modules will be deactivated:

a2enmod rewrite
a2enmod suexec
a2enmod include
a2enmod fcgid

Additionally the file php.ini is customized with the following command:

nano /etc/php5/cgi/php.ini

The following line will be commented out:

cgi.fix_pathinfo=1

FCGI-configuration

Now the file fcgid.conf is customized. Under /etc/apache2/mods-available/fcgid.conf the file can be customized with the following command:

nano /etc/apache2/mods-available/fcgid.conf
<IfModule mod_fcgid.c>
AddHandler    fcgid-script .fcgi
FcgidConnectTimeout 20
PHP_Fix_Pathinfo_Enable 1         <------- add this line
</IfModule> 

Now the Apache server will be restarted:

/etc/init.d/apache2 restart

With the following commands, an user and a group will be named web1an will be added.

groupadd web1
useradd -s /bin/false -d /var/www/web1 -m -g web1 web1
 

Now a root directory will be created and an user will be added to this directory with the following commands:

mkdir -p /var/www/web1/web
chown web1:web1 /var/www/web1/web
 

Now, the following command is running:

/usr/lib/apache2/suexec -V

The following lines should be displayed in the command window:

-D AP_DOC_ROOT="/var/www"
-D AP_GID_MIN=100
-D AP_HTTPD_USER="www-data"
-D AP_LOG_EXEC="/var/log/apache2/suexec.log"
-D AP_SAFE_PATH="/usr/local/bin:/usr/bin:/bin"
-D AP_UID_MIN=100
-D AP_USERDIR_SUFFIX="public_html"
 

With the following command/var/www/hp-fcgi-scripts/, a file will be added in the directory web1, in which the FCGI script will be created:

 mkdir -p /var/www/php-fcgi-scripts/web1
 vi /var/www/php-fcgi-scripts/web1/php-fcgi-starter

In this script the following lines have to be inserted:

#!/bin/sh
PHPRC=/etc/php5/cgi/
export PHPRC
export PHP_FCGI_MAX_REQUESTS=5000
export PHP_FCGI_CHILDREN=8
exec /usr/lib/cgi-bin/php
 

With the following command, the write and read permissions for the script php-fcgi-starter will be set. The user web1 will be set as the owner of the file:

chmod 755 /var/www/php-fcgi-scripts/web1/php-fcgi-starter
chown -R web1:web1 /var/www/php-fcgi-scripts/web1
 

Now a virtual host is created with the following command:

vi /etc/apache2/sites-available/web1

In this host, the following lines are inserted:

<VirtualHost *:80>
  	ServerName www.mein.test
  	ServerAlias mein.test
  	ServerAdmin webmaster@mein.test
  	DocumentRoot /var/www/web1/web/

  		<IfModule mod_fcgid.c>
    			SuexecUserGroup web1 web1
    		<Directory /var/www/web1/web/>
      			Options +ExecCGI
      			AllowOverride All
      			AddHandler fcgid-script .php
      			FCGIWrapper /var/www/php-fcgi-scripts/web1/php-fcgi-starter .php
      			Order allow,deny
      			Allow from all
    		</Directory>
  		</IfModule>

  		ErrorLog /var/log/apache2/error.log
  		CustomLog /var/log/apache2/access.log combined
  		ServerSignature Off
</VirtualHost>
 

Here the FCGI wrapper refers to the FCGI starter script and uses this for files with the ending .php.

The virtual host is going to be activated with the following command:

a2ensite web1

For the changes to take effect, the Apache server has to be restarted:

/etc/init.d/apache2 reload

To test whether PHP is installed on the web server, the file info.php in the directory /var/www/web1/web/ is created:

vi /var/www/web1/web/info.php

In the file info.php the following lines are inserted:

<?php
  phpinfo();
?>
 

Now, the URL of the server (http://www.mein.test) can be opened with any browser. Then the site with the PHP information should be opened. Note:www.mein.test has to be disbanded in the file /etc/hosts .

Open it with:

vi /etc/hosts

and ad the following line:

192.168.0.1(your IP)   www.mein.test

Installation of PHP 5.4

Preparing

To compile PHP 5.4 for the module mod_fcgid you have to be sure, that all the required packages are installed. Use the following commands to install the required packages:

apt-get install libapache2-mod-fcgid apache2-suexec libpcre3-dev libpcre++-dev
libpng12-dev libbz2-dev libcurl4-openssl-dev libc-client2007e-dev 
libjpeg-dev libgif-dev libgif4 libpthread-stubs0 libpthread-stubs0-dev 
libx11-dev libxau-dev libxcb1-dev libxdmcp-dev libxpm-dev 
x11proto-core-dev x11proto-input-dev x11proto-kb-dev xtrans-dev 
libxml2-dev libmysqlclient-dev libfreetype6-dev
 

Now, the default upload limit for the FCGID module will be increased up to 100 MB. To do this the configuration file fcgid.conf must be opened with the following command:

vim /etc/apache2/mods-available/fcgid.conf

Here the following line needs to be added:

 
<IfModule mod_fcgid.c>
  AddHandler    fcgid-script .fcgi
  FcgidConnectTimeout 20
  PHP_Fix_Pathinfo_Enable 1
  FcgidMaxRequestLen 104857600  <---- add this line
</IfModule>
  

To install PHP5.4 the latest version has to be downloaded from a mirror server and needs to be unpacked:

cd /tmp
wget "http://de.php.net/get/php-5.4.8.tar.bz2/from/this/mirror" -O php.tar.bz2
apt-get install bzip2
tar xfvj php.tar.bz2
cd php-5.4.8
 

To check if a 32-bit or 64-bit system is installed, the following line has to be entered:

uname -a
 
Linux localhost.localdomain 2.6.32-279.14.1.el6.x86_64 #1 SMP Tue Nov 6 23:43:09 
UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
 
i386/i68632-bit system
amd64/x86_6464-bit system

In our case, the system is equipped with a 64-bit kernel. If there is i386 or i686 instead of amd64, a 32-bit system is installed.

Compiling of PHP 5.4 with mod_fcgid

If a 32-bit system is installed, the following compile-command has to be entered:

./configure --prefix=/usr/share/php54 --datadir=/usr/share/php54 --mandir=/usr/share/man 
--bindir=/usr/bin/php54 --with-libdir=lib --includedir=/usr/include/php54 
--sysconfdir=/etc/php54/apache2 --with-config-file-path=/etc/php54/apache2 
--with-config-file-scan-dir=/etc/php54/conf.d --enable-libxml --enable-session 
--with-pcre-regex=/usr --enable-xml --enable-simplexml --enable-filter --disable-debug 
--enable-inline-optimization --disable-rpath --disable-static --enable-shared --with-pic 
--with-gnu-ld --with-mysql --with-gd --with-jpeg-dir --with-png-dir --with-xpm-dir --enable-exif 
--with-zlib --with-bz2 --with-curl --with-ldap --with-mysqli --with-freetype-dir --enable-soap 
--enable-sockets --enable-calendar --enable-ftp --enable-mbstring --enable-gd-native-ttf 
--enable-bcmath --enable-zip --with-pear --with-openssl --with-imap --with-imap-ssl --with-kerberos 
--enable-phar --enable-pdo --with-pdo-mysql –with-mysqli
 

If a 64-bit system is installed, the following compile-command has to be entered:

./configure --prefix=/usr/share/php54 --datadir=/usr/share/php54 --mandir=/usr/share/man 
--bindir=/usr/bin/php54 --with-libdir=lib64 --includedir=/usr/include/php54 
--sysconfdir=/etc/php54/apache2 --with-config-file-path=/etc/php54/apache2 
--with-config-file-scan-dir=/etc/php54/conf.d --enable-libxml --enable-session 
--with-pcre-regex=/usr --enable-xml --enable-simplexml --enable-filter --disable-debug 
--enable-inline-optimization --disable-rpath --disable-static --enable-shared --with-pic 
--with-gnu-ld --with-mysql --with-gd --with-jpeg-dir --with-png-dir --with-xpm-dir --enable-exif 
--with-zlib --with-bz2 --with-curl --with-ldap --with-mysqli --with-freetype-dir --enable-soap 
--enable-sockets --enable-calendar --enable-ftp --enable-mbstring --enable-gd-native-ttf 
--enable-bcmath --enable-zip --with-pear --with-openssl --with-imap --with-imap-ssl --with-kerberos 
--enable-phar --enable-pdo --with-pdo-mysql --with-mysqli
 

For compiling, use the following command:

make

For testing, use the following command:

make test

For install, use the following command:

make install

The command make test is optional. It should be used before the installation to make sure, that PHP was compiled correctly.

The FastCGI-module mod_fcgid and suEXEC has to be activated with the following commands:

a2enmod fcgid
a2enmod suexec

Finally the Apache server will be restarted with the following command:

/etc/init.d/apache2 force-reload

Switch between PHP5.3 and PHP5.4

The PHP starter scripts for PHP5.3 and PHP5.4 has to be customized. The script /var/www/php-fcgi-scripts/web1/php-fcgi-starter has to be customized with the following lines:

vi /var/www/php-fcgi-scripts/web1/php-fcgi-starter
#!/bin/sh
PHPRC=/etc/php5/cgi/    
export PHPRC
export PHP_FCGI_MAX_REQUESTS=5000
export PHP_FCGI_CHILDREN=8
########naechste Zeile fuer php5.3##########
exec /usr/lib/cgi-bin/php

########naechste Zeile fuer php5.4##########
# exec /usr/bin/php54/php-cgi

 

The path after exec recalls to the relevant version of the PHP binary file. Here the comment before the desired version (in the example php5.3) is deleted and the Apache server is going to be restarted.

This guide can be taken for other virtual hosts, but each host has to create its own starter script, to run parallel with different PHP versions.