Symfony 3 / Apache - Post request gives Error 500 - apache

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

Related

Apache forbidden access with Docker

I build this image on docker-compose.yml
version: '2'
services:
webserver:
build: ./docker/webserver
image: image_name
ports:
- "80:80"
- "443:443"
volumes:
- /Users/user_name/Sites/site:/var/www/html
And have this commands on Dockerfile
FROM php:7-apache
RUN apt-get update -y && apt-get install -y libpng-dev && apt-get
install -y libcurl4-openssl-dev
RUN docker-php-ext-install pdo pdo_mysql gd curl
RUN a2enmod rewrite
RUN service apache2 restart
BUT I get
Forbidden
You don't have permission to access / on this server.
Apache/2.4.10 (Debian) Server at localhost Port 80
when I go to localhost.
I work with Mac.
I have used the docker files to other project and all worked great.
what am I missing?
Log response
Cannot serve directory /var/www/html/: No matching DirectoryIndex
(index.php,index.html) found, and server-generated directory index
forbidden by Options directive
Looks like apache is not finding an index page to serve. Ensure your volume mapping is correct (enter the image with docker exec and check contents of /var/www/html folder). If your files are there, ensure that you have an index.html or index.php file for apache to be served.
If you change to apache document root to something non-standard outside of /var/www you will need to grant access in your vhost:
DocumentRoot /workspace/my-project
<Directory /workspace/my-project>
Require all granted
</Directory>

403 error on XAMPP change document root

I have installed XAMPP on Linux Mint. Got it running OK, then I wanted to change the htdocs folder location to another partition.
I made these changes to httpd.conf:
DocumentRoot "/media/alex/776FAD4B34B3CF0A/XAMPP htdocs"
<Directory "/media/alex/776FAD4B34B3CF0A/XAMPP htdocs">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
and also did:
cd /media/alex/776FAD4B34B3CF0A
sudo chmod -R 777 "XAMPP htdocs"
but I keep getting a 403 error, despite restarting Apache.
Any suggestions please!
Thanks
This looks pretty much exactly like your problem, doesn't it? :)
What's probably missing is this (assumung that your Apache is running under www-data):
sudo adduser <username> www-data
sudo chown -R www-data:www-data /media/alex/776FAD4B34B3CF0A
sudo chmod -R g+rw /media/alex/776FAD4B34B3CF0A
Eventually that won't be enough though and you gotta go with
chown -R www-data:www-data
But that's more like your last resort...

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.

Share folders Docker

I'm used to develop on vagrant but docker looks faster so I just tried it. This seems really good but I need to share the folders between my host and docker to easily update my code without recompiling docker.
I tried to add:
VOLUME /Users/ajouve/dev/test/test:/var/www/test
or
VOLUME /Users/ajouve/dev/test/test:/var/www/test:rw
in my dockerfile but the folders are nos sync
This is my complete dockfile
FROM ubuntu:12.04
MAINTAINER ajouve version: 0.1
RUN apt-get update && apt-get install -y apache2 && apt-get clean && rm -rf /var/lib/apt/lists/*
RUN mkdir /var/www/test
VOLUME /Users/ajouve/dev/test/test:/var/www/test:rw
COPY test.conf /etc/apache2/sites-availables/
RUN ln -s /etc/apache2/sites-availables/test.conf /etc/apache2/sites-enabled/test.conf
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
EXPOSE 80
CMD ["/usr/sbin/apache2", "-D", "FOREGROUND"]
this is the test.conf
<VirtualHost *:80>
ServerName test.local
DocumentRoot /var/www/test
<Directory /var/www/test>
# enable the .htaccess rewrites
AllowOverride All
Order allow,deny
Allow from All
</Directory>
ErrorLog /var/log/apache2/test-error.log
CustomLog /var/log/apache2/test-access.log combined
</VirtualHost>
I have an empty folder when I'm trying to access to the server via a browser
You can bind the folder when you start your docker instance
with -v /src/dockerShared/:/usr/local/src
have a Look here for a example
Your host folder have to be owned by the same uid:gid of the folder inside the container.

/cgi-bin/printenv - doesn't execute - outputs the script itself

I am trying to get cgi scripts working with a clean build of httpd-2.4.6 on SciLinux 6 - x86_64.
My httpd.conf file: http://pastebin.com/P0CKYfqU
This is essentially the one that was installed - with a few edits.
I do have:
ScriptAlias /cgi-bin/ "/var/tmp/apps/cgi-bin/"
in the httpd.conf file.
I built httpd using the following configure command:
./configure --prefix=/var/tmp/apps --with-apr=/var/tmp/apps/bin/apr-1-config --with-apr-util=/var/tmp/apps/bin/apu-1-config --with-pcre=/var/tmp/apps/bin/pcre-config --enable-cgi
I have done the following to /var/tmp/apps/cgi-bin/printenv
edited the #! line
done chmod a+rx
The command works from the command line.
However, when I go to localhost:8001/cgi-bin/printenv I just see the script itself - not the output of the script.
I'm sure I must be missing a configure option or an httpd.conf directive.
It turrns out that in httpd-2.4.6 the mod_cgi module is not built or enabled by default.
Here is a build recipe which works:
Build httpd with there configure options:
configure \
--prefix=$TOP \
--with-apr=$TOP/bin/apr-1-config \
--with-apr-util=$TOP/bin/apu-1-config \
--with-pcre=$TOP/bin/pcre-config \
--enable-modules=all \
--enable-proxy \
--enable-proxy-http \
--disable-userdir \
--enable-cgi
And then in the httpd.conf file make sure the mod_cgi.so module is loaded:
LoadModule cgi_module modules/mod_cgi.so
To get the printenv cgi script to work, add the ExecCGI option to the options for the /cgi-bin/ directory:
<Directory "/var/tmp/apps/cgi-bin">
AllowOverride None
- Options None
+ Options +ExecCGI
Require all granted
</Directory>