Apache not serving php files - php

So I'm trying to get my LAMP stack to work in my Macbook. I've apache setup but PHP is not working. I've installed php55 with Brew and loaded the module in my httpd.conf file like this:
LoadModule php5_module /usr/local/opt/php55/libexec/apache2/libphp5.so
I've checked if the libphp5.so was at the location the module is pointing and it was there.
If I check my apache error.log I get the following message:
[Sat Apr 23 21:36:59.307093 2016] [ssl:warn] [pid 7231] AH01873: Init: Session Cache is not configured [hint: SSLSessionCache]
[Sat Apr 23 21:36:59.358254 2016] [auth_digest:notice] [pid 7231] AH01757: generating secret for digest authentication ...
[Sat Apr 23 21:36:59.360623 2016] [mpm_prefork:notice] [pid 7231] AH00163: Apache/2.4.18 (Unix) LibreSSL/2.2.6 PHP/5.5.34 configured -- resuming normal operations
[Sat Apr 23 21:36:59.360661 2016] [core:notice] [pid 7231] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
I'm missing something but I'm not quite sure what at this point.

Did you also update your Apache config to recognize .php extensions?
AddType application/x-httpd-php .php
or
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>

add the following line to your httpd.conf:
AddHandler application/x-httpd-php .php
after apache restart everything should work

Related

Apache not working after macOS Mojave update

Ok, after update macOS from High Sierra to Mojave, Apache with PHP stop working properly, so I did everything as is said in this guide - https://getgrav.org/blog/macos-mojave-apache-multiple-php-versions
but after that, still apache not working properly, sometimes working, sometimes not, and its says in browsers ERR_CONNECTION_REFUSED or other errors like 404 or 500.
In apache log is:
[Tue Oct 02 15:02:23.209423 2018] [mpm_prefork:notice] [pid 14579] AH00173: SIGHUP received. Attempting to restart
[Tue Oct 02 15:02:23.255957 2018] [mpm_prefork:notice] [pid 14579] AH00163: Apache/2.4.35 (Unix) PHP/7.2.10 configured -- resuming normal operations
[Tue Oct 02 15:02:23.256008 2018] [core:notice] [pid 14579] AH00094: Command line: '/usr/local/opt/httpd/bin/httpd'
[Tue Oct 02 15:14:37.626645 2018] [mpm_prefork:notice] [pid 14579] AH00173: SIGHUP received. Attempting to restart
[Tue Oct 02 15:14:37.674603 2018] [mpm_prefork:notice] [pid 14579] AH00163: Apache/2.4.35 (Unix) PHP/7.2.10 configured -- resuming normal operations
[Tue Oct 02 15:14:37.674672 2018] [core:notice] [pid 14579] AH00094: Command line: '/usr/local/opt/httpd/bin/httpd'
[Tue Oct 02 15:28:40.715060 2018] [mpm_prefork:notice] [pid 14579] AH00173: SIGHUP received. Attempting to restart
[Tue Oct 02 15:28:40.752117 2018] [ssl:warn] [pid 14579] AH01909: www.example.com:8443:0 server certificate does NOT include an ID which matches the server name
[Tue Oct 02 15:28:40.766009 2018] [mpm_prefork:notice] [pid 14579] AH00163: Apache/2.4.35 (Unix) OpenSSL/1.0.2p PHP/7.2.10 configured -- resuming normal operations
[Tue Oct 02 15:28:40.766052 2018] [core:notice] [pid 14579] AH00094: Command line: '/usr/local/opt/httpd/bin/httpd'
I have faced similar issue with PHP 5.6 as it was running fine before Mojave upgrade. I did the following to resolve the issue successfully:
Run the command below
sudo nano /etc/apache2/httpd.conf
make sure the below modules are uncommented:
LoadModule authz_core_module libexec/apache2/mod_authz_core.so
LoadModule authz_host_module libexec/apache2/mod_authz_host.so
LoadModule userdir_module libexec/apache2/mod_userdir.so
LoadModule include_module libexec/apache2/mod_include.so
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
I have added the missing one in httpd.conf
Check the right php module for you (PHP 5.6 ot 7.x) and load the required module too by adding the line or commenting/uncommenting the lines
LoadModule php5_module libexec/apache2/libphp5.so
OR
LoadModule php7_module libexec/apache2/libphp7.so
Comment the one not needed by adding "#" to start of line
Run below commands for apapche restart and test
a. sudo apachectl restart
b. apachectl configtest
Check for any errors there
For PHP 5.6:
In case you were having the php 5 with brew already in system before upgarde and the above changes gives error as below
"httpd: Syntax error on line 180 of /private/etc/apache2/httpd.conf: Cannot load libexec/apache2/libphp5.so into server: dlopen(/usr/libexec/apache2/libphp5.so, 10): image not found"
Then search for libphp5.so in the system and if found copy it to "/usr/libexec/apache2/"
In my case command was
sudo cp ./local/Cellar/php#5.6/5.6.25_1/libexec/apache2/libphp5.so /usr/libexec/apache2/
This all made things working in my system
Further to adang's reply i also had to uncomment this line:
Include /private/etc/apache2/extra/httpd-userdir.conf
in order for it to know what user directories were available.
Within /private/etc/apache2/extra/httpd-userdir.conf
I had to uncomment this line:
Include /private/etc/apache2/users/*.conf
then:
sudo apachectl restart
I had the same issue after installing the Mac OS Mojave.
I have done the following steps and it worked with me:
brew update
then:
brew upgrade
I have edited /etc/apache2/httpd.conf by uncommenting the following line:
LoadModule php7_module libexec/apache2/libphp7.so
Open the terminal and restart the apache server:
sudo apachectl restart
you might find the post on this link helpful
I followed the instructions in the above answers and still got a 403 Forbidden when trying to access my /Users/myuser/Sites/ folder. To fix this I had to change the user in /etc/apache2/httpd.conf from _www to my own user.
To do this edit your httpd.conf file using your favorite editor /etc/apache2/httpd.conf. Look for:
User _www
replace with your user:
User myuser
then restart apache:
sudo apachectl restart
because the topic is the httpd.conf messed up after Mojave upgrade I got also this error during sudo apachectl configtest
Could not reliably determine the server's fully qualified domain name, using XXX. Set the 'ServerName' directive globally to suppress this message
I found out the #ServerName localhost:80 in the httpd.conf was comented out, uncommenting resolved my issue.

IBM HTTP Server (Apache2) error

I have configured IBM HTTP Server as follow:
<IfModule mod_fastcgi.c>
Options Indexes MultiViews ExecCGI
FastCGIServer "c:/php7.1/php-cgi.exe"
SetHandler fastcgi-script
</IfModule>
<Directory "C:/IBM/HTTPServer85/htdocs/public">
AddHandler fastcgi-script .php
Options FollowSymLinks Indexes MultiViews ExecCGI
AllowOverride None
Order allow,deny
Allow from all
</Directory>
I get the following errors:
[Mon Jan 29 12:17:22 2018] [notice] Child 8328: Starting 600 worker threads.
[Mon Jan 29 12:17:22 2018] [notice] FastCGI: process manager initialized
[Mon Jan 29 12:17:22 2018] [warn] FastCGI: server "C:/php7.1/php-cgi.exe" started (pid 4636)
[Mon Jan 29 12:17:22 2018] [notice] Child 8328: Listening on port 443.
[Mon Jan 29 12:17:22 2018] [notice] Child 8328: Listening on port 8443.
[Mon Jan 29 12:17:24 2018] [error] [client 192.168.107.169] (OS 2)The system cannot find the file specified. : FastCGI: stat() of "C:/IBM/HTTPServer85/htdocs/public/login/" failed
[Mon Jan 29 12:17:24 2018] [crit] (OS 193)%1 is not a valid Win32 application. : FastCGI: can't start (dynamic) server "C:/IBM/HTTPServer85/htdocs/error/500/index.php": spawn_fs_process() failed
[Mon Jan 29 12:17:24 2018] [crit] [Mon Jan 29 12:17:24 2018] file G:\\blddir\\IHS85\\apache\\modules\\fastcgi\\fcgi_pm.c, line 1787, assertion "s->procs[i].pid < 0" failed
What is wrong with my http.conf?
It looks like you have a hybrid/partial config of multiple ways to configure fastcgi.
In the era of mod_fastcgi (IHS 8.5.5 and earlier), you'd typically see the "Action" directive here which results in a request for foo.php to be passed to the PHP interpreter as an argument.
Since you don't have action, and your SetHandler does not limit to
any particular extension, mod_fastcgi tries to invoke your php script
directly as an executable. On Windows, this association of what intepreter to use is the global one of the OS.
If you stick with mod_fastcgi, I'd suggest using the boilerplate examples with Action you see everywhere. But there's no reason to torture yourself with this when even IHS 9 has mod_proxy_fcgi and you could instead configure that and php-fpm instead.

PHP Stopped working with Apache

I have the following line uncommented in httpd.conf:
LoadModule php5_module libexec/apache2/libphp5.so
When I go to any php page, the file downloads instead of displaying in the browser. I verified that if I go to a html page, the page displays correctly so it for sure has to do with PHP.
Weird thing is that this was working fine ever since I started using this Mac computer but all of a sudden stopped working. The only thing that I can think of that I did is update Slack but that doesn't seem like it would have anything to do with this.
Also another weird thing is that my command line tool (drush) which uses the same php does work.
I can't think of what it can be.
I tried to use Homebrew to install another version of php but the problem remains.
This is in the apache error log when I run the apachectl restart command:
[Tue Jan 19 16:56:12.370590 2016] [mpm_prefork:notice] [pid 994] AH00169: caught SIGTERM, shutting down
[Tue Jan 19 16:56:12.600054 2016] [mpm_prefork:notice] [pid 1005] AH00163: Apache/2.4.16 (Unix) PHP/5.5.30 configured -- resuming normal operations
[Tue Jan 19 16:56:12.600123 2016] [core:notice] [pid 1005] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
I am not seeing any errors in my php error log or anything in the apache error log (otherwise what I specified above after running the command).
Please make sure that correct AddType for php is application/x-httpd-php
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
Also make sure your php module is loaded
LoadModule php5_module modules/mod_php55.so

500 Internal Server Error in PHP files

I have a problem. I installed CentOS Web Panel and varnish cache on my VPS server. I have two domains, two hosts on a VPS. One website is using WordPress other is not. Now everything on non-wordpress site is working (html,js,css,picture files...) fine except that PHP files are not working now(Same on WordPress). Just one file is working named testmail.php, which contains: <?php echo phpinfo(); ?>
Here is apache error log:
[Sat Jul 04 16:29:29 2015] [error] [client 172.***.***.***] Premature end of script headers: testip.php
[Sat Jul 04 16:29:37 2015] [notice] caught SIGTERM, shutting down
[Sat Jul 04 16:29:39 2015] [warn] Init: Session Cache is not configured [hint: SSLSessionCache]
[Sat Jul 04 16:29:39 2015] [notice] suEXEC mechanism enabled (wrapper: /usr/local/apache/bin/suexec)
[Sat Jul 04 16:29:40 2015] [notice] Apache/2.2.27 (Unix) mod_ssl/2.2.27 OpenSSL/1.0.1e-fips configured -- resuming normal operations
[Sat Jul 04 16:42:07 2015] [notice] caught SIGTERM, shutting down
[Sat Jul 04 16:42:21 2015] [warn] Init: Session Cache is not configured [hint: SSLSessionCache]
[Sat Jul 04 16:42:21 2015] [notice] suEXEC mechanism enabled (wrapper: /usr/local/apache/bin/suexec)
[Sat Jul 04 16:42:22 2015] [notice] Apache/2.2.27 (Unix) mod_ssl/2.2.27 OpenSSL/1.0.1e-fips configured -- resuming normal operations
I've noticed that i have two php.ini files one is at /etc/php.ini other is at /usr/local/php/php.ini (used by server) and I also have two httpd.conf files one is at /etc/httpd/conf/httpd.conf other is at /usr/local/apache/conf/httpd.conf (used by server). I've also noticed that there are no modules(mod_rewrite.so.. or any other) in second apache config file(used by server).
I tried to change ownership (chown) and tried to change file permissions (chmod) but nothing works. Can you help please?
500 Internal Server Error occurs from following reason. you can solve by followng:-
1.If you have not given file permsission you can get this error. Please give file permission.
Or Open Apache’s httpd.conf file
you have to find following lines, and remove #
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule headers_module modules/mod_headers.so
you can also check your htaccess is file or folder is allowed or not.

cgi-bin configure fro httpd

I am trying to configure cgi with apache
I did following changes in httpd.conf file
uncommented
AddHandler cgi-script .cgi
<Directory "/var/www/cgi-bin">
AllowOverride None
Options +ExecCGI
Require all granted
</Directory>
service httpd restart
But unable to execute, its giving following error in logs/error_log file
[Wed Mar 26 17:08:22.088316 2014] [mime_magic:error] [pid 7760] [client ::1:59024] AH01512: mod_mime_magic: can't read `/var/www/cgi-bin/hello.cgi'
[Wed Mar 26 17:08:22.089486 2014] [cgi:error] [pid 7760] [client ::1:59024] AH01215: (13)Permission denied: exec of '/var/www/cgi-bin/hello.cgi' failed
[Wed Mar 26 17:08:22.090045 2014] [cgi:error] [pid 7760] [client ::1:59024] End of script output before headers: hello.cgi
From here:
The problem is the security of SELinux is preventing mod_mime_magic access to the testprogram.
This happens when context of the program (in this case testprogram) does not match the directory.
To change to the appropriate context, use the UNIX command "chcon".
Read the following article for details: Apache and SELinux

Categories