Why is there a problem with the configuration file for nginx - nginx

Please help me figure it out, I've been trying to solve this problem all day today. I am installing flash on an ubuntu server. I do everything according to the manual https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-uswgi-and-nginx-on-ubuntu-18-04-ru
I get to step 5. Up to this point, everything works. The test server starts on port 5000. Everything is OK. But I can't figure it out any further.
Creating a file myproject.service
[Unit]
Description=uWSGI instance to serve myproject
After=network.target
[Service]
User=norootuser
Group=www-data
WorkingDirectory=/home/norootuser/myproject
Environment="PATH=/home/norootuser/myproject/myprojectenv/bin"
ExecStart=/home/norootuser/myproject/myprojectenv/bin/uwsgi --ini myproject.ini
[Install]
WantedBy=multi-user.target
I don't understand what to do here, I did everything according to the instructions, but I get this error.

Maybe your project file permission is not correct
try both of these
chown -R www-data:www-data /home/norootuser/myproject
chmod -R 700 /home/norootuser/myproject
if not works let's try with root permission should probberly works
chown -R root:root /home/norootuser/myproject
chmod -R 700 /home/norootuser/myproject
Also try sudo too

Related

Missing a temporary folder error when uploading an image/media

I'm facing a Missing a temporary folder error in PHO version (native, 7.2).
I have already tried the bellow method:
define(‘WP_TEMP_DIR’,dirname(_FILE_). ‘/wp-content/temp/’);
but it had no result. Can you give me some solutions?
Add this code in the config
define('WP_TEMP_DIR', dirname(_FILE_) . '/wp-content/temp/');
then create the temp folder manually on wp-content folder :).
I've just had the same issue, there are some obvious solutions if you google about it...
In my situation that wasn't working. My setup was:
PHP 7.4.28
Ubuntu 20.4
Apache 2.4.41
WordPress 5.9.2
I came arround this and could finally resolve the error.
In short therms:
The apache2 / httpd systemd service uses PrivateTmp=true, its own version of the tmp dir. This is why wordpress couldn't find its "temporary folder" anymore.
I solved it by commenting out the respective entry in apache2.service:
(if you deeply care about security you might find another way to deal with it...)
[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=https://httpd.apache.org/docs/2.4/
[Service]
Type=forking
Environment=APACHE_STARTED_BY_SYSTEMD=true
ExecStart=/usr/sbin/apachectl start
ExecStop=/usr/sbin/apachectl stop
ExecReload=/usr/sbin/apachectl graceful
# PrivateTmp=true
Restart=on-abort
[Install]
WantedBy=multi-user.target
don't forget to:
reload deamon: sudo systemctl daemon-reload
restart apache: sudo systemctl restart apache2
...

Reverse a chown command

What I did
Last night while updating plugins on my Wordpress site my site crashed and I had to spin up a new server and restore from a Vaultpress backup. Once the restore had finished propogating I was unable to update the plugins so I ran the command
chown -R www-data:www-data /var/www/html/
I got the response
-bash: cd: /var/www/html: No such file or director
So after a bit of snooping I determined my directory path was off slightly. So, I ran
chown -R www-data:www-data /var/www/html/html.old
What happened
After running the chown command when I attempt to install plugin updates I get this in-browser error message:
Not Found
The requested URL /wp-admin/plugins.php was not found on this server.
Apache/2.4.29 (Ubuntu) Server at $domain Port 80
My question
Obviously I broke something when I ran the chown command, so how do I undo the command that I ran?
Any help would be very much appreciated
I don't think it's possible to revert the chown command unless you have a backup or know which file belongs to whom or all files belonged to a single user, which I doubt is the case here.

Symfony 4 file permissions of var directory change every time

I am setting up a new server and installed Ubuntu 18.04 in combination with Apache2. My project is stored in /var/www/project. In apache2.conf I added
<Directory /var/www/project/>
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
In my virtualhosts file I point to /var/www/project/public
When I go to the Ip address of my server I see my project and everything works, except one thing:
whenever I clear the cache with php bin/console cache:clear the permissions of my directory var are messed up which results in errors in the production environment.
I can fix this with:
chmod -R 777 var/
But the problem returns wheneven I clear the cache again. I tried with different users including root, but always the same problem. I do not understand what is causing this. In the documentation on file permissions it says:
In Symfony 3.x, you needed to do some extra work to make sure that your cache directory was writable. But that is no longer true! In Symfony 4, everything works automatically
Well not for me, but what could cause the problem?
The problem
The cache directory is owned by the user executing the cache:clear command.
Lets say your project files are owned by www-data.
Clearing the cache with root user
Cache is owned by root
www-data can't write in cache directory
Solution
execute cache:clear using the user owning the files.
Login as www-data: su www-data -s /bin/bash
clear the cache ./bin/console cache:clear
Depending on your settings, your www-data user may be different
The solution that worked for me (using Symfony 3.x and Ubuntu 18.04) is the one explained in the official site, here:
https://symfony.com/doc/3.4/setup/file_permissions.html#using-acl-on-a-system-that-supports-setfacl-linux-bsd
Maybe that solution work also with Symfony 4?
Extract:
3. Using ACL on a System that Supports setfacl (Linux/BSD)
Most Linux and BSD distributions don't support chmod +a, but do
support another utility called setfacl. You may need to install
setfacl and enable ACL support on your disk partition before using it.
Then, use the following script to determine your web server user and
grant the needed permissions:
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
Note:
The first setfacl command sets permissions for future files and
folders, while the second one sets permissions on the existing files
and folders. Both of these commands assign permissions for the system
user and the Apache user.
setfacl isn't available on NFS mount points. However, storing cache
and logs over NFS is strongly discouraged for performance reasons.
Personal hint:
sudo apt-get install setfacl may says "unable to find setfacl".
If so:
check if setfacl is present: setfacl -h
setfacl is part of the acl package, so install acl if missed
It took me quite a while to solve the problem in Symfony 4.4 that only was present in PROD but not in DEV. I still don't know what difference between PROD and DEV caused it, however. At least it's working now.
If ACL is present, the first solution in https://symfony.com/doc/4.4/setup/file_permissions.html#permissions-required-by-symfony-applications should work. I just manually set the HTTPDUSER since the given code returned the wrong one. Else, setting the permissions after every single cache:clear should do the job, too:
sudo chown -R "$local_user":"$webserver_group" "$app_dir/var/"
sudo chmod -R 0777 "$app_dir/var/"
Maybe you have to manually delete old files in var/ bevore first by rm -rf var/*

Docker nginx SELinux (centOS/RHEL) with 403 forbidden access

So my Dockerfile runs via docker-compose using:
Dockerfile
FROM nginx
#COPY conf
COPY myapp/ /usr/share/nginx/html
RUN chmod -R 664 /usr/share/nginx/html
RUN chown -R nginx /usr/share/nginx/html
RUN chcon -R -t httpd_sys_content_t /usr/share/nginx/html
This is on RHEL 6.x, Docker is old 1.7 or something as well.
I don't even need "run chmod/chown/chcon" for most environments!! The dockerfile works just fine on windows.
However, I still get 403 Forbidden errors whenever nginx tries to access ANY file in /usr/share/nginx/html.
What is the correct way to setup nginx in a docker container and avoid these SElinux problems? (SElinux is on "Enforcing")
In fact, if you do
RUN/CMD ls -l
we can see nginx is the user who owns that folder and it has the right permissions! So what the heck is going on?
Special circumstances related to old Docker 1.7.1 and RHEL6, means you gotta install RHEL7. SELinux does not work well with it. There are some core RHEL6 library issues (shared library permission errors) making it nearly impossible to use with Docker 1.7.1.
The labels are all wrong. the processes inside the image are init_rc_t type labels which are incorrect. The files can be changed to httpd_sys_content_t but it doesn't work.
I think also there may be some nginx:nginx (UID GID mismatching) issues.
But really, it's give up time. Not worth investing time in resolving it and my host provider wouldn't call RHEL6 to ask about it.

I can't reinstall symfony2

I am using symfony2 standard version, on linux mint 12.
I created a symfony2 project 2 days and everything went well, i installed a wrong bundle and messed up the project so i decided to delete the Symfony folder, and reinstall symfony.
And now, if i do php app/check.php i get the timezone error, although my timezone is set correctly, and the configuration page looks like this
i tried
rm -rf app/cache/*
rm -rf app/logs/*
and i tried
chmod -R 777 app/cache app/logs
could not fix it
Edit
php bin/vendors install --reinstall fixed the issue (Hakan Deryal thank you sir). However, I found out that if you rename the Symfony folder to symfony or any other name, you'll get the error, or everything goes normal but when you press Configure your Symfony Application online you'll get this error
Server error
The website encountered an error while retrieving http://localhost/mysite/web/app_dev.php/_configurator/. It may be down for maintenance or configured incorrectly.
Here are some suggestions:
Reload this webpage later.
HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.
So my next question is how to change of the symfony2 project , say you have 2 symfony2 project on localhost, they can't have the same name
Hi some time just clearing cache is not enough.
Event I came across the same type of problem, after clearing the cache, try to rebuild it.
commands are:
$ sudo php app/console cache:clear
$ sudo php app/console cache:warmup
$ sudo chmod 777 -R app/cache app/logs
The best way to set permission is to use ACLs:
sudo setfacl -R -m u:www-data:rwx -m u:`whoami`:rwx app/cache app/logs
sudo setfacl -dR -m u:www-data:rwx -m u:`whoami`:rwx app/cache app/logs
You could also try a chown www-data app/logs
Symfony reinstall at this point is not very relevant

Resources