Why are my .php files failing to be interpreted as php? - php

I have recently installed ubuntu 20.04 w/ apache2 on an Oracle VM running linux. I have followed the following guides line by line to set these up as well as php 8.1:
https://www.youtube.com/watch?v=YtH9D2SqBqA
https://www.digitalocean.com/community/tutorials/how-to-install-the-apache-web-server-on-ubuntu-22-04
I have an example file I am trying to test: my_ip/test.php where my_ip is the ip address of my virtual machine.
The code in test.php is:
<?php
$x =2;
$y =2;
echo ($x + $y);
echo "<h1>This is a test.</h1>";
?>
This is being displayed onscreen # my_ip/test.php:
This is a test."; ?>
My current interpretation is that this page is being parsed as an html file. I have done an hours worth of googling and tampering with config files but nothing worked, I ended up reverting all changes to config files so as not to prevent potential fixes provided here from working.
If it's relevant, I am accessing my linux vm server through putty.
On a side note, I have tried aliasing my server so that I can refer to it with a different address and not have to explicitly write my ip address but have failed. Can anyone point me in the direction of a guide that could help with this? I have tried following this guide line by line: https://www.digitalocean.com/community/tutorials/how-to-install-the-apache-web-server-on-ubuntu-22-04
however I am not able to successfully use http://your_domain. I simply get Server Not Found.
I tried following the aforementioned guides line by line, and was expecting my server's behavior to mimic that displayed in the guide's however my php files are not being executed properly. Also, I cannot refer to my server by its alias.

Resolution: Followed Ubuntu's PHP installation instructions for apache here https://assets.ubuntu.com/v1/2a3819f0-ubuntu-server-guide-2023-02-19.pdf
I believe I did NOT install the apache php module, despite installing php 8.1.
Running this command:
sudo apt install php libapache2-mod-php
resolved the issue and I am able to run php files now.

Related

PHP from source - Questions about Extension-Folder and Interaction with existing repo-version

As a Linux beginner I'm currently a bit confused building my own PHP from source.
I have a Ubuntu with a LAMP-Stack where all packages comes from a Repository.
(PHP as FastCGI)
Now I'm trying to set up a second PHP-Version and actually it works well but I have a few questions.
First of all some specs:
Ubuntu 10.04 (I need this older Version)
PHP 5.3.2-1ubuntu4.2.5 (Repo)
For my own PHP-Version I use the following "./configure" parameters (Reduced to the essential):
--prefix=/opt/php5310
--with-config-file-path=/opt/php5310/etc
--with-config-file-scan-dir=/opt/php5310/conf.d
--with-libdir=lib64
--with-mysql=/usr/bin/mysql
...
First of all executing "sudo make test" show up a few failed tests (about 10-14). Unfortunately I can't find any information what I have to do or what excactly goes wrong but "sudo make install" works nevertheless.
Is it normal that not all tests passed?
Then I noticed (phpinfo) the "imagick" extension was not loaded.
Looking at the "extension_dir" shows why.
On the Repo-Version:
extension_dir = /usr/lib/php5/20090626
On my own Version:
extension_dir = /opt/php5310/lib/php/extensions/no-debug-non-zts-20090626
(This folder doesn't even exist)
When I put this inside the php.ini:
extension_dir = /usr/lib/php5/20090626
It's working but is it the right way or just a creepy workaround?
And what about "--with-libdir=lib64" doesn't it belong to "extension_dir"?
On my System /usr/lib64 is a symlink to /usr/lib.
And last but not least my Repo-Version has a folder "/etc/php5/cgi/conf.d" with many ".ini" files e.g. "curl.ini", "gd.ini" and so on.
My Solution was:
"--with-config-file-scan-dir=/opt/php5310/conf.d
And then create the "conf.d" Folder and copy everthing from "/etc/php5/cgi/conf.d" to "/opt/php5310/conf.d" to be not dependent on the PHP Repo-Version.
Would this be a correct solution for multiple PHP-Versions or should it be a symlink or
"--with-config-file-scan-dir=/etc/php5/cgi/conf.d
Thank you for your help
Failing tests generally means failing functionality. Of course, for something as large as PHP you may never touch that functionality. It may be that your best bet here is to search for the names of the tests which failed to see if anyone has had the same issue (and how to fix it or disable the functionality), and to find the source of the tests in PHP and understand why they failed.

moodle - database connection failed when running a script

So I am setting up a moodle plugin that syncs groups defined in child courses into a meta course. I managed to install it based on the following instruction.
Installation
Copy the metagroups folder into your Moodle /local directory and visit
your Admin Notification page to complete the installation.
After installation you may need to synchronize existing meta-course groups, to do this run the cli/sync.php script (use the --help switch for further instructions on script usage).
So when i tried to run th sync.php script using this command in there terminal
php -f sync.php
it shows me an error message
I found that the line in the script that is causing this issue is the following line
require_once(DIR . '/../../../config.php');
my config.php file looks like this:
I have no idea why this is happening, as all moodle functionality seems to be working, which means database connection is the way it should be. Does anyone know this is happening and a way around this. Thanks in advance.
By the way, my moodle version is 2.6.3 running in localhost on a mac OSX 10.9
I had the same problem, but running moodle with MAMP.
The simple fix for me was just to add the php path for MAMP (for whichever PHP version I required):
export PATH=/Applications/MAMP/bin/php/php5.6.40/bin/:$PATH
…and then run whatever PHP script I needed!
Just a guess but I'm wondering if its picking up a different config.php
Try specifying the folder for the require_once
require_once('/Applications/XAMMP/moodlewebroot/config.php');
If that works then check the check the output of
echo DIR . '/../../../config.php'
Although it's more common to use dirname() in Moodle eg:
require_once(dirname(dirname(dirname(__FILE__))) . '/config.php');
Also some of the command line functions expect to have the dirroot set up in config.
$CFG->dirroot = '/Applications/XAMMP/moodlewebroot';

PHP is not working on Windows after I completely installed it

I am trying to setup php 5.5.12 on my Windows server 2008 R2
I found this good tutorial that walks you step by step
http://www.youtube.com/watch?v=WUoqkPJEp4Y
After completing every step everything seems to be fine.
I created a file called phpinfo.php and put the following code into and placed it on c:/inetpub/wwwroot
<?php php_info(); ?>
But when I got localhost/phpinfo.php or http://127.0.0.1:80/phpinfo.php I get a 404 error. I do not know why it is not working. when I execute the following from commands from the command line it looks like it is working and I get many output with no error.
cd c:/php
php -i
In addition to the instruction, I added the following to the registry of windows
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\PHP]
"IniFilePath"="C:\\PHP"
Can someone tell me what else do I need to make get php up and running on windows?
This is what is using port 80 on my server
To use localhost or 127.0.0.1 you need apache installed on your system too.
You can download xampp or wamp they both come with PHP, MySql & Apache installed in them.

PHMagick not working after code moved to a different server

I built a pdf generator script for one of my clients and everything works properly. He then decided that he wanted me to create a thumbnail image from the PDF to display on another page, so I came across PHMagick and that seemed to do the trick.
The following code worked on my building server (iPage -- I think it's debian?), but now that I've moved it to his VPS, it is no longer working. FPDF has no trouble generating the pdf, so it is not a permissions issue.
Code:
require("phmagick/phmagick.php");
$pdf->Output("pdf.pdf");
$p = new phmagick('','pdf.png');
$p->debug = true;
$p->resize(800);
$p->acquireFrame("pdf.pdf");
This code returns the following error:
Error executing "convert "pdf.pdf"[0] "pdf.png"" return code: 127 command output :"sh: convert: command not found"
I have not changed any of the code since I moved it from the original server, and I just copied the entire site over, so why is PHMagick not working now? How do I get it to recognize convert.php in the plugins folder?
Just a note: I am only using PHMagick, not the whole of ImageMagick.
PHMagic appears to be using the command line convert command in background.
Most likely that command is simply not installed on the server.
PHMagic use the command line convert,composite etc... commands in background.
These commands are only available if ImageMagick is installed in your server.
In your previous server ImageMagick must have been installed.
Ipage sometimes do not pre install ImageMagick on their VPS servers. And you might not be able to install it your self ( through terminal login using ... yum install ImageMagick ) coz you will be prompt for root password.
To make sure the ImageMagick binaries are installed in ur server, in ur case the convert command,
type this command in the ssh terminal...
whereis convert
If the path to the convert command is not shown, it means you need to install ImageMagick.
You will have to open a support ticket and ask them to install it for you
As arkascha said, you'll need to install imagemagick. Try yum install imagemagick since you're running CentOS.
EDIT: May be a different capitalization: ImageMagick

Warning: exec(): Unable to fork in PHP

I'm using php 5 apache on windows server 2008, I have disabled IIS.
I m using exec command in my PHP script and it was working fine
but today I got an error:
Warning: exec(): Unable to fork
I gave permissions to cmd.exe in C:\Windows\System32 folder
but this did not fix the problem.
Specifically which permissions did you give to who?
Probably not to the right user..
Run this php script:
echo 'Script is executed by: ' . get_current_user() . getmygid();
It will tell you which user is running the PHP scripts and therefore which user to grant permissions to cmd.exe.
In 64-bit windows (e.g server 2008), theres a folder named c:\windows\syswow64, that contains all executables/dll, that are required by a 32 bit app. installed on your 64-bit machine.
Make sure your required 32-bit .exe/dll etc is placed in that folder.
if you cant find it there you will have to put a 32-bit version of the required .exe/dll
there.So this can used by yopur app/process.
Now when your 32-bit application/process executes, windows will automatically redirect your process to execute required app in syswow64 folder.
Hopefully that should resolve your compatibility issue.
I had this problem myself, but was eventually able to resolve it. The problem was due to how I had accidentally set cmd.exe to "Run as Administrator" by default. I say "accidentally" as I thought I was only setting the compatibility settings of a shortcut on my task bar, but it turned-out it was setting the compatibility of the .exe itself. Anyhow, I disabled this by deleting the registry key here:
HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers
After doing this, everything started working again.

Categories