Deploy Laravel Project on Debian Server using Ngnix - linux

So I created an application with laravel, and now I try to host it in a Debian server.
I uploaded all the project laravel found in (/ var / www / html / site)
(site) is the folder that contains all the files app, public, .env ....
Just that there is also a mybb forum that is running in (/ var / www / html / board) and that's another dev who put it so I do not want to do any wrong manipulation that might make the forum down
So before I look how to start a Laravel project on Debian, and I followed the instructions from this tutorial, (Not all because I had for example already installed, PHP 7.3, phpmyadmin)
This is how i set ( sudo vim /etc/nginx/sites-available/mydomain.com )
server {
server_name mydomain.com mydomain.com;
listen 80;
root /var/www/html/site/public;
access_log /var/log/nginx/laravel-access.log;
error_log /var/log/nginx/laravel-error.log;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
and at the end i run this commund
sudo service nginx restart
i get this error
root#ns300976:~# sudo service nginx restart
Job for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xe" for details.
so next i try (systemctl status nginx.service) and i get this
root#ns300976:~# sudo service nginx restart
Job for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xe" for details.
root#ns300976:~# systemctl status nginx.service
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Wed 2019-11-13 06:37:35 UTC; 40s ago
Docs: man:nginx(8)
Process: 21913 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/F
Process: 21911 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, s
nov. 13 06:37:33 ns300976 nginx[21913]: nginx: [emerg] listen() to [::]:80, backlog 511 failed (98:
nov. 13 06:37:34 ns300976 nginx[21913]: nginx: [emerg] listen() to 0.0.0.0:80, backlog 511 failed (9
nov. 13 06:37:34 ns300976 nginx[21913]: nginx: [emerg] listen() to [::]:80, backlog 511 failed (98:
nov. 13 06:37:34 ns300976 nginx[21913]: nginx: [emerg] listen() to 0.0.0.0:80, backlog 511 failed (9
nov. 13 06:37:34 ns300976 nginx[21913]: nginx: [emerg] listen() to [::]:80, backlog 511 failed (98:
nov. 13 06:37:35 ns300976 nginx[21913]: nginx: [emerg] still could not bind()
nov. 13 06:37:35 ns300976 systemd[1]: nginx.service: Control process exited, code=exited status=1
nov. 13 06:37:35 ns300976 systemd[1]: Failed to start A high performance web server and a reverse pr
nov. 13 06:37:35 ns300976 systemd[1]: nginx.service: Unit entered failed state.
nov. 13 06:37:35 ns300976 systemd[1]: nginx.service: Failed with result 'exit-code'.
lines 1-17/17 (END)
next i try (journalctl -xe) and i get this
root#ns300976:~# journalctl -xe
nov. 13 06:59:12 ns300976 sshd[22318]: Failed password for root from 112.85.42.89 port 41078 ssh2
nov. 13 06:59:14 ns300976 sshd[22318]: Failed password for root from 112.85.42.89 port 41078 ssh2
nov. 13 06:59:15 ns300976 sshd[22318]: Received disconnect from 112.85.42.89 port 41078:11: [preaut
nov. 13 06:59:15 ns300`enter code here`976 sshd[22318]: Disconnected from 112.85.42.89 port 41078 [preauth]
nov. 13 06:59:15 ns300976 sshd[22318]: PAM 2 more authentication failures; logname= uid=0 euid=0 tty
nov. 13 07:01:01 ns300976 sudo[22331]: root : TTY=pts/1 ; PWD=/root ; USER=root ; COMMAND=/usr/s
nov. 13 07:01:01 ns300976 sudo[22331]: pam_unix(sudo:session): session opened for user root by root(
nov. 13 07:01:01 ns300976 systemd[1]: Starting A high performance web server and a reverse proxy ser
-- Subject: L'unité (unit) nginx.service a commencé à démarrer
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- L'unité (unit) nginx.service a commencé à démarrer.
nov. 13 07:01:01 ns300976 nginx[22340]: nginx: [emerg] listen() to 0.0.0.0:80, backlog 511 failed (9
nov. 13 07:01:01 ns300976 nginx[22340]: nginx: [emerg] listen() to [::]:80, backlog 511 failed (98:
nov. 13 07:01:02 ns300976 nginx[22340]: nginx: [emerg] listen() to 0.0.0.0:80, backlog 511 failed (9
nov. 13 07:01:02 ns300976 nginx[22340]: nginx: [emerg] listen() to [::]:80, backlog 511 failed (98:
nov. 13 07:01:02 ns300976 nginx[22340]: nginx: [emerg] listen() to 0.0.0.0:80, backlog 511 failed (9
nov. 13 07:01:02 ns300976 nginx[22340]: nginx: [emerg] listen() to [::]:80, backlog 511 failed (98:
nov. 13 07:01:03 ns300976 nginx[22340]: nginx: [emerg] listen() to 0.0.0.0:80, backlog 511 failed (9
nov. 13 07:01:03 ns300976 nginx[22340]: nginx: [emerg] listen() to [::]:80, backlog 511 failed (98:
nov. 13 07:01:03 ns300976 nginx[22340]: nginx: [emerg] listen() to 0.0.0.0:80, backlog 511 failed (9
nov. 13 07:01:03 ns300976 nginx[22340]: nginx: [emerg] listen() to [::]:80, backlog 511 failed (98:
nov. 13 07:01:04 ns300976 nginx[22340]: nginx: [emerg] still could not bind()
nov. 13 07:01:04 ns300976 sudo[22331]: pam_unix(sudo:session): session closed for user root
nov. 13 07:01:04 ns300976 systemd[1]: nginx.service: Control process exited, code=exited status=1
nov. 13 07:01:04 ns300976 systemd[1]: Failed to start A high performance web server and a reverse pr
-- Subject: L'unité (unit) nginx.service a échoué
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- L'unité (unit) nginx.service a échoué, avec le résultat failed.
nov. 13 07:01:04 ns300976 systemd[1]: nginx.service: Unit entered failed state.
nov. 13 07:01:04 ns300976 systemd[1]: nginx.service: Failed with result 'exit-code'.
this is the first time I have been working with Linux and looking for solutions I have suspected the apache2 which blocks the port 80
but by doing a kill process, I'm afraid to affect the forum because I do not know if it uses Apache2 for its functions
if I have to run my application via Apache, I would like to have your advice then on this
Thanks for help !

After root /var/www/html/site/public; add this
index index.php index.html index.htm index.nginx-debian.html;
I think your apache is running.check this in wchich port which is running
sudo netstat -ntpl
then kill that process
sudo kill pid(your pid)

Related

NGINX error after 'sudo systemctl status nginx' - Failed with result 'exit-code'

After trying to add new domains do my ubuntu 20.04 cloud server with nginx and pm2,I created a server block in
'/etc/nginx/sites-available/mydomain.ar'
and did the same thing into
'/etc/nginx/sites-enabled/mydomain.ar'
The next step was to do a link to both files with
ln -s /etc/nginx/sites-available/cloud.ktsoftware.ar /etc/nginx/sites-enabled/cloud.ktsoftware.ar
got a error that files already existed
ln: failed to create symbolic link '/etc/nginx/sites-enabled/mydomain.ar': File exists
in consequence i run to forced the link
sudo ln -sf /etc/nginx/sites-available/cloud.ktsoftware.ar /etc/nginx/sites-enabled/cloud.ktsoftware.ar
everything appears ok, no error response after that. Then i do
sudo systemctl status nginx
and got this error:
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sun 2022-07-10 13:47:17 -03; 17min ago
Docs: man:nginx(8)
Process: 1287489 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)
below first error paragraph
Jul 10 13:47:17 vps-2421400-x systemd[1]: nginx.service: Succeeded.
Jul 10 13:47:17 vps-2421400-x systemd[1]: Stopped A high performance web server and a reverse proxy server.
Jul 10 13:47:17 vps-2421400-x systemd[1]: Starting A high performance web server and a reverse proxy server...
Jul 10 13:47:17 vps-2421400-x nginx[1287489]: nginx: [emerg] open() "/etc/nginx/sites-enabled/mydomain.conf" failed (2: No such file or directory) in /etc/n>
Jul 10 13:47:17 vps-2421400-x nginx[1287489]: nginx: configuration file /etc/nginx/nginx.conf test failed
Jul 10 13:47:17 vps-2421400-x systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
Jul 10 13:47:17 vps-2421400-x systemd[1]: nginx.service: Failed with result 'exit-code'.
Jul 10 13:47:17 vps-2421400-x systemd[1]: Failed to start A high performance web server and a reverse proxy server.
lines 1-14/14 (END)
"lines 1-14/14 (END)" *
and crashed everything i think.
What is the best way to link the domains server blocks?

Nginx start failed - how I can repair that problem?

I'm a little bit newbie. I've got started server few months ago. Everything was okay but now on server I can't even echo something. How Can I repair nginx server?
My debian
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 10 (buster)
Release: 10
Codename: buster
root#debian:/home/maly#
and nginx version
nginx version: nginx/1.14.2
that's my status for nginx
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Drop-In: /etc/systemd/system/nginx.service.d
└─override.conf
Active: failed (Result: exit-code) since Sat 2021-11-06 19:34:43 CET; 17min ago
Docs: man:nginx(8)
lis 06 19:34:41 debian nginx[17186]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address al
lis 06 19:34:41 debian nginx[17186]: nginx: [emerg] bind() to [::]:80 failed (98: Address alrea
lis 06 19:34:42 debian nginx[17186]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address al
lis 06 19:34:42 debian nginx[17186]: nginx: [emerg] bind() to [::]:80 failed (98: Address alrea
lis 06 19:34:42 debian nginx[17186]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address al
lis 06 19:34:42 debian nginx[17186]: nginx: [emerg] bind() to [::]:80 failed (98: Address alrea
lis 06 19:34:43 debian nginx[17186]: nginx: [emerg] still could not bind()
lis 06 19:34:43 debian systemd[1]: nginx.service: Control process exited, code=exited, status=1
lis 06 19:34:43 debian systemd[1]: nginx.service: Failed with result 'exit-code'.
lis 06 19:34:43 debian systemd[1]: Failed to start A high performance web server and a reverse
and there's my try to start a nginx
Job for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xe" for details.
The error states to [::]:80 failed, which means that another process on your system is already using port 80. A port can only be occupied by a single process simultaneously, which means you will either have to
close the process running on port 80 (there‘s several ways on how to check which process is using that port, google it for your OS) or
start using Nginx on another port 80 (which is not recommended, since webservers usually run on port 80).

Gunicorn is failing to start with code=exited, status=203/EXEC

Gunicorn works when testing with 0.0.0.0:8000 but failing with the production version below.
Tried switching user:group to myproject:myproject, root:nginx, myproject:nginx nothing working
sudo systemctl status gunicorn
● gunicorn.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Sun 2020-08-30 08:49:57 PDT; 5s ago
Process: 5576 ExecStart=/var/www/myproject/public_py/env/bin/gunicorn --access-logfile - --workers 3 --bind unix:/var/www/myproject/public_py/myproject.sock myproject.wsgi:application (code=exited, status=203/EXEC)
Main PID: 5576 (code=exited, status=203/EXEC)
Aug 30 08:49:57 myprojecthost systemd[1]: Started gunicorn daemon.
Aug 30 08:49:57 myprojecthost systemd[1]: gunicorn.service: Main process exited, code=exited, status=203/EXEC
Aug 30 08:49:57 myprojecthost systemd[1]: gunicorn.service: Failed with result 'exit-code'.
gunicorn.service
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=root
Group=nginx
WorkingDirectory=/var/www/myproject/public_py
ExecStart=/var/www/myproject/public_py/env/bin/gunicorn --access-logfile - --workers 3 --bind unix:/var/www/myproject/public_py/myproject.sock myproject.wsgi:application
[Install]
WantedBy=multi-user.target
Project lives in /var/www/myproject
cat /var/log/nginx/error.log
[crit] 1198#0: *51 connect() to unix:/var/www/myproject/public_py/myproject.sock failed (2: No such file or directory) while connecting to upstream, client: xx.xxx.xx.xxx, server: myproject.com, request: "GET / HTTP/1.1", upstream: "http://unix:/var/www/myproject/public_py/myproject.sock:/", host: "myproject.com"
stat /var/www/myproject/public_py/env/bin/gunicorn
File: /var/www/myproject/public_py/env/bin/gunicorn
Size: 243 Blocks: 8 IO Block: 4096 regular file
Device: fd01h/64769d Inode: 1066021 Links: 1
Access: (0775/-rwxrwxr-x) Uid: ( 0/ root) Gid: ( 984/ nginx)
Context: unconfined_u:object_r:httpd_sys_content_t:s0
Access: 2020-08-30 08:07:44.939754370 -0700
Modify: 2020-08-29 18:16:27.280494281 -0700
Change: 2020-08-30 08:46:09.047708570 -0700
SOLUTION:
nginx was being blocked via SElinux, to resolve change to permissive.

Apache2 fails to start Putty AWS Windows

I am trying to start a django project using an AWS EC2 linux server using putty on windows, however Apache2 is showing an error related to the fact that the address is already used as shown in the next code:
apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sat 2020-07-25 19:51:59 UTC; 2min 7s ago
Docs: https://httpd.apache.org/docs/2.4/
Process: 15022 ExecStart=/usr/sbin/apachectl start (code=exited, status=1/FAILURE)
Jul 25 19:51:59 ip-172-31-4-25 apachectl[15022]: AH00558: apache2: Could not reliably determine
the server's fully qualified domain name, using 127.0.0.1. Set the 'Serv
Jul 25 19:51:59 ip-172-31-4-25 apachectl[15022]: (98)Address already in use: AH00072: make_sock:
could not bind to address [::]:80
Jul 25 19:51:59 ip-172-31-4-25 apachectl[15022]: (98)Address already in use: AH00072: make_sock:
could not bind to address 0.0.0.0:80
Jul 25 19:51:59 ip-172-31-4-25 apachectl[15022]: no listening sockets available, shutting down
Jul 25 19:51:59 ip-172-31-4-25 apachectl[15022]: AH00015: Unable to open logs
Jul 25 19:51:59 ip-172-31-4-25 apachectl[15022]: Action 'start' failed.
Jul 25 19:51:59 ip-172-31-4-25 apachectl[15022]: The Apache error log may have more information.
Jul 25 19:51:59 ip-172-31-4-25 systemd[1]: apache2.service: Control process exited, code=exited,
status=1/FAILURE
Jul 25 19:51:59 ip-172-31-4-25 systemd[1]: apache2.service: Failed with result 'exit-code'.
Jul 25 19:51:59 ip-172-31-4-25 systemd[1]: Failed to start The Apache HTTP Server.
I already tried to verify the status of the network using the next code, but the failure still the same.
systemctl status apache2.service
I also tried to verify the service listening ports using the next code, and the output was:
bitnami#ip-172-31-4-25:~$ sudo netstat -ntlp | grep 80
tcp6 0 0 :::80 :::* LISTEN 15122/httpd
I would appreciate any recommendation on it.
Check Skype, if its running then close first and then start Apache service.
Skype also use port 80.

Gitlab ist overlaying all subdomains and even my entire nginx.config

I am pretty new in those server / cloud dev things.
So I rented a vServer and started playing around. First with nginx. I made my own config and all went well, getting the right html files on the right sub-/domains:
server {
listen 80;
server_name beispiel.de;
location / {
root /var/www/beispiel;
index index.html;
}
}
server{
listen 80;
server_name gitlab.beispiel.de;
location / {
root /var/www/beispiel/gitlab;
index index.html;
}
}
Then I wanted to run my own git repo via gitlab, and I installed it like shown this tutorial:
https://www.howtoforge.com/tutorial/how-to-install-gitlab-on-debian-8/#install-the-prerequisites
Gitlab is running smooth. But my problem is now, that it overlays all subdomains as well as the domain itself. My config I wrote earlier seems skipped by some kind of second nginx, installed with gitlab.
I tried to stop it by service nginx stop but as I tried to service nginx start again this was the response:
Job for nginx.service failed. See 'systemctl status nginx.service' and 'journalctl -xn' for details.
So I htop-ed and saw that nginx processes where still runnung. I killed them, but they always autostarted again.
systemctl status nginx.service
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled)
Active: failed (Result: exit-code) since Tue 2019-12-17 14:58:43 CET; 3min 48s ago
Process: 13257 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile
/run/nginx.pid (code=exited, status=0/SUCCESS)
Process: 1539 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited,
status=1/FAILURE)
Process: 1537 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited,
status=0/SUCCESS)
Main PID: 13321 (code=exited, status=0/SUCCESS)
Dec 17 14:58:40 v2201912109976104637.goodsrv.de nginx[1539]: nginx: [emerg] bind() to 0.0.0.0:80
failed (98: Address already...use)
Dec 17 14:58:41 v2201912109976104637.goodsrv.de nginx[1539]: nginx: [emerg] bind() to 0.0.0.0:80
failed (98: Address already...use)
Dec 17 14:58:41 v2201912109976104637.goodsrv.de nginx[1539]: nginx: [emerg] bind() to 0.0.0.0:80
failed (98: Address already...use)
Dec 17 14:58:42 v2201912109976104637.goodsrv.de nginx[1539]: nginx: [emerg] bind() to 0.0.0.0:80
failed (98: Address already...use)
Dec 17 14:58:42 v2201912109976104637.goodsrv.de nginx[1539]: nginx: [emerg] bind() to 0.0.0.0:80
failed (98: Address already...use)
Dec 17 14:58:43 v2201912109976104637.goodsrv.de nginx[1539]: nginx: [emerg] still could not bind()
Dec 17 14:58:43 v2201912109976104637.goodsrv.de systemd[1]: nginx.service: control process exited,
code=exited status=1
Dec 17 14:58:43 v2201912109976104637.goodsrv.de systemd[1]: Failed to start A high performance web
server and a reverse pro...rver.
Dec 17 14:58:43 v2201912109976104637.goodsrv.de systemd[1]: Unit nginx.service entered failed state.
Hint: Some lines were ellipsized, use -l to show in full.
I don't know what to do.
Can anyone help?
Kindly,
a noob :)
After hours of googling and trying I stumbled about this link in gitlab.rb file:
https://docs.gitlab.com/omnibus/settings/nginx.html#using-a-non-bundled-web-server
It explains how to use the by your own installed nginx web server instead.
This solved my problem.
From the error logs, it looks that Old Nginx process is already using the 80 port.
Try /etc/init.d/nginx stop or systemctl stop nginx or /usr/sbin/nginx -s stop to stop old process.

Resources