I have a Docker setup that works well with Ubuntu, Nginx, PHP-FPM and MySQL.
WordPress can write to the uploads folder and I can edit templates online, but when I try to upgrade WordPress or plugins, it fails with:
Unpacking the update…
Could not create directory.: wordpress
Installation Failed
I have chmod 777 the entire WordPress folder, so I'm not sure if this is Docker or WordPress related. I have also checked various logs, but the only relevant line I found is this:
192.168.59.3 - - [01/Oct/2014:14:16:58 +0000] "POST /wp-admin/update-core.php?action=do-core-upgrade HTTP/1.1" 200 5576
"/wp-admin/update-core.php" "Mozilla/5.0
(Macintosh; Intel Mac OS X 10_10_0) AppleWebKit/537.36 (KHTML, like
Gecko) Chrome/37.0.2062.124 Safari/537.36"
Here's how I created the Docker environment:
brew install docker boot2docker
boot2docker init
# Allow VM access to our space
curl http://static.dockerfiles.io/boot2docker-v1.2.0-virtualbox-guest-additions-v4.3.14.iso > ~/.boot2docker/boot2docker.iso
VBoxManage sharedfolder add boot2docker-vm -name home -hostpath /Users
boot2docker up
Here's how I start the container:
docker run -p 80:80 --name wp -d -v ~/wordpress:/mnt/www:rw wp
Here's the Nginx configuration:
server {
listen 80; ## listen for ipv4; this line is default and implied
listen [::]:80 default ipv6only=on; ## listen for ipv6
root /mnt/www;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name localhost;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to index.html
try_files $uri $uri/ /index.php?q=$uri&$args;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/www;
}
# pass the PHP scripts to FastCGI server
#
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
It seems that some hacks are needed to be able to write to mounted volumes as other users than root. See https://github.com/boot2docker/boot2docker/issues/581
I do not have access of your Dockerfile, but for permissions problems with docker and WordPress to install plugins, templates or create folders you can use the command COPY with chown parameter in Dockerfile. Like below:
COPY [--chown=<user>:<group>] <src>... <dest>
For example, in my code runnig wordpress, I use:
COPY --chown=www-data:www-data ./app/ /var/www/html/
But you need had the last version of Docker to use chown parameter. A lot of people get the unknown chown parameter, this occurs because of Docker version. So before use chown I indicate to update your Docker.
Docker reference about COPY command: https://docs.docker.com/engine/reference/builder/#copy
Wordpress reference about permissions and www-data user: https://codex.wordpress.org/Changing_File_Permissions
Related
EDIT:
Ok, very strange still. It seems that it does not work on my main browser. In incognito browsers or just a completely new chrome window the sites now do work. I guess it has something to do with browser caching?
So I am hosting my website on Digital Ocean and I want to host multiple 'websites' on 1 droplet/server. By multiple websites, I mean different subdomains of my main domain. So I want to host admin.domain.com, dev.domain.com and test.domain.com on the same server. I followed this tutorial, but it is not working like expected. Currently, only 1 subdomain of the 3 is working...
What have I tried so far?
First of, I created 3 A records in my DNS all pointing to the same server_ip droplet on Digital Ocean.
I've created a different a different folder for each subdomain in the /var/www folder, each containing a html folder with a simple index.html file and some html:
The image above shows my /var/www folder.
I then used the following command sudo chmod -R 755 /var/www.
Next, I copied the default server block file and used this as the default for a new server block with the following command:
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/admin.domain.nl
I changed the contents of the file in all 3 config files for the 3 subdomains to the following (obviously changing the root to the specific subdomain aswell as the server_name):
server {
listen 80;
listen [::]:80;
root /var/www/admin.domain.nl/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name admin.domain.nl;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
}
I then used the following command: sudo ln -s /etc/nginx/sites-available/dev.domain.nl /etc/nginx/sites-enabled/ 3 times for the 3 different subdomains to 'enable' the server blocks.
This is my sites-enabled folder:
I've had no syntax errors and thus restarted nginx with: sudo systemctl restart nginx.
The problem
Now, for some very odd reason I do not understand, only the admin.domain.nl site is working. The other 2 subdomains simply display: This site can’t be reached.
What am I missing here?
IN /etc/nginx/nginx.conf
http {
# ...........................others contents.....................................
# in bottom
server {
listen 80;
root /var/www/html/cmp/api;
server_name "cmpapi.localhost";
index index.html index.php;
location / {
try_files $uri $uri/ $uri.html $uri.php =404;
}
}
server {
listen 80;
root /var/www/html/cmp/frontend;
server_name "cmp.localhost";
index index.html index.php;
location / {
try_files $uri $uri/ $uri.html $uri.php =404;
}
}
}
Here my project name is cmp. here 2 project
one is react frontend
another is laravel api project
Here 2 folder created in
/var/www/html/cmp/api
This assigned to http://cmpapi.localhost (server_name)
/var/www/html/cmp/frontend
This assigned to http://cmp.localhost (server_name)
cmd
sudo find /var/www/html/cmp/frontend/ -type f -exec chmod 644 {} \;
sudo find /var/www/html/cmp/frontend/ -type d -exec chmod 755 {} \;
sudo find /var/www/html/cmp/api/ -type f -exec chmod 644 {} \;
sudo find /var/www/html/cmp/api/ -type d -exec chmod 755 {} \;
systemctl reload nginx
Browser
http://cmpapi.localhost
http://cmp.localhost
I've tried since hours with lots of solutions but cannot get rid of this 403 error on serving a static subdomain with NGINX.
I've tried chmod all my permissions in the directory to the static folder and editing the config file over and over.
NGINX serves beautifully my reverse proxied Node app but shuts down all the static subdomains that once were in the server.
Permissions:
dr-xr-xr-x root root /
drwxr-xr-x root root home
drwx--x--x ca****8sh nginx ca****8sh
lrwxrwxrwx ca****8sh ca****8sh www -> public_html
drwxr-x--- ca****8sh ca****8sh public_html
drwxr-xr-x nginx nginx residenza******.******ano.ch;
config file:
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name residenza******.******ano.ch;
root /home/ca****8sh/www/residenza******.******ano.ch/;
location / {
#try_files $uri $uri/ =404;
index index.html;
#autoindex on;
#autoindex_exact_size off;
}
[continues with SSL setup]
I've also tried tweaking things around like enabling autoindex but to no avail.
I'm on despair, please help!
Check which user nginx is using in first line of nginx.conf. It should be either nginx or www-data. then run this command. Replace www-data with nginx if the user is nginx
chown -R www-data /home/ca****8sh/www/residenza******.******ano.ch/
If you are using SELinux like CentOS, run these commands too:
sudo setsebool -P httpd_can_network_connect on
chcon -Rt /home/ca****8sh/www/residenza******.******ano.ch/
I have handled by changing the global nginx user to a higher tier user. This is what was causing the permits issue.
I have set a nginx, php, mysql and phpMyAdmin on my laptop (running Arch Linux). Everything was ok till I tried to move the root in my home directory.
Here is the nginx configuration file I'm using:
server {
############### General Settings ###################
listen 80;
server_name localhost;
root /home/me/Development;
charset utf-8;
############## Document Root #####################
location / {
index index.php index.html index.htm;
autoindex on;
}
############## PHPMyAdmin #######################
#location /phpmyadmin {
# rewrite ^/* /phpMyAdmin last;
#}
############# Error redirection pages ################
error_page 404 NGINX/html/404.html;
error_page 500 502 503 504 NGINX/html/50x.html;
############## Proxy Settings for FastCGI PHP Server #####
location ~ \.php$ {
if ($request_uri ~* /phpmyadmin) {
root /usr/share/nginx/html;
}
try_files $uri =404;
#fastcgi_pass 127.0.0.1:9000; (depending on your php-fpm socket configuration)
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi.conf;
}
location ~ /\.ht {
deny all;
}
}
So I'm trying to make this "Development" folder - the folder where I will store all my php projects. And I want to keep phpMyAdmin in its default location.
Now i get 403 Forbidden if i try to access phpMyAdmin or any php file on the new location - error message:
2016/05/20 14:11:46 [crit] 5292#5292: *3 stat() "/home/me/Development/test.php" failed (13: Permission denied), client: 127.0.0.1, server: localhost, request: "GET /test.php HTTP/1.1", host: "localhost"
It should do something with the linux groups and rights but can't figure it out.
It's selinux, google disabling that or configuring it to allow what you need to do.
When your perms are set right and the logs show 'permission denied' it's selinux.
You are using HTTP to get your page. Now HTTP is returning you the error code '403' which according to RFC 2616 means "The server understood the request, but is refusing to fulfill it. Authorization will not help and the request SHOULD NOT be repeated."
The two possible reason for this error code
Authentication was provided, but the authenticated user is not permitted to perform the requested operation.
The operation is forbidden to all users. For example, requests for a directory listing return code 403 when directory listing has been disabled.
Try to check your file permissions. There is the solution.
I had a similar problem: I also got the 403 error code and tried to configure the rights of the file with chmod 777. Still the same result.
My problem was I started the nginx webserver with sudo nginx instead of starting it with my user and my rights. Just start the server with nginx without sudo and you should be fine.
I hope this helps someone.
check the owners and mode of the folder by using ls -l command if user is sudo then run this sudo chown -R yourusername:yourusername Development adn also run sudo chmod -R 777 Development
I have taken over the development of a few websites and am currently trying to get one hosted within a Vagrant box. I am very familiar with Vagrant but am having a strange issue that I have been unable to fix since last Friday.
I have created the Vagrant file and MYSQL database for the Wordpress installation has been moved to my local (host) machine and I point to this from the Wordpress installation on the guest machine. All the Wordpress files exist and the folder is being shared with the guest machine.
My Vagrant file looks as follows:
Vagrant.configure("2") do |config|
# Set Vagrant box to use
config.vm.box = "ubuntu/trusty64"
# Configure port forwarding
config.vm.network :forwarded_port, guest: 80, host: 8930, auto_correct: true
# Set synched folder
config.vm.synced_folder "./", "/var/www", create: true, group: "www-data", owner: "www-data"
# Configure the VM
config.vm.provider "virtualbox" do |v|
v.name = "St. David's Lab"
v.customize ["modifyvm", :id, "--memory", "1024"]
end
# Set up shell provisioning
config.vm.provision :shell, :path => "bootstrap.sh"
end
The boostrap.sh file is used to setup the required software and similar on the guest machine and looks as follows:
#!/bin/bash
echo "Provisioning virtual machine..."
apt-get update
echo "Installing Git"
apt-get install git -y > /dev/null
echo "Installing Nginx"
apt-get install nginx -y >/dev/null
echo "Configuring Nginx"
cp /var/www/nginx_vhost /etc/nginx/sites-available/nginx_vhost > /dev/null
ln -s /etc/nginx/sites-available/nginx_vhost /etc/nginx/sites-enabled/nginx_vhost
rm -rf /etc/nginx/sites-available/default
service nginx restart > /dev/null
echo "Updating PHP repository"
apt-get install python-software-properties build-essential -y > /dev/null
add-apt-repository ppa:ondrej/php5 -y > /dev/null
apt-get update > /dev/null
echo "Installing PHP"
apt-get install php5-common php5-dev php5-cli php5-fpm -y > /dev/null
echo "Installing PHP extensions"
apt-get install curl php5-curl php5-gd php5-mcrypt php5-mysql -y > /dev/null
apt-get install libapache2-mod-php5
And here is the server config that gets created on the guest machine:
server {
listen 80;
server_name localhost;
root /var/www/;
index index.php index.html;
# Important for VirtualBox
sendfile off;
location / {
try_files $uri $uri/ =404;
}
location ~* \.php {
include fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_cache off;
fastcgi_index index.php;
}
}
I have changed the siteurl in the Wordpress database to localhost:8930 as well.
The issue I am having is that when I try and access the address localhost:8930 (as defined in the port forwarding in my Vagrant file) I get redirected back to localhost default index page (http://localhost). It is not a cache issue as I have cleared this, used an incognito window and replaced the index file with a simple "hello world" and it shows.
Can anyone see why this may be happening?
Thanks
The $uri/ clause of the try_files directive is causing an external redirect to the default port. You probably want to avoid external redirects from nginx itself, because it over complicates your 8930 port mapping rule.
One solution is to remove the index directive and the $uri/ clause.
You really need to add a default controller for WordPress anyway, something like:
location / {
try_files $uri /index.php?$args;
}
EDIT:
Detailed analysis of the problem:
You present the URL http://localhost:8930 which is presented to nginx as http://localhost:80. The location / processes the request. The try_files directive tests for the existence of a file and a directory. The presence of a directory causes an external redirect to http://localhost:80/. The external redirect is an undocumented side-effect of the $uri/ clause.
The try_files directive is documented here.
I cannot find a way to setup php-fpm on nginx on Amazon AMI EC2 instance from scratch. I know this should not be that difficult, but finding different answers based on *nix versions is confusing.
Here are the condensed steps I've taken that I thought would work, but don't. Does anyone have a set of steps to reliably setup php-fpm with nginx in Amazon AMI EC2 instance?
I've intentionally left out nginx.conf, etc from this post since they are the "stock" installations from the default yum repositories.
nginx version: 1.6.2
Does anyone have reliable steps to setup php-fpm in nginx for Amazon AMI EC2 instances? I would prefer to setup myself instead of using the AMI in the Amazon marketplace that charges for this setup.
Thanks
# install packages
yum install -y nginx
yum install -y php56-fpm.x86_64
# enable php in nginx.conf
vi /etc/nginx/nginx.conf
# add index.php at the beginning of index
index index.php index.html index.htm;
# uncomment the php block in nginx.conf
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
# tell php-fpm to run as same account as nginx
vi /etc/php-fpm-5.6.d/www.conf
- change user and group apache to nginx
# allow nginx user to read website files since they are typically owned by root
cd /usr/share/nginx
chown -R nginx:nginx html
# check to see if php works - doesn't with these steps
echo "<?php phpinfo(); ?>" > /usr/share/nginx/info.php
# restart services since we changed things
service nginx restart
service php-fpm-5.6 restart
# verify root path exists and is owned by nginx as we said above
# ls -l /usr/share/nginx/html
-rw-r--r-- 1 nginx nginx 3696 Mar 6 03:53 404.html
-rw-r--r-- 1 nginx nginx 3738 Mar 6 03:53 50x.html
-rw-r--r-- 1 nginx nginx 3770 Mar 6 03:53 index.html
-rw-r--r-- 1 nginx nginx 20 Apr 14 14:01 index.php
# I also verified php-fpm is listening on port 9000 and nginx is setup that way in the nginx.conf
# port 9000 usage is the default and I left it as-is for this question, but I would prefer to use sock once I get this working.
Edit
This is what I see in the nginx error log
2015/04/14 17:08:25 [error] 916#0: *9 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream,
client: 12.34.56.78, server: localhost, request: "GET /index.php HTTP/1.1",
upstream: "fastcgi://127.0.0.1:9000", host: "12.34.56.90"
What do you see in nginx error log (/var/log/nginx/errors.log)?
Added after additional info (logs) provided:
To me it looks root should be server section not location.
server {
...
root /usr/share/nginx/html;
...
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
}
Where is your index.php file? If it is here:
/usr/share/nginx/html/index.php
then change this line
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
to:
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;