In the next topic, the
question from
bondbig 'a was: “Tell us better how to write down two versions of php on one server (5.3 and 5.5, for example).” general concept.
suphp is a module for apache, which is called instead of mod_php and was originally designed to run apache from different users. This was designed to prevent an attacker from hacking into 1 site from gaining access to all sites on the server (after all, by default, apache runs from one user to all sites on the server). But it can be adapted to our tasks.
I will not compare suphp with mtm-itk, I will only say that the company in which I work uses suphp on virtual hosting servers (yes, I work in a hosting provider), it applies successfully and I have never had any complaints about this module.
')
I also want to note that if you take the server from CentOS 6, execute all the commands from this post and at the end everything will work as it should, then this does not mean that the server is ready for sale. You need to reset the server and do everything “by analogy, but fine,” and not in the same way.
So we need:
- Server
- apache
- At least 2 versions of php installed on the server
- mod_suphp
- Put it all together
1) Since I have an extra battle server, I will take a virtual machine, install Centos 6 minimal into it and enter the following into the console from the root:
yum -y update yum -y groupinstall "Development Tools" yum -y install epel-release yum -y install httpd-devel httpd php php-common php-gd php-xml php-mbstring libxml2-devel libapreq2 libapreq2-devel wget vim screen links
Thus, we will update the system, connect the
epel repository to it, install apache, php (5.3) and build tools from source codes.
2) Now we need to install the second version of php. As you might guess, I will do this from the source codes:
cd /usr/src/ wget http://ru2.php.net/get/php-5.6.2.tar.gz/from/this/mirror -O php.tar.gz tar xfz php.tar.gz cd php-5.6.2/ ./configure && make install
In my case, everything went well, and php 5.6 rose to / usr / local / bin /.
You do not need to collect everything yourself. You can use the package manager of the distribution kit, an alternative package manager (for example,
Nix ) or Orthodox to build a package. In any case, if you do it on a combat server, then at least you need to add options to ./configure.
3) Install suphp:
cd /usr/src/ wget http://www.suphp.org/download/suphp-0.7.2.tar.gz tar xfz suphp-0.7.2.tar.gz cd suphp-0.7.2 autoreconf -f -i ./configure --with-apr=/usr/bin/apr-1-config && make install
(Note as to the previous item).
4) We configure apache: we connect the module, we register Wirth. hosts \ folders, set the necessary variables (on whose behalf to run, which php versions to use).
httpd.conf cat > /etc/httpd/conf/httpd.conf << EOF ServerRoot "/etc/httpd" Listen 80 LoadModule authz_host_module modules/mod_authz_host.so LoadModule mime_magic_module modules/mod_mime_magic.so LoadModule headers_module modules/mod_headers.so LoadModule mime_module modules/mod_mime.so LoadModule dir_module modules/mod_dir.so LoadModule rewrite_module modules/mod_rewrite.so LoadModule suphp_module modules/mod_suphp.so suPHP_Engine on suPHP_AddHandler application/x-httpd-php5
5) Config suphp. It is worth paying attention to the handlers section, namely, it indicates the path to your interpreters and their "names". The rest is intuitive. More in the
documentation :
suphp.conf cat > /usr/local/etc/suphp.conf << EOF [global] logfile=/var/log/suphp.log loglevel=info webserver_user=apache docroot=/ errors_to_browser=false env_path="/bin:/usr/bin" umask=0022 min_uid=1 [handlers] application/x-httpd-php5="php:/usr/bin/php-cgi" application/x-httpd-php56="php:/usr/local/bin/php-cgi" EOF
6) Now, in accordance with all the above, we will create 2 test directories in which we will have different versions of php. Management through the .htaccess file, or rather the “AddHandler” directive in it:
Hidden text mkdir -p /var/www/html/53 && mkdir -p /var/www/html/56 && echo "<?php phpinfo(); ?>" > /var/www/html/53/index.php && echo "<?php phpinfo(); ?>" > /var/www/html/56/index.php && echo "AddHandler application/x-httpd-php5 .php" > /var/www/html/53/.htaccess && echo "AddHandler application/x-httpd-php56 .php" > /var/www/html/56/.htaccess && chown -R apache:apache /var/www/html
On this by and large everything. Restart apache, stop iptables (that we could enter the browser from our PC) and check that everything works.
service httpd restart service iptables stop links2 -dump http://localhost/53 | grep 'PHP Version' links2 -dump http://localhost/56 | grep 'PHP Version'
Once again, this is not a hautushka, but only a general concept of exemplary actions.