File permission on Amazon EC2 with both Filezilla and Wordpress - wordpress

I can allow user ec2-user (Amazon AWS) write access to the public
web directory (/var/www/html):
sudo chown -R ec2-user /var/www/html
which allows me to use Filezilla.
And I can allow apache write access by:
sudo chown -R apache:apache /var/www/html
which allows me to install plugins, updates, etc on Wordpress.
How can I set the permissions to be able to do both?

Try the following:
Create a group
Add both users to that group
Make the group own the directory
Change the directory group permissions
sudo groupadd mygroup
sudo gpasswd -a apache mygroup
sudo gpasswd -a ec2-user mygroup
sudo chown -R apache:mygroup /var/www/html
sudo chmod -R g+w /var/www/html

Related

403 error on configuring new wordpress install

I am using Apache2 and ubuntu. Before my attempt to install wordpress on my server, i was able to open my domain in browser. But after the commands that i wrote below, i can not open it. When i browse my domain it is giving 403 error
Forbidden You don't have permission to access this resource.
I used the commands below while i was installing wordpress. And now, i am wondering how to fix this situation. And which files or other things should i check. Thank you.
First Commands That I Used For In My Terminal
wget http://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz
mysql -u root -p
CREATE DATABASE wordpress; Query OK, 1 row affected (0.00 sec)
CREATE USER wordpressuser#localhost; Query OK, 0 rows affected (0.00 sec)
SET PASSWORD FOR wordpressuser#localhost= PASSWORD("password"); Query OK, 0 rows affected (0.00 sec)
GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser#localhost IDENTIFIED BY 'password'; Query OK, 0 rows affected (0.00 sec)
FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec)
cp ~/wordpress/wp-config-sample.php ~/wordpress/wp-config.php
sudo nano ~/wordpress/wp-config.php
// ** MySQL settings - You can get this info from your web host ** // /** The name of the database for WordPress */ define('DB_NAME', 'wordpress'); /** MySQL database username */ define('DB_USER', 'wordpressuser'); /** MySQL database password */ define('DB_PASSWORD', 'password');
sudo rsync -avP ~/wordpress/ /var/www/
cd /var/www/
sudo chown username:www-data /var/www -R sudo chmod g+w /var/www -R
sudo apt-get install php5-gd
As These Commands Above Didnt Work for me I used Other Commands Below After Deleting Wordpress Directory
cd /var/www/html
sudo wget https://wordpress.org/latest.tar.gz
sudo tar xvfz latest.tar.gz
sudo chown www-data.www-data wordpress/
Those Commands Also Didnt Work For Me So I Added The Other Ones Below
sudo mkdir -p /var/www/html/example.com/src/
cd /var/www/html/example.com/src/
chmod 755 /var/www/html
chmod 750 /var/www
sudo chown -R www-data:www-data /var/www/html/example.com/
sudo wget http://wordpress.org/latest.tar.gz
sudo -u www-data tar -xvf latest.tar.gz
sudo mv latest.tar.gz wordpress-`date "+%Y-%m-%d"`.tar.gz
sudo mkdir /var/www/html/example.com/public_html/
sudo mv wordpress/* ../public_html/
sudo chown -R www-data:www-data /var/www/html/example.com/public_html
These are the access and error logs in my apache2. Which one should i paste?
access and error files in apache2
I replicated your steps on Ubuntu 20.04.3 LTS and it works fine. Here are my steps.
sudo su
apt install apache2
apt install mysql-server
wget http://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz
rsync -avP ./wordpress/ /var/www/html
cd /var/www/html
rm index.html
apt install php-mysql
mysql
mysql> CREATE DATABASE wordpress;
mysql> CREATE USER wordpressuser#localhost;
mysql> ALTER USER wordpressuser#localhost IDENTIFIED BY 'pass';
mysql> GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser#localhost ;
mysql> FLUSH PRIVILEGES;
systemctl restart apache2
If it doesn't work please paste your /var/log/apache2/error.log, your os-release and output of php -v.

Ho do I fixe permission denied when trying to upload a file to my wordpress server using file zila

please can anyone help with a solution? am getting an error message that says permission denied anytime I try to upload files to my (LEMP) server using File Zila. I have tried changing the file permission in File Zilla to 777 but still does not work.
if you have SFTP then follow below steps:
sudo chmod -R o+rw /var/www/html /* Location for folder or file */
chmod -R 755 /var/www/html/ /* Location for folder or file */
If you are trying to give the {user} as well as the www-data both access to the website directory try this
//without {}
sudo usermod -a -G www-data {userName}
#This adds user to www-data group
//set permissions for user group www-data
sudo chgrp -R www-data /var/www/html
//followed by
sudo chmod -R g+w /var/www/html
this will enable {user} to use SFTP with the FileZilla or other programs to read and write files in the directory without sudo

Amazon AWS EC2 Openlitespeed Permissions for SFTP

I setup SFTP on the EC2 Instance with Openlitespeed via Filezilla and it connects but I could not upload, delete or move files.
I then tried the solution suggested on this post:
Amazon AWS Filezilla transfer permission denied
So for UBUNTU,
sudo chown -R ubuntu:ubuntu /var/www/html
sudo chmod -R 755 /var/www/html
This solved that problem but now wordpress is asking for FTP details to install a plugin and the config.php and .htaccess is no longer writable (enabling/disabling litespeed cache plugin).
So this has reset the permission for wordpress as well. Does anyone have the solution how to fix the wordpress permissions on the server?
Thank you in advance.
you need to match the user that runs OLS/LSPHP
run grep -i "user" /usr/local/lsws/conf/httpd_config.conf to get the user that runs OLS , which I assume it should be www-data
then you need to chown -R www-data:www-data /var/www/html
after that, do :
find /var/www/html -type d -exec chmod 0755 {} \;
find /var/www/html -type f -exec chmod 0644 {} \;
to restore the file perm to 644, and dir perm to 755, as its previous status that ditrubted by your chmod -R 755 command.

Nginx permissions with wordpress

I am trying to set up wordpress on digitalocean with nginx. I am running into permissions issues though. When I upload a file or try to install a plugin I get the cannot create in directory warning. So I came across the post Here that says I need to give nginx access to the folder. So I executed the following:
sudo chown -R www-data:www-data /path/to/folder
sudo chmod -R 755 /path/to/folder
This works except now I cannot add and delete files with filezilla. Obviously because the permissions to the folder are no longer with the me the user they are now with www-data.
So my question is what is the correct way to configure nginx to work with wordpress and still allow me to upload and delete files with ftp.
When using digital ocean droplets you will probably be using sftp access to your server.
Try the following commands in your terminal when logged in.
Add your currently logged in user to the www-data group:
sudo usermod -aG www-data $USER
Then change your vhost directory and all files and subdirectories to be owned by www-data group:
sudo chown -R www-data:www-data /var/www
Set the proper permissions so you can upload files via sftp, manage files via command-line, and upload plugins and media directly in WordPress:
sudo chmod -R 774 /var/www
Hope this helps
Saskia

WordPress and Ubuntu, www-data and ubuntu for FTP

I'm using Amazon EC2. I'm on Ubuntu 16.04. I'm also using Apache 2. I have WordPress installed on my server.
I do:
chown -R ubuntu /var/www/html
so I can edit my files as ubuntu via FTP. But the problem is now WordPress cannot edit files, update, or upload any files via WordPress. But if I do:
chown -R www-data /var/www/html
then it works.
Any way I can make it work for both ubuntu and www-data at the same time, without always switching it?
Thanks!
I have done this before, exact same scenario.
You'll need a group with ubuntu and any other users in it, call it wordpress for instance.
# do this as root
groupadd vpsusers
gpasswd -a ubuntu wordpress
gpasswd -a www-data wordpress
etc....
then you want to use a base user (ubuntu) and the group as the owner of the folder.
# again as root
chown -R ubuntu:wordpress /var/www/html
final step make the group writable
# again as root
chmod -R g+w /var/www/html

Resources