What I have done:
Install apache 2.4 and php 5.4 from source.
apache config:
./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-modules=most --enable-mpms-shared=all --with-mpm=event
php config
./configure --prefix=/usr/local/php \
--with-mysql=mysqlnd\
--with-pdo-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--enable-mbstring \
--with-freetype-dir \
--with-jpeg-dir\
--with-png-dir\
--with-zlib \
--with-libxml-dir=/usr/local/libxml2 \
--enable-xml \
--enable-sockets \
--enable-fpm \
--with-mcrypt \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--with-bz2\
--with-apxs2=/usr/local/apache/bin/apxs
In the httpd.conf file, I enabled the mod_proxy.so and mod_proxy_fcgi.so and add the following config:
<IfModule proxy_module>
ProxyRequests off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/$1
</IfModule>
from phpinfo(), I see the Server API is FPM/FastCGI
My Problem:
I set the DirectoryIndex as below. I have index.html in the DirectoryRoot which is "/var/www". When I visit localhost, I am supposed to see the content of index.html. But it gave a 404 file not found.
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
When I switch the position of index.html and php in the above code. This time the html file is in front of php file. Then when I visit localhost, I can see the right content.
And I checked the apache error log. It says:
[Thu May 01 23:21:15.968659 2014] [proxy_fcgi:error] [pid 3415:tid 140603093 993216] [client 192.168.1.157:60384] AH01071: Got error 'Primary script unkn own\n'
When there is only index.php file in the /var/www, and leaving the httpd.conf like
<IfModule dir_module> DirectoryIndex index.html index.php</IfModule>
Also got 404, visiting the localhost.
My Question:
How do I fix the above problem?
I did some research on the configuration of fastcgi. like this and this
They dont mention the mod_proxy_fcgi, but all refering this
"FastCGIExternalServer /var/www/cgi-bin/php5.fcgi -host
127.0.0.1:9000"
So I am not sure if I am using the FastCgi the right way? Does this wrong way cause the above problem?
【P.S.】
Thank you regilero. I'm not using vhost and I had checked the error.log. It seems having something to do with php-fpm. The response page in the browser says "file not found", not "404", although the response code is 404. Here is what's in the error.log
[Thu May 01 23:21:15.968659 2014] [proxy_fcgi:error] [pid 3415:tid 140603093 993216] [client 192.168.1.157:60384] AH01071: Got error 'Primary script unknown\n'
I try to forward all the requersts ended with ".php" to fcgi. But the error above looks like that when I request index.html, it is also forwarded to the fcgi, which fcgi cannot handle it.(This is my guess) For the config about this forwarding, please see the code above, or search this page for "fcgi://".
Here is my Directory config. I'm not sure if this is what you need.
DocumentRoot "/var/www"
<Directory "/var/www">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
This is somewhat of a linked answer however it's one I share with many who come across the problem you are facing now and it seems to do the trick.
Checkout this GIST -> https://gist.github.com/diemuzi/3849349
There you will find all my working configurations for Apache and PHP-FPM. It seems like a better place to organize my configurations instead of pasting them here and confusing others. This link will not expire so no worries about that.
Perhaps also you can compare my working examples with what you have and find something missing that you currently are not using. Hope this helps!
Related
I'm running into an issue with setting a WSGIScriptAlias in Apache, where attempting to use the alias is giving a 404 error due to trying to reach the "literal" URL. Here's the test set-up in my Apache2 sites-available/000-default.conf (mimicking the mod_wsgi Quick Start Guide):
DocumentRoot /var/www/html
WSGIScriptAlias /wsgi_test /var/www/html/test.wsgi
<Directory /var/www/html>
Order allow,deny
Allow from all
</Directory>
After restarting Apache2 and going to mydomain.com/wsgi_test, a 404 page is displayed. The first line of Apache's error.log file below shows the server attempting to access the URL path wsgi_test in DocumentRoot, not the aliased file path:
AH00128: File does not exist: /var/www/html/wsgi_test
AH01964: Connection to child 1 established (server nathanclonts.com:443)
(70007)The timeout specified has expired: [client 67.161.148.188:33883] AH01991: SSL input filter read failed.
The file /var/www/html/test.wsgi has the same code as the above-mentioned Quick Start Guide:
def application(environ, start_response):
status = '200 OK'
output = b'Hello World!'
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
With permissions set to:
-rwxrw-r-- 1 username www-data 278 Apr 16 11:31 test.wsgi
Does anyone have suggestions on where to look for other configuration that may be affecting this, or any other debugging tips?
What's odd is that I have set up another (Django) application with mod_wsgi that is currently working in the same VirtualHost, but obviously I'm missing something in this test.
This was resolved by updating the <VirtualHost *:443> configuration file to include the WSGIScriptAlias line (as the server uses SSL), instead of having WSGIScriptAlias under the <VirtualHost *> configuration.
I wasn't aware that all Aliases needed to be included in the 443 port to function, but eventually worked it out after playing with a vanilla Alias and locating which files they were defined in with:
grep -R "Alias" /etc/apache2/*
Good day
Im trying to install a GamePanel with PHP called Swiftpanel on my VPS Centos7 64bit
i installed LAMP on my vps and html files work perfectly.
But my gamepanel doesnt work
and the gamepanel is located at:
http://51.255.199.40/gpanel/
as you can see when i try reaching my gpanel it gives me the SERVER ERROR 500
i looked at my apache error logs and this is what i get:
[Fri Mar 04 15:53:53.533162 2016] [autoindex:error] [pid 18753] [client 46.99.59.98:51034] AH01276: Cannot serve directory /var/www/html/: No matching DirectoryIndex (index.html,index.php) found, and server-generated directory index forbidden by Options directive
Here is my httpd.conf and php.conf:
http://pastebin.com/HJfH3gWQ
I need some help fixing this, im a begginer in coding.
With respect
Benjamin Selmani
In httpd.conf, try changing the line:
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
to
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
and restart Apache.
OK, edit your httpd.conf file and change the following line:
Options Indexes FollowSymLinks
to:
Options +Indexes +FollowSymLinks
then restart your Apache server. If this doesn't work, it's likely we are editing the wrong httpd.conf file. You'd be surprised how many you might find on your computer including all the conf files in sub directories (look at the last line of your httpd.conf file). Somewhere there is probably a line that looks like this:
Options -Indexes
Which is the explicit cause of the problem. But try my earlier suggestion first.
In Magento CE, I'd like to install an add-on to Extendware Page Cache called Lightening Cache.
It requires editing the Apache configuration inside the virtual host definition for the site, by adding:
RewriteEngine On
RewriteMap ewpchash prg:/home/.../shell/extendware/ewpagecache/apache/md5.php
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{REQUEST_URI} !\.(js|css|png|jpg|jpeg|ico|gif)$ [NC]
RewriteCond %{DOCUMENT_ROOT}%{SCRIPT_FILENAME} !-f
RewriteCond ${ewpchash:%{HTTPS};~;%{HTTP_HOST};~;%{REQUEST_URI};~;%{QUERY_STRING};~;%{HTTP:Cookie};~;%{SCRIPT_FILENAME};~;%{REMOTE_ADDR};~;%{HTTP_USER_AGENT}} -f
RewriteRule ^(.*)$ ${ewpchash:%{HTTPS};~;%{HTTP_HOST};~;%{REQUEST_URI};~;%{QUERY_STRING};~;%{HTTP:Cookie};~;%{SCRIPT_FILENAME};~;%{REMOTE_ADDR};~;%{HTTP_USER_AGENT}} [NC,L]
<FilesMatch "\.(html)$">
Header unset Cache-Control
Header unset Expires
Header append Expires "Thu, 19 Nov 1981 08:52:00 GMT"
Header append Cache-Control "must-revalidate"
</FilesMatch>
I have added this to the bottom of /etc/apache2/sites-enabled/site.conf.
When I run the command apachectl graceful, I receive the error:
AH00526: Syntax error on line 53 of
/etc/apache2/sites-enabled/site.conf: Invalid command 'Header',
perhaps misspelled or defined by a module not included in the server
configuration Action 'graceful' failed. The Apache error log may have
more information.
Site is running Apache 2.4
Have I done something wrong?
In order to use Header directive in apache you have to load mod_header module.
You can test if module is loaded or not by :-
apache2ctl -M | grep headers_module
find / -name mod_headers.so
If it is loaded you will see something like :-
headers_module (shared)
/usr/lib/apache2/modules/mod_headers.so
If you see no output of find command than load that module directly in your apache conf file. Just append below line :-
LoadModule headers_module modules/mod_headers.so
Note :- mod_header is available as base module in apache. So you don't need to install it explicitly.
Issue following command :-
a2enmod headers
Restart web service
apache2ctl restart
If someone is experiencing this error on a dockerized apache, the solution was only add this to my Dockerfile
RUN a2enmod headers
This was the error log:
[Fri Oct 21 17:39:55.384761 2022] [core:alert] [pid 19] [client 172.17.0.1:57480]
/var/www/html/page1/.htaccess:
Invalid command 'Header', perhaps misspelled or defined by a module not included in the server configuration
And the error:
And the .htaccess:
Header add X-Custom "Custom Value"
Solution
Here my complete Dockerfile:
FROM php:8.0-apache
RUN a2enmod rewrite
RUN a2enmod headers
COPY src/ /var/www/html
EXPOSE 80
After the fix:
i searched sth about this a lot but solutions doesnt help so much.I tried to upgrade redmine to 2.6.5 on my FreeBSD but i have 403 error.
apache error log:
[autoindex:error] AH01276: Cannot serve directory
/usr/local/www/redmine/public/: No matching DirectoryIndex (none)
found, and server-generated directory index forbidden by Options
directive
my httpd conf:
<VirtualHost example.com:80>
DocumentRoot "/usr/local/www/redmine/public"
ServerName example.com
FastCgiServer /usr/local/www/redmine/public/dispatch.fcgi -idle-timeout 120 -initial-env RAILS_ENV=production -initial-env PATH=/usr/local/bin -processes 2
<Directory "/usr/local/www/redmine/public">
AddHandler fastcgi-script fcgi
Order allow,deny
Allow from all
AllowOverride all
Options +FollowSymLinks +ExecCGI
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi
</Directory>
ErrorLog /logs/error.log
</Virtualhost>
i have to say: if i add +Indexes in Option i see files in my browser, so i guess premissions are good.
Anyone can give me any hint?
thanks in advance 4 your help
In my situation the problem was caused by a bug in the apache module ModAutoIndex. Disabling the module did the trick.
See https://serverfault.com/a/731859
Disabling the module auto index (which is the cause of the wrong behaviour, will prevent the error.
#LoadModule autoindex_module modules/mod_autoindex.so
Phusion will address the issue in the realase of Passenger 5.0.22 before Apache 2.5.0 will be released.
I suffered the same issue on my ArchLinux installation with Apache 2.4 and Redmine 2.6.5. Instead of fcgi I use the Phusion Passenger web application server but I always ended up on a 403 Forbidden page like you when accessing the server.
With the +Indexes option I also got the contents of the Redmine public directory on the browser.
When using webrick or passenger directly to host Redmine everything was fine. That's how you can verify your Redmine is not corrupted somehow. From the Redmine root directory run:
bundle exec ruby scripts/rails server -e production
Since I'm using RVM to manage ruby versions and gemsets on the system I can also tell you that the behavior is not related to ruby ( I tried every version from 1.8.x to 2.2.x without any change ).
In the end I substituted Apache with nginx 1.8.0 (stable release) and got Redmine back to work. So with passenger it's quite easy to get rolling. Just run
gem install passenger
so you get the passenger package. And then compile nginx with the passenger module using
passenger-install-nginx-module
You'll get an automated dialog that downloads nginx and compiles it with the appropriate config. By default it will be installed to /opt/nginx
On ArchLinux you would rather use the ABS to get the PKGBUILD and add the following to the configure part
--add-module=$(passenger-config --nginx-addon-dir) \
That way you also get the systemd unit-file to start and stop nginx.service
Last but not least here's the nginx config I use to run Redmine:
server {
listen 80;
server_name redmine.example;
root /usr/share/webapps/redmine-2.6.5/public;
passenger_base_uri /;
passenger_app_root /usr/share/webapps/redmine-2.6.5;
passenger_document_root /usr/share/webapps/redmine-2.6.5/public;
passenger_enabled on;
passenger_ruby /usr/local/rvm/gems/ruby-1.9.3-p551#redmine/wrappers/ruby;
}
Using another webserver may be a daunting step but it took me less than 2 hours to get Redmine up and running with nginx compared to nearly 2 days of wasted time to figure out why the heck Apache didn't serve the webapp any more.
I am trying to use Passenger to deploy a rails app on Ubuntu with Apache. I've followed pretty much every guide I could find on configuring Passenger with Apache/Ubuntu. However, when I go to the site, I just see the actual file directories and not the running version of the application. If i switch to the /public directory I just see the public directory when I go to the site. I can start and stop the rails server by calling rails s without getting any errors, but still am not able to see the running version of the application. Does anyone ran into similar problems? Is there a good starting point anyone could suggest I look at? I'm not sure if the problem is with apache or passenger.
Apache config
LoadModule passenger_module /usr/lib/ruby/gems/1.9.1/gems/passenger-3.0.9/ext/apache2/mod_passenger.so
PassengerRuby /usr/bin/ruby
PassengerRoot /usr/lib/ruby/gems/1.9.1/gems/passenger-3.0.9
PassengerMaxPoolSize 10
<VirtualHost *:80>
ServerName http://www.myapp.com/
DocumentRoot /var/www/myapp/current/
<Directory /var/www/myapp/current/public>
Allow from all
</Directory>
When I restart apache, I get a message stating [Sun Nov 06 14:43:48 2011] [warn] module passenger_module is already loaded, skipping I'm not sure if this is an error or is normal.
Update
When I run find / -name 'mod_passenger.so' I get two locations:
/usr/lib/ruby/gems/1.9.1/gems/passenger-3.0.9/ext/apache2/mod_passenger.so
/usr/lib/apache2/modules/mod_passenger.so
Update 2
I have several passenger.config files
/etc/apache2/mods-enabled/passenger.conf
/etc/apache2/mods-available/passenger.conf
/usr/lib/ruby/gems/1.9.1/gems/passenger-3.0.9/debian/passenger.conf
Each of the passenger.conf files has the following:
<IfModule mod_passenger.c>
PassengerRoot /usr
PassengerRuby /usr/bin/ruby
</IfModule>
Try to put following in apache config file
<Directory /var/www/myapp/current/public>
Allow from all
#Add following line
Options +Includes -Indexes
</Directory>
You may have mod_passenger.so symlinked into your apache2/mods-enabled directory. This would account for the double import.
Run
a2dismod mod_passenger.so
to remove any symlink, then restart Apache.