Trouble Installing Nginx and php5-fpm on Debian 7.3 - php

I have a Debian 7.3 installation in a VM that I am practising installing Nginx and php5-fpm on. I got the Nginx working, by assigning it a manual port of :8080 and that points to /var/www/ for data and in that directory is an index.html and info.php file.
The config file for my Nginx is located at /etc/nginx/conf.d/default.conf and looks like this:
server {
listen 8080;
root /var/www;
index index.php index.html index.htm;
server_name localhost;
location / {
try_files $uri $uri/ /index.html;
}
location /doc/ {
alias /usr/share/doc/;
autoindex on;
allow 127.0.0.1;
allow ::1;
deny all;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/www;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
#fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
I have tried changing fastcgi_pass both ways:
fastcgi_pass 127.0.0.1:9000;
and also as:
fastcgi_pass unix:/var/run/php5-fpm.sock;
In my /etc/php5/fpm/pool.d/www.conf file I have the following configuration:
[www]
user = www-data
group = www-data
listen = 127.0.0.1:9000
;listen = /var/run/php5-fpm.sock
Here too, I have uncommented the line to match in the Nginx default.conf file.
In my php.ini file I have edited it so that it shows cgi.fix_pathinfo = 0 as required by most of the guides I have seen.
When I try to load nginx, it runs OK. When I try to run php5-fpm this is what happens:
root#debianx86:/# /etc/init.d/php5-fpm status
[FAIL] php5-fpm is not running ... failed!
root#debianx86:/# /etc/init.d/php5-fpm reload
[ ok ] Reloading PHP5 FastCGI Process Manager: php5-fpm.
root#debianx86:/# /etc/init.d/php5-fpm restart
[FAIL] Restarting PHP5 FastCGI Process Manager: php5-fpm failed!
root#debianx86:/# /etc/init.d/php5-fpm start
root#debianx86:/# /etc/init.d/php5-fpm status
[FAIL] php5-fpm is not running ... failed!
root#debianx86:/#
I then open up any of the browsers on my VM and point them to either 127.0.0.1:8080 or localhost:8080 and I get the custom index.html loading that I made and it works! So I then try to load theinfo.php file and I get presented with a 404 Not Found - nginx/1.4.4.
I don't understand what I'm doing wrong. Is there something I'm missing from all this?
I installed nginx from sudo apt-get -y install nginx and sudo apt-get -y install php5-fpm too. Any dependencies they required would have been installed along with that.
Is there a script that I can run on a fresh install of Debian 7.3 that someone has got that will install it properly for me, and make all the modifications so that nginx and php5-fpm are up and running? I've looked over many of the websites with the instructions and I seem to be doing pretty much everything they do, except for the default-sites and enabled-sites, as neither of those folders exist for me, and I don't want to run my virtual hosts like that. I will run them with their own servers listed in the default.conf file.
EDIT: I have even tried following this article at DigitalOcean and it still doesn't work.
EDIT #2: I also did chown -R www-data:www-data /var/www to ensure that the user and group match the information in the www.conf file. I also tried by changing it back to the original root:root specs too. Still nothing.

I think maybe port 9000 is already being used, so php5-fpm can't bind with that port and fails to start.
in the fpm pool settings swap the line of port 9000 with the line with the sock file, then try to start php5-fpm like you were doing, if it works then all you need is to update the nginx configuratuin to proxy pass to the sock file instead of the port.

Related

How to install latest phpmyadmin on ubuntu nginx server

I have installed phpmyadmin on ubuntu server using php81,
When i access the phpmyadmin on my browser I kept getting deprecation notice as shown below
Deprecation Notice in ./libraries/classes/Url.php#221
http_build_query(): Passing null to parameter #2 ($numeric_prefix) of type string is deprecated
I'm running ubuntu 20.04
Following lots of research, I found out that the only way out is to install phpmyadmin 5 which is currently the latest version
But the problem is that following this answer
sudo apt-get install phpmyadmin=5.1.1
Gives the following error
E: Version '5.1.1' for 'phpmyadmin' was not found
Is there anything I can do to get the latest phpmyadmin on my ubuntu server
As far as i can seee the latest version for phpmyadmin available for focal (Ubuntu 20.04) is 4.9.5: https://packages.ubuntu.com/focal/phpmyadmin
You could do any of the following:
Disable error reporting for notices in php so the notice doesn't come up(How do I turn off PHP Notices?)
Try to manually install the latest version of phpmyadmin(https://www.phpmyadmin.net/)
Install an older version of php and run phpmyadmin on that(https://www.digitalocean.com/community/tutorials/how-to-run-multiple-php-versions-on-one-server-using-apache-and-php-fpm-on-ubuntu-18-04)
Download and Install phpMyAdmin on Ubuntu 20.04
#sudo apt install phpmyadmin
press enter without apache2 lighttpd
You can use the following command to log into MariaDB server.
#sudo mysql -u root
show grants for phpmyadmin#localhost;
Create Nginx Server Block for phpMyAdmin
sudo nano /etc/nginx/conf.d/phpmyadmin.conf
server { listen 80; listen [::]:80; server_name pma.example.com; root /usr/share/phpmyadmin/; index index.php index.html index.htm index.nginx-debian.html;
access_log /var/log/nginx/phpmyadmin_access.log; error_log /var/log/nginx/phpmyadmin_error.log;
location / { try_files $uri $uri/ /index.php; }
location ~ ^/(doc|sql|setup)/ { deny all; }
location ~ .php$ { fastcgi_pass unix:/run/php/php7.4-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; include snippets/fastcgi-php.conf; }
location ~ /.ht { deny all; } }
enter code here
#sudo nginx -t
#sudo systemctl reload nginx
pma.example.com

How to setup up Laravel with Nginx on AWS linux AMI

I am trying to user laravel with nginx on AWS linux ami, however when I try to access my instance public ip i get file not found. Here is what i do
sudo amazon-linux-extras install nginx1
sudo service nginx start
After this step I am sure nginx is working because I can see nginx webpage. Now I am trying to install laravel
sudo amazon-linux-extras install php7.3
sudo yum install php-xml php-mbstring
sudo service php-fpm start
sudo service nginx restart
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
composer global require laravel/installer
export PATH=$PATH:/home/ec2-user/.config/composer/vendor/bin/
laravel new test
sudo vi /etc/nginx/nginx.conf
server {
listen 80;
server_name _;
root /home/ec2-user/test/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php-fpm/www.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
sudo chown -R apache:apache storage/
sudo chown -R apache:apache bootstrap/cache
When I try to load my page i recieve file not found.
You can fix this issue in 2 way:
Providing a valid server name/ Domain
Fixing Nginx Default IP address
Provide valid server name
You need to fix the server name inside your Nginx configuration you have putten the server name as _. You need to put there a valid domain name. For example:
server_name example.com;
Then create an A record of the domain pointing to the IP adress. For example:
example.com A 123.123.123.123
Fix Nginx Default configuration
By default, if you install Nginx the server IP takes the files from /var/www/html so you can find this issue in 2 way:
Upload the files in the default path
Change the Nginx default path
Upload the files in the default path:
1st delete the html folder under /var/www/
2nd uload your laravel files inside /var/www/
3rd rename your laravel project public folder to html
Now restart nginx and visit your ip
Change Nginx Default Path
Open the default file
sudo nano /etc/nginx/sites-enabled/default
Find root /var/www/html and replace the /var/www/html with your path
Restart nginx and then visit your IP

Configuration nginx 1.18 with php-fpm7.4

I want to run php under nginx, I have some difficulties. I'm almost done, however, I have an error 502, I don't know why.
I have Nginx 1.18, php 7.4.x with fpm. I created a php file in: /usr/share/nginx/html/info.php, however when I am on it, I have an error 502. Here is the file I have for the default conf:
server {
listen 80;
root /usr/share/nginx/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name localhost;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
I have seen this line in some cases, however when I do "nginx -t" it fails.
include snippets / fastcgi-php.conf;
I looked carefully, everything works locally, everything works. I do not understand.
In your post above you have server_name example.com. Check if you have the right server name there. Also, make sure your application server is running because nginx is unable to reach that's why you are seeing 502
The problem is having more than 1 config file in /etc/php/7.4/fpm/pool.d
usr#server:/etc/php/7.4/fpm/pool.d$ ls
www.conf foor-php-fpm.conf bar-php-fpm.conf.bak
Solution
Step 1: Remove or rename any other .conf files and leave only www.conf
usr#server:/etc/php/7.4/fpm/pool.d$ sudo mv other-php-fpm.conf other-php-fpm.conf.bak2
Step 2: systemctl restart php7.4-fpm.service
Done!
user#server:~$ systemctl status php7.4-fpm.service
● php7.4-fpm.service - The PHP 7.4 FastCGI Process Manager
Loaded: loaded (/lib/systemd/system/php7.4-fpm.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2020-12-31 16:16:22 UTC; 6s ago
Docs: man:php-fpm7.4(8)
Process: 381508 ExecStartPost=/usr/lib/php/php-fpm-socket-helper install /run/php/php-fpm.sock /etc/php/7.4/fpm/pool.d/www.conf 74 (code=exited, status=0/SUCCESS)
Main PID: 381487 (php-fpm7.4)
Status: "Ready to handle connections"
Tasks: 3 (limit: 4568)
Memory: 12.1M
CGroup: /system.slice/php7.4-fpm.service
├─381487 php-fpm: master process (/etc/php/7.4/fpm/php-fpm.conf)
├─381506 php-fpm: pool www
└─381507 php-fpm: pool www
This solution applies to php-fpm-7.2 as well.

Nginx virtual host not working

I'm hosting a PHP system on my localhost, I created index.php in the /var/www/html like this:
// /var/www/html/index.php
<?php
phpinfo();
And when I access localhost:80 it's showing up my PHP configurations info.
But when I cloned /etc/nginx/sites-available/default to /etc/nginx/sites-available/superstore and changed server_name it's not working after sudo service nginx restart, even sudo service nginx status is returning success.
My nginx config (/etc/nginx/sites-available/superstore) is like this:
server {
listen 80;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name superstore.dev;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
My PHP version:
Nginx status after restart:
I added this virtual host to my /etc/hosts like this:
127.0.0.1 superstore.dev
But when I try to access superstore.dev it's returning this error to me:
I installed PHP and Nginx by following command on Ubuntu 16:
sudo apt install nginx php7.0-fpm -y
And I'm sure that I already symbolic linked superstore config file to sites-enabled folder.
Why my virtual host is not working?
Similar to Apache config scheme, folder sites-available is supposed to contain all your config files, even the ones you don't want to run.
There is a second folder, sites-enabled, that contains symlinks to the config files you want to run.
To create the symlink run ln -s /etc/nginx/sites-available/superstore /etc/nginx/sites-enabled/ and then service nginx reload
For more info see answer https://serverfault.com/a/424456/240702

webserver process permissions problems on vagrant+nginx+php fpm

I have a vagrant box with a LEMP (linux, nginx, mariadb, php) stack for developing a webapp and I am currently having some issues configuring nginx and php-fpm. I am using puppet and puPHPet to provision the VM.
It seems that the combo php-fpm and nginx are unable to write files (ie. log files generated, assets published by the framework (yii2) etc).
This project worked just fine using apache instead of nginx, so I would discard a programming issue and I have been following the guidelines for nginx installation and still getting messages such as "The directory is not writable by the Web process" or "Permission denied" like errors.
As recommended I set /etc/php5/fpm/php.ini the option cgi.fix_pathinfo = 0.
nginx/sites-available/site.conf
server {
listen *:80;
server_name site.dev;
client_max_body_size 128M;
root /var/www/frontend/web;
index index.php;
access_log /var/log/nginx/test.access.log;
error_log /var/log/nginx/test.error.log;
location / {
root /var/www/frontend/web;
try_files $uri $uri/ index.php /index.php$is_args$args;
}
location ~ \.php$ {
root /var/www/frontend/web;
index index.html index.htm index.php;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param APP_ENV dev;
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
}
sendfile off;
}
php-fpm/www.conf
user = www-data
group = www-data
listen-owner = www-data
listen-group = www-data
listen-mode = 0660
I've seen other posts where listen-mode is commented out, I tried both methods and setting mode to 0666 but still no luck.
I tried also setting permissions from the out and the inside of the vagrant to 0777 over the folders that I know that the framework uses to write data but still no luck.
I have a very similar project at work configured just the same that it works but this one doesn't and I can't find the difference (in fact I took config files from this project to set up the new one after the first failed attempt).
ps aux | grep php
root php-fpm: master process (/etc/php5/fpm/php-fpm.conf)
www-data php-fpm: pool www
www-data php-fpm: pool www
Directories in the different projects seem to have the same permissions number yet onw eorks and the other doesn't.
I'm completely clueless! Ideas are very welcomed!

Categories