AWS Elastic Beanstalk Apply configuration file on nginx server - php

I am trying to migrated my application in ebs because it was deprecated, my previous platform was:
PHP 5.6 running on 64bit Amazon Linux / 2.9.8
now i'm migrating to:
PHP 7.4 running on 64bit Amazon Linux 2 / 3.0.3
This platform uses the Nginx server instead of Apache.
I was able to deploy my application but the problem is that my .htaccess configuration file was deprecated as was my .ebextensions configuration file. so I have lost the settings I had for example to get clean urls and redirects from http to https.
I have tried to transform the apache configurations to Nginx by putting the respective configuration file but apparently they have no effect.
I have tried many test configurations and I have come to the conclusion that the platform is not reading the configurations that I put.
I have tried to try for example with this little configuration, which should allow me to list the "views" directory:
cleanurl.config
server {
location / views / {
autoindex on;
}
}
I have tried putting it in the following folders.
".ebextensions / cleanurl.config"
files:
"/etc/nginx/conf.d/cleanurl.conf":
mode: "000644"
owner: root
group: root
content: |
server {
location / views / {
autoindex on;
}
}
".platform / nginx / conf.d / cleanurl.config"
server {
location / views / {
autoindex on;
}
}
But I don't get results. I always get 403 Forbidden when I point to a folder. Please help.
Thanks in advance

After trying and trying I was able to solve it in the following way:
I put the file in this location
.platform/nginx/conf.d/elasticbeanstalk/cleanurl.conf
change my config file like this
location/views/ {
autoindex on;
}
and now everything works.

I have tried many test configurations and I have come to the conclusion that the platform is not reading the configurations that I put.
In the first case this is because the configuration files that you use are for Amazon Linux 1 (AL1). However, you environment is PHP 7.4 running on 64bit Amazon Linux 2 (AL2).
In your second attempt, you are using the config files in .platform/nginx/conf.d/ as you should. However, you are using *.config extension. This wrong extension and it should be:
cleanurl.conf
You still may have other issues, but the wrong extension could explain why the files are being ignored.

Related

index.php not loading from ubuntu server VM (nginx & sftp)

I'll try to be short as it can get bloated.
I set up an ubuntu server 20.04 VM on an Oracle vbox.
I installed nginx, php7.4, Xdebug 3.
I configured everything properly for remote debugging and sftp ( I use PHPstorm), I forwarded the ports and customized my local hosts file.Everything works except...
when loading HTTP://127.0.0.2 it loads the default nginx landing page.My index.php file is uploaded in the root /var/www/my_domain folder through sftp. I created the server block for my_domain.
Still won't work. I am new to this so I am missing something.
If you need more info please request.
Any help appreciated!
Vhost config ( server block in nginx) - php-projects being my current domain and containing index.php:
server {
listen 80;
listen [::]:80 ipv6only=on;
root /var/www/php-projects;
server_name php-projects www.php-projects;
location / {
try_files $uri $uri/ =404;
}
error_log /var/log/nginx/debug.log debug;
}
Network settings from Vbox:
PS. I have tried :
How to set index.html as root file in Nginx?
and
Rewrite rule for the root file in nginx?
with no success.
"I configured everything properly for remote debugging and sftp"
Please post your xdebug configuration.
"when loading HTTP://127.0.0.2"
From where ? Host machine or VM?
"My index.php file is uploaded in the root /var/www/my_domain folder
through sftp."
Please post your nginx vhost configuration
"I created the server block for my_domain"
Where? Post the path to the file where you have done this

Why is my PHP not autostarting with NginX on Windows 10?

I'm running a new install of Windows 10. I need to create a local testing environment for PHP. I've set up and run NginX/PHP servers on Ubuntu Linux before, but never on Windows. I've installed the NginX and PHP binaries for Windows.
After I've booted up and logged in, if I cd to C:\nginx and run nginx.exe, the Nginx server starts up and runs fine, and I get the "Welcome to NginX" screen at http://127.0.0.1.
Then, if I cd to C:\nginx\php and run php-cgi.exe -b 127.0.0.1:9000 -c c:/nginx/php/php.ini, the PHP server runs, and I can access http://127.0.0.1/php.info and get the output of php_info();. So it seems everything is installed okay.
My goal now, is to to have the PHP server autostart when I boot the machine. I downloaded the Non-Sucking Service Manager, and opened a command prompt in Administraror mode, and ran nssm edit nginx. I filled out the screens as follows:
Then I did the same for PHP:
However, while NginX seems to be starting at boot, PHP does not. After a boot, without manually starting anything at the command line, I get the NginX welcome screen. However, if I try to view the PHP info page, I get the following message:
Unable to connect
Firefox can’t establish a connection to the server at 127.0.0.1.
How do I get PHP to autostart on boot?
This is my nginx.conf file:
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type text/html;
sendfile on;
keepalive_timeout 65;
server {
#Uncomment and edit the line below if you want to use a custom domainname
#server_name your.domain.com;
listen 80;
root c:/nginx/html;
location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME c:/nginx/html/$fastcgi_script_name;
include fastcgi_params;
}
}
}
Your nginx.conf seems OK.
... However, while NginX seems to be starting at boot ...
I wouldn't trust NGINX welcome page, it most likely comes from cache. I also don't trust a service status Running unless there are nginx processes started by nssm.
In my tests both nginx and php services were not started properly.
I needed to set AppNoConsole=1 for both services to make them work.
According to the author(s) this is a known issue with Windows 10 Creators Update.
2017-04-26: Users of Windows 10 Creators Update should use prelease
build 2.2.4-101 to avoid an issue with services failing to start. If
for some reason you cannot use that build you can also set
AppNoConsole=1 in the registry, noting that applications which expect
a console window may behave unexpectedly.
You can change this setting via NSSM Service Editor GUI > Process > Console window. Just clear the checkbox and click Edit service. It's done.
The same operation can be done with commands too.
net stop php
net stop nginx
nssm set php AppNoConsole 1
nssm set nginx AppNoConsole 1
net start nginx
net start php

symfony + nginx + Plesk 12 - url rewriting not working fine

I have a symfony project with a lot of requests and users, so I decided to use nginx + php-fpm to get a bit more performance.
But my client wants to have plesk for server administration. So, I installed everything whats required (nginx, fpm, apache) and created the host instance in plesk. Now, the start page of the website works fine - but some child pages gives me a 404 error code directly from nginx, other child pages works.
All urls are rewritten (symfony default). I only renamed the symfony default index file of the web folder app.php to index.php.
My additional configuration in plesk is: nothing
edit: I use nginx 1.9.4 (delivered with ubuntu or plesk) and symfony 2.8
Try to add a following lines in "Apache & Nginx settings" > "Additional nginx directives" to your domain in Plesk:
if (!-f $request_filename) {
rewrite ^/(.*)$ /index.php last;
}

Silently install Apache with php and files

I am writing a C++ installer and want to have it perform the following tasks without user interaction:
Silently install an instance of Apache
Silently add PHP to said apache instance
Determine the DocumentRoot of the apache instance and copy a bunch of php files to that location
Currently I have it installing apache using this command: apache_2.2.6-win32-x86-no_ssl.msi /passive ALLUSERS=1 SERVERADMIN=admin#localhost SERVERNAME=localhost SERVERDOMAIN=localhost SERVERPORT=80. This silently installs apache with the specified settings and leaves the services automatically started. Perfect.
The problem is that after this I don't know how to get the DocumentRoot that Apache uses (it is by default C:\Program Files (x86)\Apache Software Foundation\Apache\htdocs on my test computer), so I don't know where to send the files. So I either need to:
Control the location of htdocs (preferable)
Find a way to dynamically grab the DocumentRoot
Thanks!
You'll need to parse the Apache/conf/httpd.conf file then change the DocumentRoot value to what location you want him to point at.
Find this
DocumentRoot ".*"
Change it to
DocumentRoot "Your Location"
To find the location of the httpd.conf knowing that the default installation folder of apache is Programe Files ...
Using the win 32 API
TCHAR pf[MAX_PATH];
SHGetSpecialFolderPath(
0,
pf,
CSIDL_PROGRAM_FILES,
FALSE );
http://msdn.microsoft.com/en-us/library/bb762204(VS.85).aspx
Then add \Apache Software Foundation\Apache\conf\httpd.conf to the program files folder to locate the httpd.conf file

Fresh Laravel install displays 403 Forbidden in Nginx

I have created a fresh Laravel application by using composer create-project command. Then I put all the folders and files in /usr/share/nginx/html/, which is the default document root for my nginx server. However everytime I runs the http://localhost, it keeps displaying 403 Forbiden. I tried creating a testing index.php (<? php_info();) and it worked fine.
I've read somewhere that I need to set the containing folder (/html), as well as the app/storage folder permission to 777 but still no luck.
Please help me. Thank you in advance.
Here is the nginx default.conf
Laravel projects serve from the <projectName>/public directory. Make sure your nginx config is set up to look there for your index file and NOT in your <projectName> folder only.
Would you edit your question and paste your server config there?
I think it may because index.php is not in the index file list. check these lines:
index index.html index.php;
or
try_files $uri $uri/ =404;
The accepted answer is correct - Laravel services from the public folder and you need to tell nginx to look there - but also a little vague if you're bumping up against this problem. When you create new sites on a Homestead installation by adding them to your .yaml file and using vagrant provision or vagrant up --provision, the created nginx conf file will need editing before Laravel will serve files correctly.
Go to your CLI, and enter Homestead using vagrant ssh or homestead ssh. It will ask for your password, which by default is "vagrant".
Once you're in the virtual machine, type the following commands:
sudo nano /etc/nginx/sites-enabled/your-site-name-here
Then add /public to the end of the existing root near the top of the file (it'll be something like /home/vagrant/projects/your-site to begin with and save in Nano (ctrl+s), then exit nano (ctrl+x).
Once you've exited Nano, restart nginx using sudo nginx -s reload. Your routing will now work!

Categories