How do I configure nginx to handle virtual paths (paths handled by Drupal) properly? - ddev

I have a virtual /xmlrpc.php route on my Drupal site. It's for legacy compatibility. With the default DDEV configuration, nginx returns "No input file specified." when I visit https://mysite.ddev.local/xmlrpc.php.
How can I make it ask Drupal to handle the request instead?

This answer assumes the use of DDEV 1.8.0+.
Create a new file in the nginx subfolder of your project's .ddev directory, e.g. .ddev/nginx/xmlrpc.conf. (The file can be named anything as long as it ends in .conf.)
Paste in the following:
# pass the PHP scripts to FastCGI server listening on socket
location = '/xmlrpc.php' {
try_files $uri #rewrite;
}
Run ddev start to recreate the web container.
This pattern, also used for things like handling /system/files paths (for Drupal private files), will prefer a real xmlrpc.php file if it exists, and otherwise will ask Drupal's index.php (and routing system) to handle the request.

Related

AWS Beanstalk config file not executing at deployment

After multiple fails to correctly deploy my Laravel app through Beanstalk I decided to follow the basic AWS tutorial on how to create a Laravel app and deploy it to Beanstack (in order to rule it out as a cause.)
It launched and so I then added the following endpoint in routes/web.php:
Route::get('/hello', function () {
return 'hi';
});
It failed.
I then discovered that Beanstalk switched its server from Apache to nginx just a couple of months ago! No mention of this in the Laravel tutorial despite it meaning that the two are no longer compatible in their default states.
After doing a bit of digging, I found a link to another AWS tutorial which apparently resolves the issues: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/platforms-linux-extend.html
The solution looked very simple: create a custom configuration file and store it in a .ebextensions directory called '.platform' (dot platform) which would be located in the app directory.
I created a custom file called laravel.config with the inside:
location / {
try_files $uri $uri/ /index.php?$query_string;
gzip_static on;
}
The path to the file is:
~/my-app/.platform/nginx/conf.d/elasticbeanstalk/
I re-deployed. The api still doesn't work...
I connected to the instance through SHH and noticed that the .platform directory isn't there. I guess this makes sense since it's only used at the point of deployment...
One apparent issue is the use of wrong extensions for your nginx config files.
The file should be *.conf, not *.config as shown in the docs.
A reason why your .platform folder is ignored, could be that you maybe have it in your .gitignore or .ebignore files.
Please note that even if you fix the extension, the configuration itself may be still incorrect, which I can't verify.

Install Laravel on dedicated server's subfolder

So I am having an issue with pushing a Laravel app to production on a dedicated server's subfolder.
Server is run on Apache.
Url I want to push my app would be subdomain.domain.com/project
The structure of my dedicated server is
.cpanel
...
-laravel
-app
-vendor
-...
-public_ftp
-public_html
-folder
-contents of laravels public directory
-ssl
I know that in order not to expose my hidden files I am required to install it in a root directory, but this is not an option because I will be having multiple projects running under subdomain.domain.com/project-1, subdomain.domain.com/project-2 and etc... and all will have a separate laravel installation.
I need a hand in order to achieve that, can anyone give me some advice?
Managed to do it myself, the problem was when i was creating a symlink, so instead i just moved contents of my public directory to public_html/project-1/ and changed index.php path to /../../laravel/
The thing was that I have done it originally but I didnt expect that permissions for storage need to be manually set, that solved my issue and laravel works.
ALWAYS CHECK ERROR LOGS :)
You can place your separate folders in your subdomain with no problem.
The important thing is that you need to point the browser to public/ folder under your laravel projects.
You can create a .htaccess file with the command below in root folder of each project and perform a redirect.
Place the following command in your .htaccess file:
RedirectMatch ^/$ /public/

Lets Encrypt Error "urn:acme:error:unauthorized"

I use Lets Encrypt and get error:
urn:acme:error:unauthorized :: The client lacks sufficient authorization :: Error parsing key authorization file: Invalid key authorization: malformed token
I try: sudo service nginx stop
but get error: nginx service not loaded
So I had a lot of trouble with this stuff. Basically, the error means that certbot was unable to find the file it was looking for when testing that you owned the site. This has a number of potential causes, so I'll try to summarize because I encountered most of them when I set this up. For more reference material, I found the github readme much more useful than the docs.
First thing to note is that the nginx service needs to be running for the acme authorization to work. It looks like you're saying it's not, so start by spinning that up.
sudo service nginx start
With that going, everything here is based on the file location of the website you're trying to create a certificate for. If you don't know where that is, it will be in the relevant configuration file under /etc/nginx which depends largely on your version of NGINX, but is usually under /etc/nginx/nginx.conf or /etc/nginx/sites-enabled/[site-name] or /etc/nginx/conf/[something].conf. Note that the configuration file should be listed (or at least it's directory) under /etc/nginx/nginx.conf so you might start there.
This is an important folder, because this is the folder that certbot needs to modify. It needs to create some files in a nested folder structure that the URL it tries to read from returns the data from those files. The folder it tries to create will be under the root directory you give it under the folder:
/.well-known/acme-challenge
It will then try to create a file with an obscure name (I think it's a GUID), and read that file from the URL. Something like:
http://example.com/.well-known/acme-challenge/abcdefgh12345678
This is important, because if your root directory is poorly configured, the url will not match the folder and the authorization will fail. And if certbot does not have write permissions to the folders when you run it, the file will not be created, so the authorization will fail. I encountered both of these issues.
Additionally, you may have noticed that the above URL is http not https. This is also important. I was using an existing encryption tool, so I had to configure NGINX to allow me to view the ./well-known folder tree under port 80 instead of 443 while still keeping most of my data under the secure https url. These two things make for a somewhat complicated NGINX file, so here is an example configuration to reference.
server {
listen 80;
server_name example.com;
location '/.well-known/acme-challenge' {
default_type "text/plain";
root /home/example;
}
location '/' {
return 301 https://$server_name$request_uri;
}
}
This allows port 80 for everything related to the certbot challenges, while retaining security for the rest of my website. You can modify the directory permissions to ensure that certbot has access to write the files, or simply run it as root:
sudo ./certbot-auto certonly
After you get the certificate, you'll have to set it up in your config as well, but that's outside the scope of this question, so here's a link.

How to run laravel 5.0 project on localhost without use php artisan serve

I have created a laravel 5.0 project with php artisan serve, now i need to know how to run laravel 5.0 project run without start php artisan serve, i have already browse lot of websites no one help me..
You need to change "server.php" to "index.php" then copy ".htaccess" from public to root directory.
See: https://stackoverflow.com/a/30053989/3948755
Laravel sever Folder is "public". There is an index.php so you can run you project from there.
Suppose if you using UbuntuOS then you have to create your local server in public directory. Suppose your folder name is laravel_test then go in that directory and run some thing like this
php -S localhost:8000 -t public
If you using windows then access public folder from URL.
localhost/laravel/public
Actually it's bad practise to access folder from URL but for local its good. You also can go with host entry. Just make sure that your target folder is "public" directory.
Normally you would have WAMP/XAMPP installed. You can access Laravel project like below
localhost/laravel/public
But this is not recommended. You should create Virtual host for example
laravel.local that pints to server-root/laravel/public.
this is how you create virtual host.
Or even better go for a Laravel Homestead .
How is your .htaccess file configured?
Try with localhost/laravel/public/index.php
Use http://localhost/projectName/public
It will be work. but in case if you have another Route and you can not access that Route and get the error like " Page Not Found " then please use the following command
sudo a2enmod rewrite
Now open the http://localhost/projectName/public/yourRoute
This is a little late but still applicable, what I like to do (using ubuntu 14.x+) is put my laravel project (let's say Project1) in my var directory, so it would be in /var/Project1, then symlink the public folder to somewhere in /var/www(+/html depending on apache version).
Symlink can be done something like this:
ln -s /var/Project1/public /var/www/html
This keeps your internal files off the grid so to speak, this is untested so if I've missed anything just comment and I will amend this post.
EDIT:
Obviously if your http root is /var/www/html you can put your project in /var/www/Project1
If you have access to xampp or wampp on your operating system you can more or less configure your virtual host like in the instruction below:
https://bestin-it.com/creating-virtualhost-on-your-local-computer-to-start-simple-index-php/
This instruction shows how to run it locally on your PC, but it works generally the same on any hosting portals. In most case in payed portals you have any web panels to configure your public folder that reference to /public folder in laravel folder's structure.

How to create different vhosts on nginx? (WINDOWS)

So far I'm using this configuration for a server block
server {
listen 80;
server_name mydomain.com;
root /D:/www;
}
But it's giving me this error
403 Forbidden
nginx/1.5.12
Apparently it's reading the vhost, but it's not reading the right directory.
How can I change the directory to whatever I want?
Not root, I want it specially on D:/www/my page
IMPORTANT: I'm using windows 7, so the root directory won't be like /var/user,
My directories are D:\www\mypage
So, how should I put in the nginx config file?
Use quotes:
root "D:/www/my page"
Omit the drive letter and try below directive to define document root of nginx in Windows OS.
root /www;
Or, if your configuration is on different drive try
root /d/www;
If directory name contains space, enclose the path in quotes.

Resources