Any php file is not working in browser - php

I have tried many php files like huge file, small file but any of them is not working it will load and shows 504 gateway error
I tried test.php file with one line of code it is also showing the same error
<?php echo"Hi working fine"; ?>

I think you have updated php execution time in php config but what about Nginx config?
Try updating your Nginx Config :
Step 1 : Updates for your website test.com
vim /etc/nginx/sites-available/test.com
Step 2 : Updating Execution Time
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_read_timeout 300;
}
Step 3 : Don't forget to reload to reflect changes
service php5-fpm reload
service nginx reload
Hope this helps.

I'd check in the following order:
1) If php5-fpm is running:
sudo service php5-fpm status
if it returns the process number - try telneting it:
telnet 127.0.0.1 9000
2) If telnet returns connected status - I'd start checking the /etc/nginx/sites-enabled if the config of your site is there. If it's there - check that the stuff is set up correspondingly...one of the examples of how to set up nginx with php-fpm is here:
https://www.howtoforge.com/installing-nginx-with-php5-fpm-and-mysql-on-ubuntu-14.04-lts-lemp
3) If that is ok - reload the php5-fpm and nginx and check if permissions in your site dir (typically something like /var/www/html/site.com) are set right for user www-data (the default nginx user).
If that is ok - then I can't think of anything more without seeing configs and having fingertips on machine terminal.
Hopefully this helps a bit.

Had this problem on Ubuntu 16.04 with Apache and PHP 7.0. Tried a dozen solutions, which still gave me errors, and then found https://www.howtoforge.com/tutorial/apache-with-php-fpm-on-ubuntu-16-04/ which worked for me. With PHP 7.0 and Apache 2 installed, and as superuser:
apt install libapache2-mod-fastcgi php7.0-fpm
a2enmod actions fastcgi alias
Restart Apache.
And then add the following to a copy of /etc/apache2/sites-available/000-default.conf as a child of <VirtualHost>
<Directory /usr/lib/cgi-bin>
Require all granted
</Directory>
<IfModule mod_fastcgi.c>
SetHandler php7-fcgi.php
Action php7-fcgi /php7-fcgi virtual
Alias /php7-fcgi /usr/lib/cgi-bin/php7-fcgi
FastCgiExternalServer /usr/lib/cgi-bin/php7-fcgi -socket /var/run/php/php7.0-fpm.sock -pass-header Authorization
</IfModule>
In my case, I used a Sites directory in Home instead of /var/www/ and also had inside :
ServerName localhost
ServerAdmin me#myemail.com
DocumentRoot /home/me/Sites
If using a copy of 000-default.conf make sure to disable it with a2disconf and enable your copy with a2enconf.

Related

Setting up /status page of php-fpm on Apache2

I'm trying to set up the /status page of php-fpm on apache, but i'm getting a 404 error and i can't know why. I'm not expert at neither Apache2 or php, and i been struggling with this a couple days, so i'm here for some help.
This is my apache2.conf settings. And i also have another site hosted on apache with a Directory config:
<LocationMatch "/fpm-status">
Order Allow,Deny
Allow from 127.0.0.1
ProxyPass unix:/var/run/php/php5.6-fpm.sock|fcgi://localhost/fpm-status
</LocationMatch>
This is my php5.6 settings
listen = /run/php/php5.6-fpm.sock
listen.backlog = 65535
user = www-data
group = www-data
pm.status_path = /fpm_status
When i try to curl over http://localhost/fpm-status this message appears:
File not found.
On apache2 logs this appears when i try to acces that path:
AH01071: Got error 'Primary script unknown\n'
Check this: https://gist.github.com/Jiab77/a9428050ab9bb3f17c5e33343da94fd8
Seems you may be missing an Alias.
I solved it, I made multiple changes and then it worked, i don't know what certainly was, so i listed them.
Changed "fcgi://localhost/fpm-status" to "fcgi://localhost/"
Changed "pm.status_path = /fpm_status" to "pm.status_path = /status"
service apache2 restart
service php5.6-fpm restart
Then curl to http://localhost/status and worked as expected

DNS resolution error under php-fpm chroot

After days of intensive search to solve my problem, I couldn't get anything that worked, so here it is.
I‘m running a chrooted php with FastCGI and php-fpm (under Ubuntu 16.04 with php7), which works well, however I get the expected DNS resolution problem, for example when trying to file_get_content : file_get_contents(): php_network_getaddresses: getaddrinfo failed.
I looked online quite a bit and here's what i've already tried (without success) :
I used the methods described here, and also tried to adapt this tutorial in order to copy all the libraries used by php, and of course copied hosts and resolv files
I also tried to use nscd to link hosts file inside and outside the chroot by mounting it inside the chroot at /var/run/nscd
I also got some SSL issues, so I downloaded this certificate and put it where the default php-curl certificate was probably missing (found after openssl_get_cert_locations() : ["default_cert_file"]=> string(21) "/usr/lib/ssl/cert.pem)
edit: This doesn't seem to do much as phpinfo() returns no value for the certs files (see), so maybe I should tweak a bit openssl config file but I really don't know what to look for.
Using debootstrap (or other programs like this) is not an option for me, because it creates a too large chroot, and I'm willing to keep it lightweight and fast to create as I could have many chroots running on one machine.
Plus, here are my config files, however I doubt the problem to be here because most php functions work well under chroot :
Default php-fpm pool:
[${username}]
user = ${username}
group = www-data
listen = /run/php/php7.0-fpm.${username}.sock
listen.owner = ${username}
listen.group = www-data
pm = ondemand
pm.max_children = 20
pm.process_idle_timeout = 10s
pm.max_requests = 250
chroot = /var/www/${username}
chdir = /
Default apache virtualhost file :
<VirtualHost *:80>
ServerName www.${domain}
ServerAlias ${domain}
ServerAdmin webmaster#${domain}
DocumentRoot /var/www/${username}/var/www/${username}
<IfModule mod_fastcgi.c>
AddHandler php7-fcgi-${username} .php
Action php7-fcgi-${username} /php7-fcgi-${username} virtual
Alias /php7-fcgi-${username} /usr/lib/cgi-bin/php7-fcgi-${username}
FastCgiExternalServer /usr/lib/cgi-bin/php7-fcgi-${username} -socket /var/run/php/php7.0-fpm.${username}.sock -pass-header Authorization
<Directory /usr/lib/cgi-bin>
Require all granted
</Directory>
</IfModule>
</VirtualHost>
Thanks !
Under Ubuntu 16.04, you need at least these files in your chroot:
etc/resolv.conf
lib/libnss_dns.so.2
You can hardlink to prevent using extra disk space (only works when the chroot is on the same partition as /lib):
ln --logical /lib/x86_64-linux-gnu/libnss_dns.so.2 /chroot/lib
If it still fails (future Ubuntu?) you can debug the issue by running strace -e file -fp $(pgrep fpm)

Could not reliably determine the server's fully qualified domain name for MacBook

First time got a new MBP 2016. Trying to setup PHP,MySQL & Apache. Started Apache by using command
sudo apachectl restart
Then installed PHP by
brew install php71 --with-httpd24
Also did following changes...
#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
DirectoryIndex index.html index.php
SetHandler application/x-httpd-php
ServerName dev-server
Also, updated the same in host file /etc/hosts/
But, whenever I'm trying to Stop/Restart my apache by using command sudo apachectl restart or sudo apachectl stop I'm getting following errors.
AH00557: httpd: apr_sockaddr_info_get() failed for Sureshs-MacBook-Pro.local
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
httpd not running, trying to start
But, strangely when I'm executing any PHP file from my browser http://localhost/index.php it's working fine. As in my index.php file I'm using code <?php phpinfo(); ?> It's showing PHP version PHP Version 7.1.4 loaded.
Tried a lot but no clude what's going wrong at where.
---UPDATE---
After updating 127.0.0.1 Sureshs-MacBook-Pro.local in my /private/etc/hosts file, one error solved. Now I'm getting only one below error.
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using Sureshs-MacBook-Pro.local. Set the 'ServerName' directive globally to suppress this message
Finally, I solved this by updating ServerName localhost:8080 on file /usr/local/etc/apache2/2.4/httpd.conf. It was a differnt httpd.conf file which I didn't knew about it.
Also, for Apache start/restart/stop following command sudo /usr/sbin/apachectl start works for me.
As per message:
Set the 'ServerName' directive globally to suppress this message.
You need to identify httpd.conf Apache configuration file by:
apachectl -t -D DUMP_INCLUDES
then edit it and uncomment the line with ServerName (make sure it has the valid server name). E.g.
ServerName localhost
open file httpd.conf
vi /etc/httpd/conf/httpd.conf
add to first line
ServerName localhost
systemctl restart httpd
I resolved this issue changing the port address in the httpd.conf file in windows.
This problem arises due to the port already listening, which we use in the conf file.
To view the port listening, use the command "netview /a"
if the port used in the conf file already listening, change to different one(e.g, 8080)
set servername to "localhost" or 127.0.0.1
Now start the apache server "httpd.exe -k start"
it will work fine.
On macOS Catalina...
Edit the Apache config file
sudo vi /etc/apache2/httpd.conf
Find the ServerName entry by typing a / followed by ServerName and hit enter
Press n to go to the next occurrence until you are on #ServerName www.example.com:80 (keep pressing n if you go past it)
Add a newline by typing an o
Type the following: ServerName localhost
Save and exit by typing !wq then hit enter (or type ZZ which is capital Z twice)
Restart Apache
sudo apachectl restart

Apache + PHPMyAdmin - Redirect directory to subdomain

So im running Apache on Ubuntu 16. I have phpmyadmin accessible via a directory because thats how it does it by default (e.g. to access phpmyadmin, I have to go to www.mydomain.com/phpmyadmin)
I wrote an Apache VHost to make it accessible via a subdomain as shown here in my Vhosts:
http://pastebin.com/raw/tyZGbsSC
This works and now I can access phpmyadmin via a subdomain (phpmyadmin.mydomain.com) but the problem is that it is still accessible through the directory (www.mydomain.com/phpmyadmin)
How to i stop this?
There should be a conf file phpmyadmin.conf in /etc/apache2/conf-enabled which contains the following line
Alias /phpmyadmin /usr/share/phpmyadmin
Just comment out that line by putting a hash
#Alias /phpmyadmin /usr/share/phpmyadmin
and restart apache.
That should do the job.
You probably have the server-wide configuration enabled in /etc/apache2/conf-enabled
user#host:~ $ sudo a2disconf phpmyadmin
should disable it for you, or just remove /etc/apache2/conf-enabled/phpmyadmin.conf

Configuring HHVM 3.7 with Apache 2.4 gives me a 404?

I can't seem to configure HHVM and Apache, it keeps giving me a 404 file not found error. My configuration file for the website is saved as www.example.com.conf, it contains:
<VirtualHost *:80>
ServerName website.com
ServerAdmin mail#website.com
DocumentRoot /var/www/website.com/public_html/
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/website.com.com/public_html/$1
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Note that I've removed my actual website name, but it's for a subdomain so it's this: subdomain.xyz.com. I've tried looking up how to fix this, but whatever I've tried doesn't seem to work; even the GitHub issues people have posted on the official repository don't seem to work. I also haven't changed the default apache configuration, the only thing I have changed is the root directory of my website which does much up to the directory in the configuration file above.
Any ideas? Thanks.
I know it's been two months already, but maybe it helps someone else (I had a similar issue occur many times when configuring HHVM + Apache2).
Try to enable the vhost if you haven't yet done so. Issue sudo a2ensite www.example.com and reload apache afterwards with sudo service apache2 reload.
If the vhost is ok and you have your browser requests visible in the vhost access log, then it means that it's not Apache2 that's the culprit there.
So if you're still with me and the first two steps didn't help, try the following, although in HHVM 3.7 it shoulnd't be the case anymore (but it might, I just follow the try-and-check method when it comes to configuring HHVM, and it usually works). Open /etc/hhvm/server.ini and append the following line to that file:
hhvm.server.fix_path_info = true
After changing the HHVM's configuration, issue sudo service hhvm restart. Then try to refresh your website. It should be all good.
I had similar issues and back then it was the most common fix on all webservers I configured to work with HHVM. But, after the latest updates, I had to comment that line out of my hhvm server.ini in order for my code to work - I read that they have somehow changed the parameters of the server and this parameter does no good anymore, AFAIK.
I have also tried to put that line in /etc/hhvm/php.ini but as far as I remember, it should go to server.ini because it's a server parameter.
So. Try it and let me know if that helped. If not then please issue the following commands on your webserver and paste the output here, so I can see if you have the necessary modules installed
ls /etc/apache2/mods-available | grep -E 'proxy|alias|fcgi|hhvm'
ls /etc/apache2/mods-enabled | grep -E 'proxy|alias|fcgi|hhvm'
Oh, and please include your full HHVM and Apache2 version output:
hhvm --version
apache2 -v

Categories