i've installed both version php in server, 5.6 , 7.0. can switch between versions, i'd set php version vhost. default version php 5.6. below example vhost:
<virtualhost *:80> servername example.com documentroot "/var/www phpinidir /etc/php/7.0/cli/ <directory "var/www"> allowoverride directoryindex index.php </directory> </virtualhost>.
phpinfo()
still displaying version 5.6, loaded configuration file php 7.0. im using debian 8.
first, there no way enable 2 different mod_php in apache, describe way configure php-fastcgi via mod_fcgid , suexec. assume install php7.0 dotteb.
first, need need install required packages:
# apt-get install libapache2-mod-fcgid php5-cgi php7.0-cgi apache2-suexec
then need enable required apache modules , disable not required:
# a2enmod suexec # a2dismod php5 # a2dismod php7.0
after create users , virtual hosts directories:
# useradd site1 -s /sbin/nologin -d /var/www/html/site1 -m # useradd site2 -s /sbin/nologin -d /var/www/html/site2 -m
php scripts executed these users. recommended own site data user , group.
then create php runners - cannot use /usr/bin/php5-cgi
, suexec forbid due security reasons: script runners should resides inside suexec document root, can shown running suexec -v
in line ap_doc_root
# /usr/lib/apache2/suexec -v -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"
also suexec check permission on script runner, place runner subdirectory cgi-bin (you can change name other, it's convention) of site owner home directory:
# mkdir -p /var/www/html/site1/cgi-bin /var/www/html/site2/cgi-bin
and create runner first site (with php5):
# cat <<-eof >/var/www/html/site1/cgi-bin/php #!/bin/sh exec /usr/lib/cgi-bin/php5 eof
you can specify additional environment parameters ( exporting environment variables such php_fcgi_max_requests
) php or specific php.ini
and second site (with php7):
# cat <<-eof >/var/www/html/site2/cgi-bin/php #!/bin/sh exec /usr/lib/cgi-bin/php7.0 eof
set executable flag on script runners:
# chmod 755 /var/www/html/site2/cgi-bin/php /var/www/html/site1/cgi-bin/php
document root , test scripts:
# mkdir -p /var/www/html/site1/data /var/www/html/site2/data # echo -e "<?php\nphpinfo();" > /var/www/html/site1/data/test.php # echo -e "<?php\nphpinfo();" > /var/www/html/site2/data/test.php
set ownership files in sites:
# chown -r site1:site1 /var/www/html/site1 # chown -r site2:site2 /var/www/html/site2
finally create virtual hosts both sites, first site1:
# cat <<eof > /etc/apache2/sites-available/site1.conf <virtualhost *:80> servername site1.example.com documentroot "/var/www/html/site1.data" <ifmodule mod_fcgid.c> suexecusergroup site1 site1 <directory /var/www/html/site1/data> options +execcgi allowoverride addhandler fcgid-script .php fcgiwrapper /var/www/html/site1/cgi-bin/php .php order allow,deny allow </directory> </ifmodule> </virtualhost> eof
and site2
# cat <<eof > /etc/apache2/sites-available/site2.conf <virtualhost *:80> servername site2.example.com documentroot "/var/www/html/site2/data" <ifmodule mod_fcgid.c> suexecusergroup site2 site2 <directory /var/www/html/site2/data> options +execcgi allowoverride addhandler fcgid-script .php fcgiwrapper /var/www/html/site2/cgi-bin/php .php order allow,deny allow </directory> </ifmodule> </virtualhost> eof
then enable sites a2ensite site1
, a2ensite site2
, , restart apache: systemctl restart apache2
. if ok - apache should restarted , can check hosts has different version of php via browser or curl curl -s -h 'host: site1.example.com' http://localhost/test.php
if going wrong, can check output of systemctl status apache
(in case if apache doesn't start), or /var/log/apache2/suexec.log
(in case if see 500 internal server error), or /var/log/apache2/error.log (in case generic error).
hope help
Comments
Post a Comment