403 error on configuring new wordpress install - wordpress

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.

Related

How to Keep wp-content folder after releasing a new container?

I have a Wordpress instance on Azure App Service. I release it as an Azure Docker Container. I use a single DockerFile. My release process is working as expected but it's updating my wp-content folder after each release. I'm missing my new media files.
How can I secure them? Or can I download all media items via any plugins etc?
DockerFile
FROM wordpress:5.9.2-php7.3-apache
COPY html /var/www/html
# ssh
ENV SSH_PASSWD "root:Docker!"
RUN apt-get update \
&& apt-get install -y --no-install-recommends dialog \
&& apt-get update \
&& apt-get install -y --no-install-recommends openssh-server \
&& echo "$SSH_PASSWD" | chpasswd
COPY sshd_config /etc/ssh/
COPY init.sh /usr/local/bin/
RUN chmod u+x /usr/local/bin/init.sh
EXPOSE 8000 2222
ENTRYPOINT ["init.sh"]
init.sh
#!/bin/bash
set -e
echo "Starting SSH ..."
service ssh start
chown -R www-data:www-data /var/www/html/
chown -R www-data:www-data /var/www/html/wp-content/
chmod -R 775 /var/www/html/
chmod -R 775 /var/www/html/wp-content/
apache2-foreground
Thanks.

Cannot update plugin for WordPress on localhost on Mac

I'm running WordPress 5.8.1 on localhost, on my Mac. I am unable to update plugins. I get this error:
Update failed: Could not create directory.
I've tried changing the permission on the wp-content folder as suggested here like this:
sudo chmod -R 755 wp-content
but it didn't work. I still get the error message.
I also tried this
sudo chown -R _www wp-dir
sudo chmod -R g+w wp-dir
still no luck.
Ok, Managed to find the issue. Apache uses a different username so this command was ok:
sudo chown -R _www wp-dir
But my username wasn't _www (hence my error)
you can find the apache username in the etc/httpd.conf file

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

Docker Alpine nginx 403 Forbidden error for swagger-ui-builder

This happened on Ubuntu 16.04 in VirtualBox on Windows 10, with docker version 1.12.1, and swagger-ui version 2.2.2.
I was trying to build and run Swagger UI in a docker container, following the instructions on their site:
docker build -t swagger-ui-builder .
docker run -p 127.0.0.1:8080:8080 swagger-ui-builder
The instruction says that now I should be able to view the swagger-ui running, however, when I opened 127.0.0.1:8080 I only got this page back:
<html>
<head><title>403 Forbidden</title></head>
<body bgcolor="white">
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx/1.8.1</center>
</body>
</html>
This is the content of the Dockerfile:
FROM alpine:3.3
MAINTAINER Roman Tarnavski
RUN apk add --update nginx
COPY nginx.conf /etc/nginx/
ADD ./dist/ /usr/share/nginx/html
EXPOSE 8080
CMD nginx -g 'daemon off;'
I found similar posts on stackoverflow, but none of them helped me solve this problem. What am I doing wrong and how to fix this?
The problem was caused by a permission requirement: the www-data user/group did not have access to website's directory and files.
This problem was explained in the accepted answer to this post: Nginx 403 forbidden for all files
To solve this, the following lines have to be added to the Dockerfile:
RUN set -x ; \
addgroup -g 82 -S www-data ; \
adduser -u 82 -D -S -G www-data www-data && exit 0 ; exit 1
RUN chown -R www-data:www-data /usr/share/nginx/html/*
RUN chmod -R 0755 /usr/share/nginx/html/*
The upper part of the commands are explained in this gist: https://gist.github.com/briceburg/47131d8caf235334b6114954a6e64922
The user/group www-data has to be added first, before the permission can be set for it. The snippet notes that 82 is the standard uid/gid for "www-data" in Alpine
The lower part of the commands is the solution to a similar question in another forum: https://www.digitalocean.com/community/questions/nginx-403-forbidden--2
So the fixed Dockerfile would look like this:
FROM alpine:3.3
MAINTAINER Roman Tarnavski
RUN apk add --update nginx
COPY nginx.conf /etc/nginx/
ADD ./dist/ /usr/share/nginx/html
RUN set -x ; \
addgroup -g 82 -S www-data ; \
adduser -u 82 -D -S -G www-data www-data && exit 0 ; exit 1
RUN chown -R www-data:www-data /usr/share/nginx/html/*
RUN chmod -R 0755 /usr/share/nginx/html/*
EXPOSE 8080
CMD nginx -g 'daemon off;'
Now if I rebuild and rerun swagger-ui-builder, the website shows up correctly.

File permission on Amazon EC2 with both Filezilla and 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

Resources