Apache giving "No such file or directory" error when trying to run cgi - apache

No such file or directory: AH01241: exec of '/usr/lib/cgi-bin/haml.cgi' failed
Is the main error I'm getting right now. Trying to run a custom CGI, the cgi currently works successfully on another server I have, but it seems I've overlooked some configuration option on this server.
I have the cgi-bin directory set to allow CGI execution:
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
I've set the perms of haml.cgi to 777, simply to eliminate any permission issue from being the problem:
root#jp:/usr/lib/cgi-bin# ls -lah
total 16K
drwxr-xr-x 2 root www-data 4.0K Aug 14 18:28 .
drwxr-xr-x 64 root root 4.0K Oct 28 2014 ..
-rwxrwxrwx 1 root www-data 505 Aug 14 18:20 haml.cgi
I have cgid enabled:
root#jp:/etc/apache2# ls mods-enabled/
access_compat.load alias.load authz_core.load autoindex.load deflate.load filter.load mpm_event.load setenvif.load
actions.conf auth_basic.load authz_host.load cgid.conf dir.conf mime.conf negotiation.conf status.conf
actions.load authn_core.load authz_user.load cgid.load dir.load mime.load negotiation.load status.load
alias.conf authn_file.load autoindex.conf deflate.conf env.load mpm_event.conf setenvif.conf
And my site itself is set up to exec cgi:
DocumentRoot /home/j/web/
DirectoryIndex index.haml index.html
<Directory "/home/j/web">
AllowOverride All
Allow from All
Options +ExecCGI
</Directory>
Am I missing anything here? Any idea why the CGI isn't running?

Ended up actually being my ruby installation that was giving me issues. Running the cgi directly showed me this:
root#jp:/usr/lib/cgi-bin# ./haml.cgi
bash: ./haml.cgi: /usr/bin/ruby: bad interpreter: No such file or directory

Related

Symfony 3 / Apache - Post request gives Error 500

I have a Symfony 3 API and I'm trying to register a user but I have an error 500 when executing a POST request (GET request works). It's probably a problem with my Apache configuration because I don't have any errors in my logs files. A var_dump('ok') at the top of my function also give me error 500.
My Apache configuration:
<VirtualHost *:80>
ServerName subscription.api.local
ServerAlias www.subscription.api.local
DocumentRoot /var/www/subscription_backend/web
DirectoryIndex /app.php
<Directory /var/www/subscription_backend/web>
AllowOverride None
Order Allow,Deny
Allow from All
FallbackResource /app.php
</Directory>
<Directory /var/www/subscription_backend>
Options FollowSymlinks
</Directory>
<Directory /var/www/subscription_backend/web/bundles>
FallbackResource disabled
</Directory>
ErrorLog /var/log/subscription-error.log
CustomLog /var/log/subscription-access.log combined
</VirtualHost>
Line added in my hosts file:
127.0.0.1 subscription.api.local www.subscription.api.local
My projet is in ~/Projects/subscription_backend directory and I use a symbolic to /var/www/subscription_backend :
sudo ln -s ~/Projects/subscription_backend /var/www/subscription_backend
Permissions of "~/Projects/subscription_backend directory":
Permissions of "/var/www/subscription_backend directory":
lrwxrwxrwx 1 www-data www-data 55 avril 19 21:45 /var/www/subscription_backend -> /home/khan/Projects/subscription_backend/
What's wrong with my configuration ? Why GET request works but not POST ?
Thx
Finally, i solved the problem.
First,fix permissions https://symfony.com/doc/3.3/setup/file_permissions.html:
cd ~/Projects/subscription_backend
rm -rf var/cache/*
rm -rf var/logs/*
HTTPDUSER=$(ps axo user,comm | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data [n]ginx' | grep -v root | head -1 | cut -d\ -f1)
sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:$(whoami):rwX var
sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:$(whoami):rwX var
composer install
Then install memcache extension:
sudo apt-get install memcached
sudo apt-get install php-memcached
sudo apt-get install php-memcache
sudo service apache2 restart
Clear cache:
bin/console c:c
bin/console c:c --env=prod

run lxr perl module as scripts under apache 2.4

I have been trying to get it right for the past couple of days, but could not. I am not a LAMP guy.
I installed Apache 2 from the default Ubuntu repositories. Here is the contents of the /etc/apache2 directory:
/etc/apache2$ ls
apache2.conf conf-enabled magic mods-enabled sites-available
conf-available envvars mods-available ports.conf sites-e
And here are the contents of the sites-enabled directory:
/etc/apache2/sites-enabled$ ls
000-default.conf
Here is what I added to 000-default.conf:
Alias "/lxr" "/usr/local/share/lxr"
<Location /lxr>
allow from all
Require all granted
</Location>
And here is the contents of the perl module at this link.
My problem is: when I visit the link http://localhost/lxr/source , I get it as a text file, it is not executed as a script.
How can I fix this?
Thank you!
You have first to install mod_perl on your system. If you are in a debian-like distribution, suche as ubuntu, you can use :
sudo apt-get install libapache2-mod-perl2
Then enable this module on apache :
sudo a2enmod perl
and restart the apache server
sudo service apache2 restart
You will also have to add some configuration such as :
PerlModule Apache::Registry
Alias /cgi-bin/ /usr/lib/cgi-bin
<Location /cgi-bin>
SetHandler perl-script
PerlHandler Apache::Registry
PerlSendHeader On
Options +ExecCGI
</Location>
Read this article for more information.

Perl scripts will not run in apache (Permission Denied) [duplicate]

This question already has answers here:
How do I configure Apache 2 to run Perl CGI scripts?
(8 answers)
Closed 8 years ago.
I have LAMP installed on Ubuntu 14.04.1.
I want to be able to run cgi scripts from all directories that are within my website. So I added this to /etc/apache2/apache.conf
<Directory /var/www/>
AddHandler cgi-script .cgi .pl
Options FollowSymLinks +ExecCGI
</Directory>
I also did this edit in /etc/apache2/mods-enabled/mime.conf
# To use CGI scripts outside of ScriptAliased directories:
# (You will also need to add "ExecCGI" to the "Options" directive.)
#
AddHandler cgi-script .cgi .py .pl
But now when i visit my script it says
You don't have permission to access /hello.pl on this server.
But I have chmodded and chowned the script.. in fact look...
ls -la hello.cgi
-rwxrwxrwx 1 www-data www-data 84 Jan 26 03:19 hello.pl
(Self answer by Banned_User moved from question body)
What I did was edit /etc/apache2/sites-enabled/www.example.com/ and add:
<Directory /var/www/www.example.com>
Options +ExecCGI
</Directory>

can you help me out touchy wordpress debian install?

I have installed WordPress 3.6.1 on Debian 6.0.8 (alongside with other websites) by following this tutorial https://wiki.debian.org/WordPress.
I keep strugling with wordpress asking for ftp Connection Information for theme or plugin updates.
Could you please help me setting the rights correctly ?
Looking forward to read from you
What I can to do
install/delete plugin
install/delete themes
What I can't do
display theme nicely unless I manually create the symbolic link to the files.
Posts I have read :
Can I install/update WordPress plugins without providing FTP access?
How do I know which linux user Wordpress uses for plugin installation
WordPress can't install themes
A general linux file permissions question: Apache and WordPress
apache and sftp permissions for wordpress automatic update in ubuntu
What I have tried
Set FS_METHOD to direct
in /etc/wordpress/config-mydomain.fr.php
define('FS_METHOD', 'direct');
Re assigh permissions :
admin#server01:/usr/share/wordpress$ find -type d -exec sudo chmod 755 {} \;
admin#server01:/usr/share/wordpress$ find -type f -exec sudo chmod 644 {} \;
admin#server01:/usr/share/wordpress$ ls -l
total 144
-rw-r--r-- 1 root root 395 8 janv. 2012 index.php
-rw-r--r-- 1 root root 7155 14 sept. 2013 readme.html
-rw-r--r-- 1 root root 4616 21 janv. 2013 wp-activate.php
drwxr-xr-x 9 root root 4096 19 mars 13:00 wp-admin
-rw-r--r-- 1 root root 271 8 janv. 2012 wp-blog-header.php
-rw-r--r-- 1 root root 3513 16 juil. 2013 wp-comments-post.php
-rw-r--r-- 1 root root 2381 13 sept. 2013 wp-config.php
-rw-r--r-- 1 root root 3177 1 nov. 2010 wp-config-sample.php
drwxr-xr-x 5 root www-data 4096 19 mars 13:00 wp-content
-rw-r--r-- 1 root root 2718 23 sept. 2012 wp-cron.php
drwxr-xr-x 10 root root 4096 19 mars 13:00 wp-includes
-rw-r--r-- 1 root root 1997 23 oct. 2010 wp-links-opml.php
-rw-r--r-- 1 root root 2408 26 oct. 2012 wp-load.php
-rw-r--r-- 1 root root 29751 23 juil. 2013 wp-login.php
-rw-r--r-- 1 root root 7715 3 mars 2013 wp-mail.php
-rw-r--r-- 1 root root 9990 21 févr. 2013 wp-settings.php
-rw-r--r-- 1 root root 22135 15 mai 2013 wp-signup.php
-rw-r--r-- 1 root root 3692 9 mai 2013 wp-trackback.php
-rw-r--r-- 1 root root 2722 4 mars 2013 xmlrpc.php
&
admin#server01:/var/lib/wordpress$ find -type d -exec sudo chmod 755 {} \;
admin#server01:/var/lib/wordpress$ find -type f -exec sudo chmod 644 {} \;
admin#server01:/var/lib/wordpress$ ls -l
total 4
drwxr-xr-x 8 www-data www-data 4096 20 mars 15:04 wp-content
Manually remove broken plugin
admin#server01:/var/lib/wordpress/wp-content/plugins$ sudo rm akismet
admin#server01:/usr/share/wordpress/wp-content/plugins$ sudo rmdir akismet/
Manually remove broken themes
admin#server01:/usr/share/wordpress/wp-content/themes$ sudo rmdir twentythirteen/
admin#server01:/usr/share/wordpress/wp-content/themes$ sudo rmdir twentytwelve/
&
admin#server01:/var/lib/wordpress/wp-content/themes/clear$ sudo rm *
admin#server01:/var/lib/wordpress/wp-content/themes$ sudo rmdir clear/
Manually define themes symbolic links that dont want to appear automatically
admin#server01:/usr/share/wordpress/wp-content/themes$ sudo ln -s '/var/lib/wordpress/wp-content/themes/clear' 'clear'
Restart ssh :
admin#server01:~$ sudo /etc/init.d/ssh restart
Restarting OpenBSD Secure Shell server: sshd.
Restart apache :
admin#server01:~$ sudo service apache2 reload
Reloading web server config: apache2apache2: Could not reliably determine the server's fully qualified domain name, using 92.243.##.### for ServerName
/etc/apache2/sites-available/fr.mydomain.www
<VirtualHost *:80>
ServerName mydomain.fr
ServerAlias www.mydomain.fr
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomain\.fr
RewriteRule $(.*)$ http://www.mydomain.fr$1 [R=permanent,L]
DocumentRoot /usr/share/wordpress/
DirectoryIndex index.php index.html
ErrorLog /var/log/apache2/wp-error.log
TransferLog /var/log/apache2/wp-access.log
<Directory /usr/share/wordpress>
Options -Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /wp/wp-content /var/lib/wordpress/wp-content/
ScriptAlias /wp /usr/share/wordpress/
<Directory "/var/lib/wordpress/wp-content">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
/etc/wordpress/config-mydomain.fr.php
<?php
define('DB_NAME', 'wordpress');
define('DB_USER', 'wordpress');
define('DB_PASSWORD', 'myPassword');
define('DB_HOST', 'localhost');
define('WP_CONTENT_DIR', '/var/lib/wordpress/wp-content');
define('FS_METHOD', 'direct');
?>
Apache seems to run as root
ps aux | grep apache
root 11565 0.0 0.7 227076 15040 ? Ss Mar19 0:03 /usr/sbin/apache2 -k start
root 23668 0.0 0.3 227212 7500 ? S 10:07 0:00 /usr/sbin/apache2 -k start
...
root 26875 0.0 0.3 227212 7500 ? S 12:50 0:00 /usr/sbin/apache2 -k start
admin 27111 0.0 0.0 9620 916 pts/1 S+ 13:18 0:00 grep apache
777*
I have tried to change /usr/share/wordpress/wp-content and /var/lib/wordpress/wp-content to 777 without success...and I know that is very very bad.
Maybe this is because of some weird behaviour of Wordpress: The check whether WP has write permissions creates a temporary file and compares the owner of that file (which will be the Apache process, www-data) to the result of getmyuid(). However, getmyuid() returns the owner of the running php file (wp-admin/update.php in this case) which is 0 (root) in the default install. Try to change the owner of this file to www-data, which made it work for me:
chown www-data:www-data /usr/share/wordpress/wp-admin/update.php

How to get Apache to follow symlink instead of downloading it?

I am just using the standard apache config file which mentions that it follows symlinks, but when I hit the url http://localhost/test it downloads the symlink file instead of following it. What config do I need to change to get apache to follow the symlink instead of downloading it?
This is an ls on the directory:
$ ls -al
total 10
drwx------+ 1 SYSTEM SYSTEM 0 Oct 20 10:55 .
drwx------+ 1 SYSTEM SYSTEM 0 Aug 26 12:27 ..
-rw-r--r--+ 1 me None 47 Oct 20 10:14 index.html
lrwxrwxrwx 1 me None 29 Oct 19 17:10 test -> /home/me/projects/test
This is in my apache config file:
<Directory "D:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
I figured out the problem. The symlink I was using was made using cygwin and it crossed drives/volumes. I found out that's not allowed in windows so I had to move the files to the same drive as apache and the link is now working.