PHP fails to read files - php

I have two servers, one production and one development. Both machines are windows machines, running Apache as the same user on the network. Last week, the network password for the user was changed, and that's when things stopped working.
Ok, no problem, once I identified that happened, I simply change the user/password credentials on the service, and restart Apache.
PHP doesn't want to open any files, or even acknowledge that they exist on the production machine. But everything is dandy on the dev machine.
For illustrative purposes, The following works fine on the development server, but not the production server:
<HTML>
<?php
$filename = '\\\\petra\\operations\\test.txt';
if (file_exists($filename)) {
echo "The file <u>$filename</u> exists";
} else {
echo "The file <u>$filename</u> does <b>not</b> exist";
}
?>
</HTML>
On the dev machine, I get a lovely The file \\petra\operations\test.txt exists but on my production machine, i get much less happy The file \\petra\operations\test.txt does not exist I can point to any file on any server on the network and the same will happen.
The hardware is completely different on the two machines, but they are very similar, software wise. For example the Apache configurations and php.ini files are exact copies.
This is related to a previous question I asked. At the time, I was thinking it was a bad file path, or maybe something someone else had made a mess of. That much was true (vis-a-vis, the password changed), but now both machines know the new user credentials and apache has been restarted on both.
Ideas? What would prevent PHP from being able to open a file?
EDIT: I don't think it has to do with user permissions on the files, just as such. Both machines are running Apache as the same user, pointing to the same file on the same network.
I did setup a new test file location on some other random machine on the network, upon which I then set very permissive permissions. my php now calls this: $filename = '\\\\procl35\\folder\\test.txt'; and I get The file \\procl35\folder\test.txt does not exist on the production server.

I have a resolution to this.
First, I should mention the production server is run by the IT department, in the server farm. In the original question above, I stated "I simply change the user/password credentials on the service, and restart Apache." Actually, IT changed the password and restarted Apache. This is a semantic difference, but one which turns out to be important here.
This morning, I asked the people over in IT if they had any ideas on the problem. The sysadmin poked around, and realized he hadn't actually changed the user password at all, despite his insistence that he had done so.
I'm not going to throw IT under the bus here. They're busy people, and they are human, and that's okay. But I will offer this resolution to future developers: If you encounter this kind of problem I suggest "re-updating" the password, because maybe it didn't happen right the first time. Maybe he updated the password on a different service (which also needed it anyway). Maybe he typed it in, mistyped one character, didn't read the failure message, and closed the window. Whatever, it's not important.
The resolution is to update the password in the service.
Cheers!

Related

How to change 'No Privileges' for phpMyAdmin online?

I have a website I uploaded online. It works perfectly fine on XAMPP (localhost), but when online, it seems that functions like INSERTING new users to the DB (to register) do not work online, as well as many other INSERT functions. I gave all privileges on DirectAdmin, but on phpMyAdmin I still get "No Privileges".
Does anybody have a fix? and also, is it the phpMyAdmin blocking me from registering new users, or is the problem something else?
There are a few problems here, the most pressing is the lack of information.
phpMyAdmin runs on a web server, but it looks like you are using XAMPP, which is a pre-rolled solution for users that might not necessarily know how to configure phpMyAdmin in Linux/Mac/Windows, setup their own solution, or want something easy to deploy. There should be a log file you can grab.
I've never used XAMPP, but I have used phpMyAdmin for decades. Setting up using the default settings XAMPP is installed to "C:\XAMPP".
If I browse to that file I see a directory called "apache" and inside that "logs". This file, "error", should contain the error that will help us determine why your server is having issues with permissions.
**
Please send the text from the error file in
"\apache\logs".
**
This might be a bug with XAMPP, phpMyAdmin, your configuration, or something else. Paste the errors from the log file and I will be happy to look at them. I can't solve your problem with the information you have provided, but hopefully this will help point you in the right direction.

Check who made changes in server

We have a digital ocean server which runs 5-6 wordpress websites we have. We have 3 programmers who have access to the server. And today all websites were down until I fixed. I didn't know this issue until one programmer told me.
I checked the log and found out:
unix:/run/php/php7.0-fpm.sock failed
I saw this
Failed to restart php7.0-fpm.service: Unit php7.0-fpm.service is masked.
When I tried to restart it.
I checked the file and nothing was in that directory, so I install, then restarted the server, websites were back online.
My question is: is there any way to find out who did this? Or when it happened? Any helps will be appreciated. Thanks.
It sounds to me like nginx crashed and had to be restarted.
It's something that happens every now and again on our servers and restarting the server always gets it back online.
In this case, I don't believe that you should point the finger at anyone as sometimes these things just happen with servers.
It might be worth checking over the server for any potential issues like the disk space, etc.
Keep an eye on the error log and see if that provides any clues.

How to debug a site move, for a PHP5/MySQL web application

I have been running a PHP site for years on my own servers. I recently purchased a dedicated server package and am trying to move my site to the dedicated server. I recently upgraded to PHP 5, and my current server is running PHP 5.6.16. I moved the files and the database, and put it in a live test domain, but the site is not functioning properly on the new dedicated server. Several key scripts are non-functional. I made sure that the dedicated server is running a version of 5.6. I have configured it to the same settings I have on the old server. I can see that the site is talking to the MySQL database. I turned on error reporting and I see no significant errors suggesting why these important scripts are now non-functional. I made sure the include path is there, and if it wasn't nothing would work. What am I overlooking? What could be different between one server and the other that might impact PHP functionality? I'm basically at my wits end here, so if these seems stupid please forgive me, but I don't know where to look next.
Start with the basics.
Does your web server respond to static page requests?
Is your web server configured to use PHP?
Can your web server execute and/or connect to PHP?
If you have a simple script with <?php phpinfo(); in it, does it work?
Are all the expected modules there in your phpinfo() output?
Do you have rewrite rules that need to be reconfigured? (Check your web server error log. Check your response status codes.)
Assuming PHP is all good, move into your application.
Are you absolutely sure error logging is on? (Again, check phpinfo() output. Try to force an error, maybe a syntax error or something and see if you see the error.)
How do you know your application is connecting to MySQL?
Start with a basic script that just echos some things.
Comment out large swaths of code and see if you can narrow down the problem that way, re-enabling chunks as you go. (You want to bi-sect the problem, cutting in half and in half and in half until you figure out exactly what the issue is.)
Other system-level things to check...
File system permissions? (See also https://serverfault.com/questions/48587/is-there-a-linux-log-for-when-a-user-is-denied-access-to-files-due-to-permission, for Linux.)
Firewalls? (Are you sure you can actually access MySQL over the network?)
Disk? (Are you out of space? Are your partitions set up correct? Is /tmp full?)
Once you figure out the problem, some advice:
Do this sort of thing regularly. Write a provisioning script to build yourself a new machine from one command, and do it regularly. These days with cloud providers (physical hardware or not) there's no reason you can't blow away your application servers on a regular basis, and re-provision them. Consider making this your system upgrade strategy. (Why reboot to get a new kernel when you can just have a whole new server with the new kernel and other patches, that you can cut over to?)
Ensure your development environment closely matches your production environment. (Consider Vagrant for this.)
You're using version control, right? If not, start using version control so that you can hack on your code for things like this and easily roll back when done.

shell_exec is not working on server

i am using shell_exec to get whois details of a domain. Everything is working fine on localhost but when i am uploading the script on server, it is creating problems. On server, the shell_exec is working partially.
echo "shell_exec('whoami')";
gives me an output.
mac
but when i am using
echo "shell_exec('whois example.com')";
I am getting a blank page
Should i consider using a hosting account with root privilege? If yes then how to deal with security issues?
P.S- i dont know if something like this even exists but i've tested it on localhost and it is running fine on MAMP.
Thanks in advance.
If you do decide to host this script with root privileges, then you should (and I'm sorry) be locked up in a padded cell. That's just mad! You don't need root privileges to run a simple whois command. That's insane!
Hosting as root is about as safe as a nursery, ran by catholic priests, serial killers and crack addicts, who haven't had a fix in three days. Things are going to happen... You can only speculate as to when and how bad it's going to end.
Check using whoami what user is running the script, then check what it's PATH looks like, compare that to where whois actually is, if at all present. If it's not installed, ask your admin to set it up, and give you the rights to use it. If it's installed, try shel_exec('/path/to/bin/whois example.com');
Read up on user rights, and environment variables, (and how to load/manipulate them from a PHP script)

Connecting to SQL Server very slow

I have a standard php app that uses SQL Server as the back-end database. There is a serious delay in response for each page I access. This is my development server, so its not an issue with the live setup, but it is really annoying for working on the system.
I have a 5 - 8 second delay on each page.
I am running SqlServer 2000 Developer Edition on a Virtual Machine (Virtual PC).
I have installed SqlServer on my development machine but get the same delay.
I have isolated the issue to the call to mssql_connect (calling mssql_pconnect has no effect)
It is a networking issue on how I have set up (or not set up, since I didn't really change default config) SQL server. It's not a strictly a programming issue but I thought I might get some valuable feedback here.
Can anyone tell me if there is a trick, specific set of protocols, registry setting, something that will kill this delay?
I was also experiencing a 5-10 second delay on every connect, using the official Microsoft SQL drivers for PHP (as suggested by #gaRex) - none of the answers posted here solved it for me.
As suggested by #ircmaxell, my problem was a DNS issue - and the solution was to edit the \windows\system32\drivers\etc\hosts file (your local local host file) and add the name of my own machine to it.
In the "system properties" dialog, find the "computer name" of your machine - then add a line like 127.0.0.1 my-computer to your local host file.
For me, the delay occurred once more, on the following attempt to load the page - after that, it was super fast, no delay at all.
Note that this problem may occur even on a physical machine, not only on a VM.
I came across network issues when running virtual pc, everything network related is slow, try adding this entry on your registry:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters
Create new DWORD value named DisableTaskOffload and set its value to 1.
Restart the computer.
It worked for me, source.
Is it perhaps a DNS issue? I know that MySQL does a reverse DNS lookup on each login (not each connection). If you don't have a reverse dns record for your server (or your dns is slow) it can cause a major delay at login. There's an option in MySQL to disable that. I'm not sure about SQL Server, but I'd assume it may be doing something similar...
I remember the same problem, but forgot, how we have solve it.
To clarify please specify exact connect strings, your SQLserver versions and also try to start this old good utility c:\WINDOWS\system32\cliconfg.exe, which is also can bring some light.
Yes, I know, it's from 2k, but guys at m$ don't like to create client tools from scratch.
Also try to get "right" mssql client dlls for PHP.

Categories