How to enable PHP short tags?

后端 未结 19 2480
清酒与你
清酒与你 2020-11-21 05:29

I have a web application on a Linux server which starts with

I needed to copy this application to a windows environment and everything is working

相关标签:
19条回答
  • 2020-11-21 05:52

    If you are using Ubuntu with Apache+php5, then on current versions there are 2 places where you need to change to short_open_tag = On

    1. /etc/php5/apache2/php.ini - this is for the pages loaded through your web server (Apache)
    2. /etc/php5/cli/php.ini - this configuration is used when you launch your php files from command line, like: php yourscript.php - that goes for manually or cronjob executed php files directly on the server.
    0 讨论(0)
  • 2020-11-21 05:55

    Set the asp_tags = On and short_open_tag = On in both the files \apache\Apache2.2.21\bin\php.ini and \bin\php\php5.3.8\php.ini and then restart the apache server.

    0 讨论(0)
  • 2020-11-21 05:56

    In CentOS 6(tested on Centos 7 too) you can't set short_open_tag in /etc/php.ini for php-fpm. You will have error:

    ERROR: [/etc/php.ini:159] unknown entry 'short_open_tag'
    ERROR: Unable to include /etc/php.ini from /etc/php-fpm.conf at line 159
    ERROR: failed to load configuration file '/etc/php-fpm.conf'
    ERROR: FPM initialization failed
    

    You must edit config for your site, which can found in /etc/php-fpm.d/www.conf And write at end of file:

    php_value[short_open_tag] =  On
    
    0 讨论(0)
  • 2020-11-21 05:58

    To set short tags to open from a Vagrant install script on Ubuntu:

    sed -i "s/short_open_tag = .*/short_open_tag = On/" /etc/php5/apache2/php.ini
    
    0 讨论(0)
  • 2020-11-21 06:00

    I can see all answers above are partially correct only. In reality all 21st Century PHP apps will have FastCGI Process Manager(php-fpm) so once you have added php-info() into your test.php script and checked the correct path for php.ini

    Go to php.ini and set short_open_tag = On
    

    IMPORTANT: then you must restart your php-fpm process so this can work!

    sudo service php-fpm restart
    

    and then finally restart your nginx/http server

    sudo service nginx restart
    
    0 讨论(0)
  • 2020-11-21 06:00
    ; Default Value: On
    ; Development Value: Off
    ; Production Value: Off
    ; http://php.net/short-open-tag
    ;short_open_tag=Off   <--Comment this out
    ; XAMPP for Linux is currently old fashioned
    short_open_tag = On   <--Uncomment this
    
    0 讨论(0)
提交回复
热议问题