Stopping "php-fpm" ( homebrew installation ) Mac OSX 10.8.2 - homebrew

I have managed to successfully install PHP-FPM using homebrew.
I have even configured my nginx.conf to work. However, whenever I do in the terminal:
$: php-fpm
I get the error :
[24-Jul-2013 19:58:34] ERROR: failed to open configuration file '/private/etc/php-fpm.conf': No such file or directory (2)
[24-Jul-2013 19:58:34] ERROR: failed to load configuration file '/private/etc/php-fpm.conf'
[24-Jul-2013 19:58:34] ERROR: FPM initialization failed
However, my nginx is working fine.
Here is the nginx.conf according to running Yii.
server {
listen 80;
server_name campusplugin;
set $host_path "/var/www/campusplugin";
root $host_path;
set $yii_bootstrap "index.php";
charset utf-8;
#access_log logs/host.access.log main;
location / {
index index.html $yii_bootstrap;
try_files $uri $uri/ /$yii_bootstrap?$args;
}
location ~ ^/(protected|framework|themes/\w+/views) {
deny all;
}
#avoid processing of calls to unexisting static files by yii
location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
try_files $uri =404;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(.*)$;
#let yii catch the calls to unexising PHP files
set $fsn /$yii_bootstrap;
if (-f $document_root$fastcgi_script_name){
set $fsn $fastcgi_script_name;
}
root /var/www/campusplugin;
include fastcgi.conf;
fastcgi_intercept_errors on;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fsn;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fsn;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
I am also not able to stop the php-fpm. I need to stop it as I have modified the php.ini a little bit. What is the method to do it??
service php-fpm restart
-bash: service: command not found
Where am I going wrong?
Even when I am typing : php-fpm -v I am getting :
php-fpm -v
PHP 5.3.15 (fpm-fcgi) (built: Aug 24 2012 17:45:59)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
However, it is showing the old php-fpm, as I had installed 5.4.

I used this guide for my set up:
https://web.archive.org/web/20161220083008/https://echo.co/blog/os-x-1010-yosemite-local-development-environment-apache-php-and-mysql-homebrew
And this command to restart my php-fpm:
brew services restart php56
If you don't have brew services, try installing it like this:
brew tap homebrew/services
In more modern versions, simply doing
brew services start php
brew services stop php
brew services restart php
would either start, stop or restart the php-fpm service.

Apple says: "The SystemStarter utility is deprecated."
But I found another great solution:
Put this in ~/Library/LaunchDaemons/: https://github.com/tarnfeld/osx-stack/blob/master/LaunchDaemons/org.php-fpm.plist
Change paths in this plist file according to your paths (e.g. my php-fpm executable is in /usr/sbin instead of /usr/local/sbin)
Put the following in a new file in /usr/sbin/ or /usr/local/sbin/
.
/#!/bin/sh
echo "Stopping php-fpm..."
launchctl unload -w /Users/<home-folder>/Library/LaunchDaemons/org.php-fpm.plist
echo "Starting php-fpm..."
launchctl load -w /Users/<home-folder>/Library/LaunchDaemons/org.php-fpm.plist
echo "php-fpm restarted"
exit 0
make sure that directory is in your $PATH
Now you can call 'php-restart' to restart php-fpm
(Thanks to another post)

If you use mac, You can checkout your php-fpm is running?
you can use this command:
php-fpm -t
Now, You can see the question! And how to resolve by this error info in
the command line!

I got it :
The method to do it was as follows :
1. To checkout php-fpm, use :
php-fpm php54-fpm
2. To stop the service, we have to use Apple's SystemStarter, like so :
SystemStarter php54-fpm restart

Related

Nginx Reverse Proxy To Docker Container Web Apps Giving 404

I just made a fresh Ubuntu desktop vm, threw docker on it, threw Nginx on it, and pulled and ran the container yeasy/simple-web:latest, and ran it twice with the commands
docker run --rm -it -p 8000:80 yeasy/simple-web:latest
docker run --rm -it -p 8001:80 yeasy/simple-web:latest
I went over to /etc/nginx/sites-available and created a new file localhost.conf with the contents
server {
listen 80;
location /chad {
proxy_pass http://127.0.0.1:8000/;
}
location /brock {
proxy_pass http://127.0.0.1:8081/;
}
}
I then created a symlink of the localhost.conf file at /etc/nginx/sites-enabled with the command
ln -s ../sites-available/localhost.conf .
This was all done as root.
When I curl localhost:8000 and localhost:8001 I get the correct webpage hosted in the docker container. When I curl localhost/chad or localhost/brock, I get an Nginx 404 error. I have not touched the default config for Nginx, and did not modify the Docker images
I am limited to using docker images and Nginx, so I cannot change technology stacks.
Not sure if you're already doing this but it's worth mentioning:
You need to reload or restart Nginx whenever you make changes to its configuration.
To reload Nginx, use one of the following commands:
sudo systemctl reload nginx
sudo service nginx reload
I ended up being able to host both my docker containers with Nginx on the host machine with the following config following the above instructions.
server {
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
listen 127.0.0.1;
server_name localhost;
location / {
try_files $uri $uri/ =404;
}
location /chad {
proxy_pass http://127.0.0.1:8000/;
}
location /brock {
proxy_pass http://127.0.0.1:8001/;
}
}

Issue with nginx config using docker

I'm start doing a little test using docker in order to set up my own server and I have a little bit issues.
I use the nginx-fpm image which have most of the services I need to set up my server.
This is my Dockerfile I did in order to set up a basic server. I built it perfectly without any issues and named it as nginx-custom-server.
Dockerfile
FROM "richarvey/nginx-php-fpm"
ADD /conf/simple-project.conf /etc/nginx/sites-available/simple-project.conf
RUN mkdir /srv/www/
RUN mkdir /LOGS/
RUN ln -s /etc/nginx/sites-available/simple-project.conf /etc/nginx/sites-enabled/simple-project.conf
RUN rm /etc/nginx/sites-enabled/default.conf
CMD ["/start.sh"]
I ran it using the following command via terminal.
docker run --name=server-stack -v /home/ismael/Documentos/docker-nginx/code:/srv/www -v /home/ismael/Documentos/docker-nginx/logs:/LOGS -p 80:80 -d nginx-custom-server:stack
In /srv/www folder I have a simple hello world php. I want make changes in my code on my local machine and sync it with docker container using the shared folder code.
The nginx logs are empty so I don't know what is wrong. I set up logs in my conf but nginx didn't create them so I think there is a problem with the general nginx conf I guess.
Here is the conf I'm using for my hello world. Also I mapped this server name in the hosts of the host machine.
simple-project.conf
server {
listen 0.0.0.0:80;
server_name simple-project.olive.com;
root /srv/www/simple-project/;
location / {
try_files $uri /index.php$is_args$args;
}
location ~ ^/index\.php(/|$) {
# the ubuntu default
fastcgi_pass /var/run/php-fpm.sock:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param APPLICATION_ENV int;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
location ~ \.php$ {
return 404;
}
error_log /LOGS/custom_error.log;
access_log /LOGS/custom_access.log;
}
EDIT : Error when I tried to access to the server inside docker's container.
bash-4.4# wget localhost:80 > /tmp/output.html
--2019-03-27 12:33:11-- http://localhost/ Resolving localhost... 127.0.0.1, ::1 Connecting to localhost|127.0.0.1|:80... failed: Connection refused. Connecting to localhost|::1|:80... failed: Address
not available. Retrying.
From what I can tell, there are two reasons why you can't access the server.
The first is that you don't forward any ports from the container to the host. You should include the -p 80:80 argument to your docker run command.
The second is that you're attempting to listen on what I assume to be the IP of the container itself, which is not static (by default). In the nginx config, you should replace listen 172.17.0.2:80; with listen 0.0.0.0:80;.
With these two modifications in place, you should be able to access your server.
A different approach (but not recommended) would be to start the container in with the --network=host parameter. This way, the host's network is actually visible from within the container. In this scenario, you would only need to set the nginx config to listen on a valid address.
However, if the problem persists, a good approach would be to run docker exec -it {$container_id} bash when the container is running and see if you can access the server from within the container itself. This would mean that the server is running correctly but from other reasons, the port is not being correctly forwarded to the host.

directory index of "..." is forbidden

I am trying to get phusion passenger and nginx running on Mac OSX. It has been very difficult.
I followed the instructions here exactly.
$ brew install nginx --with-passenger
$ brew info nginx --with-passenger
Then it tells me this:
To activate Phusion Passenger, add this to
/usr/local/etc/nginx/nginx.conf, inside the 'http' context:
passenger_root /usr/local/opt/passenger/libexec/src/ruby_supportlib/phusion_passenger/locations.ini;
passenger_ruby /usr/bin/ruby;
What's interesting about that is that is not the ruby my site uses. I use rvm and have generated a .versions.conf file:
rvm --create --versions-conf use ruby-2.1.2#core
Hence, when you cd to my root folder of site, you get the following:
$ rvm-prompt
ruby-2.1.2#core
So that is what I added to nginx.conf:
http {
...
passenger_root /usr/local/opt/passenger/libexec/src/ruby_supportlib/phusion_passenger/locations.ini;
passenger_ruby /Users/dviglione/.rvm/gems/ruby-2.1.2#core/wrappers/ruby;
Note that when I run passenger-config, it does give me a different location for locations.ini:
$ /usr/local/bin/passenger-config --root
/usr/local/Cellar/passenger/5.0.26/libexec/src/ruby_supportlib/phusion_passenger/locations.ini
I don't know which location is correct but I stuck with the one that it provided during the install. If I changed to the other location, I get a different issue: "This site can't be reached".
In nginx.conf, my server block looks like this:
server {
rack_env development;
listen 8080;
server_name mysite_development;
root /Users/myuser/projects/core;
access_log /Users/myuser/projects/core/log/nginx_access.log;
error_log /Users/myuser/projects/core/log/nginx_error.log;
passenger_enabled on;
}
I added the following to /etc/hosts:
127.0.0.1 mysite_development
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
The root directory has the following permissions:
$ ls -ld core
drwxr-xr-x 37 myuser CORP\Domain Users 1258 Oct 14 18:45 core
Yet, when I navigate to http://mysite_development:8080/, I get the following error in my nginx error log:
2016/10/14 18:52:23 [error] 90766#0: *1 directory index of
"/Users/myuser/projects/core/" is forbidden, client: 127.0.0.1,
server: mysite_development, request: "GET / HTTP/1.1", host:
"mysite_development:8080"
The problem is not with nginx itself because I created a test folder and put an index.html in there and then created a server block for that and the index.html successfully displayed in browser. So problem is either with Passenger or Rails.
Note if I add this to the server block:
location / {
root html;
index index.html index.htm;
}
Then I just get the 'Welcome to nginx!' page.
I even chmod 777 recursively on the entire directory and its files of the Rails app. Still get the 403 Forbidden error. It has to be a problem with Passenger.
How can I resolve this?
You need to explicitly specify, where actual Ruby code of a Rails application is located, using passenger_app_root directive, described in Passenger's documentaion.
More details in my full answer.

Ruby on rails nginx , unicorn, capistrano vps hosting error

Hi I am learning how to deploy rails application in VPS, I have followed https://coderwall.com/p/yz8cha this tutorial, and everything worked well, I got some errors and corrected them by searching the net, and all works correctly capistrano deploys the files and folders to VPS and if I am changing any code then after type cap deploy it will changed in VPS also, everything works fine there is no error shown in terminal, But the problem is the nginx server is not running (at initial stage it shows its index page -welcome to nginx), I dont know where may be ther problem occurs and what I have to do any help will be appreciated ,,I am using rails 4.1.4, ruby 2.1.2, capistrano (2.15.5) if its matters..
I dont know which code has to be shown here If you want to see any code I am eager to show you....This is my nginx.conf file
upstream unicorn {
server unix:/tmp/unicorn.projectname.sock fail_timeout=0;
}
server {
listen 80 default_server deferred;
# server_name example.com;
root /home/administrator/apps/testvps/current/public;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri #unicorn;
location #unicorn {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://unicorn;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 20M;
keepalive_timeout 10;
}
This is the error I got while nginx -t in VPS terminal
nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)
2014/08/01 15:40:35 [warn] 5682#0: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:1
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
2014/08/01 15:40:35 [emerg] 5682#0: open() "/run/nginx.pid" failed (13: Permission denied)
nginx: configuration file /etc/nginx/nginx.conf test failed
As per error shown by nginx -t, user don't have permission to write into nginx log files.
Try running nginx -t as root user sudo nginx -t, if still it shows permission error then try updating permissions:
sudo chown -R www-data:www-data /var/log/nginx;
sudo chmod -R 755 /var/log/nginx;
Edit:
As per our discussion, your nginx configuration is successfully set. Now you are seeing blank page while accessing the app.
You need to add root to your routes.rb file. Rails 4 don't have public/index.html file . So, you are seeing blank page. After setting root you will be able to see your home page.
Your further doubt:
so this is nginx.conf file
root /home/administrator/apps/testvps/current/public;
shall i change like this:
root /home/administrator/apps/testvps/current;
No, nginx should look to your public directory of the app. it's rails responsibility to navigate the request to root_path as mentioned in routes.rb

adding wordpress into site that was built in rails

I'm trying to add a Wordpress blog into a site that was built in ruby on rails. I just need it to be in a sub directory. I made a folder in the public directory and put the Wordpress files in there and now i'm getting a routing error and i'm really not that familiar with rails. Can someone help me figure out a way to do this?
You can get PHP and rails working in the same project if you have access to the server configuration. I was able to get things working on a test VPS in just a few minutes. I didn't test with wordpress, just a simple phpinfo() call, but I don't see any reason why it would fail.
My install uses NGINX for the web server, Unicorn for Rails, and spawn-fcgi and php-cgi for the PHP processing.
I already had a rails app working so I just added PHP to that. The rails app uses NGINX to proxy requests to Unicorn, so it was already serving the public directory as static. I will post my virtual host file below so you can see how it was done.
This was all done on an ArchLinux VPS, but other distros should be similar.
My virtual host file:
upstream unicorn {
server unix:/tmp/unicorn.jrosw.sock fail_timeout=0;
}
server {
listen 80 default deferred;
server_name example.com www.example.com;
root /home/example/app/current/public;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri #unicorn;
location #unicorn {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://unicorn;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/conf/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/example/app/current/public$fastcgi_script$
}
}
And then a small script to bring up php-cgi:
#!/bin/sh
# You may want to just set this to run as your app user
# if you upload files to the php app, just to avoid
# permissions problems
if [ `grep -c "nginx" /etc/passwd` = "1" ]; then
FASTCGI_USER=nginx
elif [ `grep -c "www-data" /etc/passwd` = "1" ]; then
FASTCGI_USER=www-data
elif [ `grep -c "http" /etc/passwd` = "1" ]; then
FASTCGI_USER=http
else
# Set the FASTCGI_USER variable below to the user that
# you want to run the php-fastcgi processes as
FASTCGI_USER=
fi
# Change 3 to the number of cgi instances you want.
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 3 -u $FASTCGI_USER -f /usr/bin/php-cgi
The only problem I had was getting the fastcgi_index option to work, so you'd probably need to look into nginx's url rewriting capabilities to get wordpress' permalink functionality working.
I know this method isn't ideal, but hopefully it gets you on the right track.

Resources