I have a server, and I decided to update the OS, php was also updated from php5 to php7. In the web pages, I have includes to get layout info.
like this:
<html><body>
<?php include "scripts/sidebar.php";?>
</body></html>
(For example).
The php files individually work, but the web pages do not INCLUDE the files in the include statements. Formerly, this had been working. I have looked for errors in /var/log/nginx/error.log and /var/log/nginx/access.log, there are none.
There are also no errors in /var/log/php7.0-fpm.log
I tried changing the php.ini file variable "include_path" to point to the location of the scripts, (and reload nginx and php), but this had no effect.
I tried setting "allow_url_include = On" as described in the PHP documentation: http://php.net/manual/en/filesystem.configuration.php
After restarting php, and nginx, this seemed to have no effect.
What can I do to make the <?php include 'scripts/sidebar.php';?> function work?
if you can use like this.
include_once './test.php';
all files in same directory
You have not mentioned your file name from where you are including the php file, if your file extension is php then it will work.
Try to use
<?php include_once(dirname(__FILE__)."/scripts/sidebar.php"); ?>
Related
I'm using no template engine, but I have an index.php file, which requires my "index.tpl" file. So I can divide php and html code. In the index.tpl file I can use the php short-syntax and everything works fine... I have so say: worked. I had to reinstall my server (my SD-card of the PI was broken) and now this way doesn't work anymore. The php-code in the .tpl-files isn't executed anymore.
How do I have to configure my apache, that the code gets executed? Strangely I never had this problems in any installation before.
UPDATE:
I just tested: php code in .html-files doesn't work either.
Make sure that the PHP short opening tags <? ... ?> are enabled :
To achieve this, just set :
short_open_tag=On
In your php.ini file and then restart your Apache server.
Source
I am having trouble getting my PHP to work for my Apache server. I am running Oracle Linux, and used yum install php + yum install httpd to get my PHP and Apache. I have scoured the internet and done a couple of things:
Firstly, I have gone into my httpd.conf file and added LoadModule php5_module modules/libphp5.so. I have chosen to use the one in my php.conf file, which is the exact same one. Furthermore, I have done AddType application/x-http-php .php, so now my .php files are loading fine.
Secondly, I have tried to run my Apache server, and it works fine. It displays my index.html file, which I set with DirectoryIndex. However, when I tried to put php code into it, it got automatically commented out, which I assume is because I haven't set it to properly execute on the server side.
Now, with all that said, I am wondering what else I may be missing. I have two set-ups, one where I have a .php file, and one where the php is inline with the html.
index.html
<!DOCTYPE html>
<body>
<?php echo "Hello everybody."; ?>
</body>
</html>
index.php
<?php phpinfo(); ?>
The index.php file loads fine, but the index.html doesn't run the php code. How do I get the inlined version of php to work?
Note: I have set-up my Mac OS to work fine with .php files, but it is also having trouble with inline php within an Html file. What am I missing?
SOLUTION: Html files themselves cannot include php. Instead, the file must be a .php extension, and within a .php file, you can have text, html, and JavaScript.
I do not think .html files are run through php at all so the <? ... ?> is treated as a normal tag which is invisible.
Change the extension to .php.
Php can contain html.
Edit:
There exists an option to configure for example Apache to parse html files as if they are php if you for some reason cannot or do not want to use php endings.
This, in my opinion, is not a good solution as it hides the fact that the page is dynamic to a future maintainer.
There is a similar question which has a similar problem:
PHP code is not being executed, instead code shows on the page
You might want to check out points 2 to 5 in the accepted answer:
LoadModule (It seems, that you have configured that properly)
Set Apache to run PHP files (this is the third point, and it seems that
you didn't configure that). Add the following line to your httpd.conf file: AddType application/x-httpd-php .php
Make sure, that you have the file ending with the .php extension (after you have configured Apache to run PHP files, see the previous point)
Change your code to use the long PHP opening tag (<?php instead of just <?)
You need to set short_open_tag = On in your php.ini file
I'm trying to use a PHP include for the first time. I'm reasonably familiar with HTML, and new to PHP.
I've put the HTML for my header in a separate PHP file, and am trying to call it from http://www.kirtancentral.com/index-test.html. You can see I attempted it in a bunch of formats, I was of course hoping this one would do the trick:
<?php include("/home/danielctucker/kirtancentral.com/includes/header.php"); ?>
Not sure what I'm doing wrong!
You have to make your web server execute the PHP before any PHP embedded in a page will work. The fact you can see the PHP when you View Source shows that this is not happening.
Most servers (which have PHP installed and enabled) will only look in files with a .php file extension for PHP code (although this can be configured otherwise).
Try changing from index.html to index.php. If that doesn't work, then you need to install and enable PHP (if you control the server) or change your hosting pacakage.
You do not have PHP enabled on your server.
Install/enable PHP
Also it is good practice to use a relative path to your PHP script:
<?php include("includes/header.php"); ?>
Of course, this will only work when you have PHP enabled on your server.
Radhe-Shyam! :)
I took over a PHP project and I'm trying to get it running on my dev box. I'm a developer and not a sysadmin, so I'm having trouble getting it working.
The previous developer used .h files to include PHP. My current configuration is taking that .h file and including it without executing it. What do I need to look for in my apache config (or is it my php.ini)?
EDIT:
Something clicked when I read one of the comments below. The code is using ASP style tags "<?". I've turned the option on in php.ini and according to phpinfo(), it's enabled, but apache is still just including the code as text.
I just checked it and running the code with the full opening PHP tag "<?php" fixes the problem. Having said that, I'd still like it to work the other way.
I'm running the code on a Macbook with the latest versions available. PHP 5.2.6, postgresql 8.3 and apache 2.
The code works on the staging server, but I can't figure out what the difference it.
EDIT
Durrr...I didn't have short_open_tags enabled in php.ini.
Could the problem be that the .h file you are including just starts into php code without the opening "<?php" tag?
From include documentation:
When a file is included, parsing drops out of PHP mode and into HTML mode at the beginning of the target file, and resumes again at the end. For this reason, any code inside the target file which should be executed as PHP code must be enclosed within valid PHP start and end tags.
PHP is an interpreted language, so you can't 'include' a file without executing it. Remember that '.h' is just a file extension, so although the previous coder may have put PHP in a '.h' file, it's still just PHP.
More details on the problems you're running into would be helpful.
you can use a .htaccess file and add:
php_value auto_prepend_file /path/to/include-file.h
Edit
I've just read that .htaccess only works with the module version of php.
You should change them all to .php extensions. But, if you are going to leave them as .h, you change the mapping in Apache. It's Apache that runs the file through the proper interpreter, not PHP. The PHP engine will process anything passed to it.
include and require will execute the included file. If you are using readfile, it simply echoes the file without treating it as PHP code.
If the .h files are "missing" the <?php directive, then you may have to switch from include to something like:
eval( file_get_contents("file.h") );
Personally I try to avoid eval whenever I can, but sometimes there is just no choice.
I got my Xampp server running and can run my html in subdirectories now, as well (can't have spaces in the subdirectory names).
SSI Includes or PHP Includes:
Xampp says SSI is deactivated. Tried uncommenting the lines for includes, but it doesn't change the deactivation.
How do I activate SSI?
Then, how do I implement either SSI include statements or PHP include statements into my html to call up html files that include html, images, javascript and commands that call other javascript menu files?
I don't know if Xampp has a special way of activating SSI or not, but the normal Apache way should work.
The normal way to include files in SSI is
<!--#include virtual="/something/file.html" -->
where the url to the file is actually http://www.example.com/something/file.html .
PHP includes are pretty straightforward. Just name your file something.php and do this:
<?php include('path/to/file.php'); ?>
The file will be parsed by php so it can contain the standard mix of PHP/HTML tags or whatever other text you'd like.
If XAMPP says SSI are disabled by default, you need to edit your server configuration (not your .HTACCESS file) to change this. Otherwise, you could try installing a plugin for your server to fix the issue.
Hope this helps!
~ Nate.