PHP scripts missing <?php won't run - php

I've downloaded a module library for Yii in which every PHP file starts with this:
<?
...rather than:
<?php
On my local Apache server, these files get loaded as flat files, rather than as executable scripts, though the files are all modded as writable and executable. Is there a way to force these files to be run as PHP, or do I have to modify all the files (and there are probably a hundred of them).

You will have to enable short_php_tag from php.ini Or better change <? to <?php in your file.
Tells PHP whether the short form () of PHP's open tag should be
allowed. If you want to use PHP in combination with XML, you can
disable this option in order to use inline. Otherwise, you
can print it with PHP, for example: '; ?>'. Also, if disabled, you must use the long form of
the PHP open tag ().

You need to activate the
short_open_tag
in the php.ini from "Off" to "On".
Dont forget to reload/restart the apache

you can add a .htaccess file with the following line to make it work:
php_value short_tags on

Related

Embed a PHP file into INI

I'd like to insert a line, similar to include('path to php file.php'), into php.ini.
Actually I already found this solution from the Internet, however I don't remember which parameter is used in php.ini in this case.
For what: I want to execute a short code (written by php) before every php script from my web server.
If I understand you correctly, you're looking to run a PHP script before all files on your server? If so, the auto-prepend-file directive in php.ini configuration is perfect for this. From the help docs:
Specifies the name of a file that is automatically parsed before the
main file. The file is included as if it was called with the require
function, so include_path is used.
The special value none disables auto-prepending.
Sample Code:
# Inside either main php.ini or child file
auto_prepend_file=/path/to/your/global/php/file.php
Note that PHP also gives the ability to append a file after every script interpretation as well. There is also a previous SO entry for this with additional information. HTH.
You must be searching for auto_prepend_file or auto_append_file, i.e.:
auto_prepend_file string
Specifies the name of a file that is automatically parsed before the
main file. The file is included as if it was called with the require
function, so include_path is used.
auto_append_file string
Specifies the name of a file that is automatically parsed after the
main file. The file is included as if it was called with the require
function, so include_path is used.
Usage php.ini:
auto_prepend_file="/path/to/prepend.php"
auto_append_file="/path/to/append.php"

How to load an extention in php's built-in server?

In the PHPs built-in server, I can see there are two php.ini-development and php.ini-production files, now, since I am trying to enable curl I un-commented both files and restarted the server, but everytime I need to use curl, php says, curl extention is not loaded, even with I checked even with extension_loaded() method, it seems like PHP is not reading from the ini files, or both files are not the real ini config file, and whenever I do something like dl('php_curl.dll') it says, undefined function dl() because, I guess dl is deprecated, so I am looking to find out the problem, if the ini files are not the one's I am checking or how to load this extention and where
Use php.ini, not php.ini-something_else. You can check which php.ini is being used by creating a page with this line:
<?php phpinfo(); ?>
and viewing it in your web browser.
Those 2 files are just examples and never loaded. You are supposed to copy either of those files to php.ini.

How to enable the directive "short_open_tag" via the. Htaccess Apache [PHP 5.3]

I am currently using PHP 5.3.8 and I can not access it with php.ini.
I absolutely must enable the PHP directive "short_open_tag" to On it because I work with a great CMS that uses only the <? ?>.
I tried to enable it with my Apache .htaccess (php_value short_open_tag 1), but adding this causes Apache to always issue 500 errors.
N.B. My server works with PHP in CGI mode.
If PHP is running as a CGI, then you cannot use a .htaccess file to set PHP flags, this only works if PHP is an Apache module.
You can use ini_set to set this flag from a PHP script, but this won't help you since ini_set only affects the currently running PHP process and doesn't persist.
Your only option may be to request your host enable short tags in php.ini, or edit each PHP file to replace <? with <?php
You should be able to use...
ini_set('short_open_tag', '1');
According to the documentation (PHP_INI_ALL).
Hopefully this great CMS has a front controller where you can replace the first <? with <?php, and then use ini_set().

How do I include a php.ini file in another php.ini file?

How do I include a php.ini file in another php.ini file?
I don't think you can "include" .ini files from the main php.ini file.
One possible solution, though, might be to use this option on the configure line, when compiling PHP:
--with-config-file-scan-dir=PATH
Set the path where to scan for configuration files
If this option is used at compile-time, PHP will look for every .ini file in this directory, in addition to the "normal" php.ini file.
I suppose this is what is used by Ubuntu, for instance, which uses a different .ini file for each downloaded extension, instead of modifying php.ini.
The path to the php.ini file is being defined with this option, on the configure line:
--with-config-file-path=PATH
Set the path in which to look for php.ini [PREFIX/lib]
Still, it probably means you'll have to re-compile PHP -- which is not that hard, btw -- the hardest part being to get the dependencies you need.
And, here is a post on the internals# mailling-list that says the same thing as I do: config files and PHP_CONFIG_FILE_SCAN_DIR
One can also define the path in ~/.bashrc
export PHP_INI_SCAN_DIR=/usr/local/lib/php.d
I installed Memcached for php and wasn't sure how to make sure that its ini was included in my php.ini file, but as it turns out, it automatically is. You can validate what is being loaded by running php --ini.
php --ini
Configuration File (php.ini) Path: /opt/local/etc/php5
Loaded Configuration File: (none)
Scan for additional .ini files in: /opt/local/var/db/php5
Additional .ini files parsed: /opt/local/var/db/php5/memcached.ini
EDIT: My answer was mistaken. This only works in .conf files, which is not the question asked. Better testing showed that it won't work in php.ini files, where include statement is ignored.
I just tested it on DebianĀ 9 (Stretch) with PHP-FPM. From some .conf file, use this syntax:
include=/path/to/special-php.ini
or even
include=/path/to/special-dir-full-of-conf-files/*.conf
as it is used in
/etc/php/7.0/fpm/php-fpm.conf
include=/etc/php/7.0/fpm/pool.d/*.conf
By the way, this will be most useful if you split your settings by topic, and or if you want a set for development and another one for production. Then you could do it the Debian/Apache style like
/etc/php/conf-available/
/etc/php/conf-enabled/
with symliks from the second to the other and an include to that one.
It seems you cannot include one ini file into another so it gets referenced and loaded. But you can set php up to load several files by telling it which folders to look into.
When using a FastCGI setup (possibly in FPM, too, though I don't know that for sure) you can export environment variables from within the PHP wrapper.
There you could do:
export PHP_INI_SCAN_DIR=/etc/php5/cgi/conf.d:/var/www/mydomain.net/etc
/var/www/mydomain.net/etc is just an example. It's the folder where you put your additional ini files into. It seems this can be a : separated list.
Use a phpinfo.php (file called arbitrarily containing only <?php phpinfo();), open the corresponding URL in your browser and check the list of directories that are parsed and the list of files that get loaded in the top area of it.
/etc/php5/cgi/conf.d should always be included (I guess because it was compiled into the PHP executable) and possibly not really be needed.
You can't. Read online pages:
The configuration file
SUMMARY: The configuration file
(php.ini) is read when PHP starts up.
For the server module versions of PHP,
this happens only once when the web
server is started. For the CGI and CLI
version, it happens on every
invocation.
.user.ini files
SUMMARY: In addition to the main
php.ini file, PHP scans for INI files
in each directory, starting with the
directory of the requested PHP file,
and working its way up to the current
document root (as set in
$_SERVER['DOCUMENT_ROOT']). Only INI
settings with the modes PHP_INI_PERDIR
and PHP_INI_USER will be recognized in
.user.ini-style INI files.
You could try to simulate it making use of the ini_set function. But as the "man page" indicates, not all ini options can be changed using ini_set. It's definitely a useful function, though.

Include problems in PHP

I need to turn allow_url_include On. How can I do this? I have access to .htaccess as well as php.ini.
I'm using PHP version 5.2.9
I've tried adding
php_value allow_url_include On
in .htaccess and
allow_url_include = On
in php.ini.
Both files are at the root of my website.
Is there a way to use the curl/get page function as a workaround?
Are you sure you're grabbing the right php.ini file?
If you're on a linux box, you might be grabbing the wrong one. I've seen that happen in the past. If you are indeed using Linux, open the terminal and type
which httpd
which php
Then you'll know if your pointing to the right locations.
Depending on what you are trying to use as a file to include you will need to enable both url_fopen and url_include.
The relevant php documentation entry is available here:
http://www.php.net/manual/en/filesystem.configuration.php

Categories