Different php result between terminal and browser - php

My server is running php-fpm with nginx. I had applied these permissions.
sudo chgrp -R www-data /usr/share/nginx/html
sudo chmod -R g+rw /usr/share/nginx/html
sudo chmod g+s /usr/share/nginx/html
I have this code.
if(function_exists("my_void_function")){
echo "exist";
}else{
echo "none exist";
}
I am getting different result that simple code. you can see screenshot of my pc from this image.

As you have added the function via a custom extension, you must load the extension with the respective php.ini file of the PHP engine. PHP CLI has a different php.ini than PHP-FPM/mod_php.
Also, after changing php.ini of PHP-FPM, you must restart the PHP-FPM service (usually sudo service php-fpm restart on Debian-like systems). Those who are using mod_php with Apache need to restart the Apache service.

Related

white screen when running the phpMyAdmin 5.2.0 script from another apache (php-fpm) user

operating system: RockyLinux 8
apache version: 2.4.37
php version: 7.2.24 (cli)
script location: /var/www/html
phpMyAdmin version: 5.2.0
chmod permissions on files/folders don't matter (please use default system chmod permissions)
there are no errors in the Apache/PHP-FPM logs that would indicate this problem
please do the following:
$ sudo useradd -d /var/www/ -m -U -s /sbin/nologin www
change the lines in the file /etc/httpd/conf/httpd.conf
User www
Group www
change the lines in the file /etc/php-fpm.d/www.conf
user = www
group = www
listen.acl_users = www,nginx
restart Apache and PHP-FPM
$ sudo systemctl restart httpd
$ sudo systemctl restart php-fpm
open the page in a browser, you will see a white screen
now, set for php-fpm configuration user as apache and group as apache
change the lines in the file /etc/php-fpm.d/www.conf
user = apache
group = apache
restart PHP-FPM
$ sudo systemctl restart php-fpm
now you see the main page of the phpMyAdmin script in a browser
what's the matter here? Thank you!
I was having these exact same symptoms in my Rocky 8 environment. Basically trying to run the entire LAMP service as a user other than "apache", would cause phpMyAdmin to show a blank screen, while all other PHP scripts still worked fine.
The solution for me was to change the permissions of three folders within /var/lib/php directory:
/var/lib/php/opcahce
/var/lib/php/session
/var/lib/php/wsdlcache
These were all set to root:apache ownership with file permissions 770 (rwxrwx---).
By modifying the permissions on these three folders to be writable by the new user (non apache) that is running the httpd & php-fpm services, the phpMyAdmin page began working again. In my case I simply changed the ownership to root:newuser ("newuser" being the user running the services rather than apache).
Environment:
Rocky Linux 8.7: 4.18.0-425.3.1.el8.x86_64
WEB: Apache/2.4.37 (rocky) OpenSSL/1.1.1k SVN/1.14.1
PHP: 7.4.30

Symfony can't write in cache folder on CentOS 7 even with the right permissions

Symfony cannot write in cache folder even i give full permissions to that folder
chmod 777 -R /path/to/symfony/var
But I am always getting these error
Cache directory "/path/to/symfony/var/cache/dev" is not writable.
I am on Centos 7 and I use nginx and php7
I never had this problem on Ubuntu or Windows. It's just when i moved my application to CentOS
One suggest to me to run those commands on the var folder
chcon -R -t httpd_sys_content_rw_t /path/to/symfony/var
systemctl restart nginx
This solution worked once. But after a while i got the same problem.
I tried to re-run tose commands but nothing changed.
Any ideas?
I've solved this issue.
Here is how.
First, Nginx and php-fpm are running using the nginx user. This user is created automaticlly when installing Nginx.
On the /etc/nginx/nginx.conf
user nginx;
And on the /etc/php-fpm.d/www.conf
user = nginx
group = nginx
...
...
listen.owner = nginx
listen.group = nginx
listen.mode = 0660
Second the permissions on the symfony app are set to 755 and the owner is changed to nginx user/group (The user Nginx and php-fpm are using)
sudo chown -R nginx:nginx /path/to/symfony
sudo chmod 0755 -R /path/to/symfony
Then, I run two commands. The first is to ennable the httpd connections
And the second allows the httpd process to read and write on the /path/to/symfony folder
sudo setsebool -P httpd_can_network_connect on
sudo chcon -R -t httpd_sys_content_rw_t /path/to/symfony
Finanlly, restarting the Nginx service
sudo systemctl restart nginx

How to fix error 403 error php files

I'm running ubuntu 16.04 and installed LAMP this way:
Install Apache
sudo apt-get install apache2
Install MySQL
sudo apt-get install mysql-server
Install PHP
sudo apt-get install php7.0 libapache2-mod-php7.0
Restart Server
sudo /etc/init.d/apache2 restart
Check Apache
Working
Check PHP
php -r 'echo "\n\nYour PHP installation is working fine.\n\n\n";'
Working
Files structure:
/var/www/html/index.html > redirects to index.php
/var/www/html/pages/index.php < this file is not working and all php files
The owner group is set to:
chown -R www-data:www-data /var/www
The folders permissions are 755. The index.php permssions is 644 This is my apache2.conf file: https://ghostbin.com/paste/wwhog
But when i go to: http://localhost/pages/index.php I get this 403 Forbidden error. It seems like i can't see php files.
Here is some ways how to fix it.
chmod files 644 and folders 755 (you have opposite side)
check owner of folders and files and chown them correctly.
Disable SELinux.
Checking error log file of Apache will give you more information about error.
Try chown -R www-data:www-data /var/www, if you still get a 403, that means the problem is in apache2 conf, but i do not think.
I'll complete this response when i'll can see your apache's conf :) (apache2.conf & sites-enabled/000-default.conf -it should be the one you'are using in /var/www/html/-)

Ubuntu 14.04.1 LTS, LAMP Server, PHP not working

I have installed Ubuntu 14.04 on a server for local use.
Apache is working fine. I have see the phpinfo() method in /var/www . I have also changed the document root to /var/www but then also I cannot see the phpinfo on the browser.
HTTP 5000 error is thrown by the browser.
sudo apt-get install php5
sudo chmod -R 755 /var/www/
Try the following:
sudo chmod 777 -R var/www
What your doing here is allowing the read/write permission to your www folder into the var directory. First cd into your root and enter the above into your terminal.
http://www.computerhope.com/unix/uchmod.htm
Read the above link in order to get the detailed idea in chmod in terminal.

Cannot load or save configuration

I get this cannot load phpMyAdmin message. I've tried creating the config folder and the config.inc.php file. When I ĺog on to localhost/phpmyadmin/setup/ it still gives me this message.
Error message: "Cannot load or save configuration Please create web server writable folder config in phpMyAdmin top level directory as described in documentation. Otherwise you will be only able to download or display it."
I have given the www/html folder full rights.
How to I fix this?
thanks in advance!
I have had similar issue on my Ubuntu 16.04. I made a research and in the end I found a resolution of the issue. Maybe my case solution will help somebody else.
Background: For security reasons I have non privileged user and group apache:apache (sudo groupadd apache | useradd -g apache apache). They are preset by directives (User apache; Group apache) in /etc/apache2/apache2.conf. This user apache:apache owns Apache2 main directory (sudo chown -R apache:apache /etc/apache2) and some other files, for example: sudo chown -R apache:apache/etc/phpmyadmin/htpasswd.setup
In this manual: http://docs.phpmyadmin.net/en/latest/setup.html - I found that...
Debian and Ubuntu have changed way how setup is enabled and disabled,
in a way that single command has to be executed for either of these.
To allow editing configuration invoke:
/usr/sbin/pma-configure
To block editing configuration invoke:
/usr/sbin/pma-secure
Note! In the content of the two files listed above we talk about /var/lib/phpmyadmin/config.inc.php instead of /etc/phpmyadmin/config/config.inc.php. It was the key.
In my case I was modified the content of these scripts (see below) and now I can use localhost/phpmyadmin/setup properly.
/usr/sbin/pma-configure:
#!/bin/sh
echo "Unsecuring phpMyAdmin installation..."
echo "Setup script can now write to the configuration file."
echo
echo "Do not forget to run /usr/sbin/pma-secure after configuring,"
echo "otherwise your installation might be at risk of attack."
sudo sudo chown -R apache:apache /var/lib/phpmyadmin/config.inc.php
chmod 0660 /var/lib/phpmyadmin/config.inc.php
/usr/sbin/pma-secure:
#!/bin/sh
echo "Securing phpMyAdmin installation..."
echo "Setup script won't be able to write configuration."
sudo sudo chown -R root:root /var/lib/phpmyadmin/config.inc.php
chmod 0640 /var/lib/phpmyadmin/config.inc.php

Categories