====== Enable Per-Directory PHP in LSWS (Native) ====== It is possible to use different versions of PHP in different directories, but only with a LiteSpeed Web Server (native) installation. It is not applicable for control panel or Apache configuration modes. ===== Set Different PHP Per Virtual Host ===== When you use LSWS (native) without Apache configuration, you can define the PHP version through a PHP handler for each virtual host. To do so, you normally define multiple server-level external PHP apps, and then assign different handlers at the server level and virtual host level. If no virtual host level hander is defined, the virtual host will inherit the server-level PHP configuration. ====Example==== We set these external apps at the server level: ''lsphp54'', ''lsphp55'', ''lsphp56'', ''lsphp70'', ''lsphp71'', ''lsphp72''. {{ :litespeed_wiki:php:lsws-native-per-directory-php-1.png?800 |}} The configuration for the lsphp70 external app looks like this, and the rest are similar to it: {{ :litespeed_wiki:php:lsws-native-per-directory-php-external-apps-1.png?800 |}} At the server level, we define lsphp71 as the default handler to handle ''.php'' and ''.php5''. {{ :litespeed_wiki:php:lsws-native-per-directory-php-handlers-default-2.png?800 |}} The virtual host will inherit the above server default handler ''lsphp71'' unless overridden. Here we override the PHP version to ''lsphp56'' for that virtual host: {{ :litespeed_wiki:php:lsws-native-per-directory-php-handlers-vh-3.png?800 |}} ===== Set Different PHP Per Directory Within One Virtual Host ===== We saw how to set different PHPs for each virtual host, but if you would like to set different PHPs //within// a virtual host, there is some additional configuration. Most likely you'll want to do this on a per-directory basis, so in addition to the above steps, you will set more handlers at the server level under **Script Handler**, and then use ''.htaccess'' to change the PHP version. Add handlers to server level: in addition to the existing ''.php'' and ''.php5'' suffix, add ''.php54'', ''.php55'', ''.php56'', ''.php70'', ''.php71'', ''.php71'', and ''.php72''. {{ :litespeed_wiki:php:lsws-native-per-directory-php-handlers-2.png?800 |}} On virtual host DEFAULT, we have changed it to use ''lsphp56''. Under the sub directory ''/sub1/'', it will use lsphp56 as well. To change it to use different version lsphp72, ''vi sub1/.htaccess'' ForceType application/x-httpd-php72 You can also change it to use another PHP version by changing the last two digits. such as: ForceType application/x-httpd-php54 or ForceType application/x-httpd-php55 or ForceType application/x-httpd-php56 or ForceType application/x-httpd-php70 or ForceType application/x-httpd-php71 ===== Set Different php.ini Per Directory ===== The above instructions will set different PHP versions by using server-level-defined external apps, hence only the global ''php.ini'' is set for each version. To define a different ''php.ini'' per directory, you will set all server level external apps at the virtual host level with different names and add the ''PHPRC'' environment variable definition to ''php.ini'' for each version under that virtual host.