I want to be able to use debugger inside docker container and i managed to map entry point of laravel's /public/index.php to path on nginx server inside container, breakpoint in index.php is being hit, but breakpoint in default route "/" in app/http/routes.php is not, although route's code is being executed. It's laravel 5.1 default folder structure.
Working path mapping for index.php is /var/www/laravel/public - C:\Users\username\Desktop\zemke2\public (server path - project path respectively)
Printscreen here:
I need help making mapping for "/" route's breakpoints to work.
After some wondering I succeeded to figure it out. It is quite simple. The point is you map FOLDERS and you map ABSOLUTE FILESYSTEM PATHS on server and local. Browser url is IRRELEVANT, it does not matter how you run your code.
Folder containing file (or files) you want to debug on server to local folder containing that file.
In my case those are:
server path: /var/www/laravel/public - local path: C:\Users\username\Desktop\zemke2\public
server path: /var/www/laravel/app/Http - local path: C:\Users\username\Desktop\zemke2\app\Http
Linux paths are case sensitive. Checking stop debugger on first line also helps debugging problems like this.
Related
I have a Laravel app running on XAMPP. I did point the VirtualHost directory at C:/xampp/htdocs/donor/public, which public in this case is Laravel's public folder.
However after I've tried changing the VirtualHost directory to C:/xampp/htdocs, and added the following alias, Laravel's seems not to see the full path of the app (which is http://domain.tld/donor), and recognise only the http://domain.tld/, making it point to invalid URL.
This make all the resources loaded from the wrong URL. Notice that there should be /donor/ in the red circle provided. (Such as, http://url.domain/donor/css/file.css becomes http://url.domain/donor/file.css)
The alias added is:
Alias "/donor" "C:/xampp/htdocs/donor/public"
How can I config this in Laravel so it does its job perfectly?
I am using Cakephp3 and would like to know if there is a better alternative to relocating the config folder.
The issue rises from the fact that everytime I have to refresh the production app, i copy over the entire app from development to production and reconfigure the required settings in the config folder.
After some iterations of this process, I started to make a backup of the config folder and after copying the app, restore the config folder.
After some time even this started to get tedious, so I ended up hacking the cake files and folders.
I relocated the config folder outside the root directory
Created a symbolic link in the root directory poiting to the config directory outside the root directory.
Updated the ROOT constant in config/paths.php to the real root folder
In webroot/index.php redefined the bootstrap.php require location
So as long as long as I dont update the cakephp core, I can copy over the dev app to the prod app and all the config stays the same.
I would like to know if some one has a simpler approach.
Thanks
After some research and reading carefully the comments in related bootstrap file, I found a solution for, well at least, my problem.
The problem basically was that I had to refresh the database, email, debug settings define in the app.php file, everytime I uploaded the app from my dev server to my prod server.
Reading the comments in the bootstrap file I found the comment which stated:
Load an environment local configuration file.
You can use a file like app_local.php to provide local overrides to your
shared configuration.
So this allows me to redefine the configurations defined in the app.php file. However I wanted this to me more dynamic, so I ended up creating an APP_INSTANCE_NAME constant in the bootstrap.php file of the webroot directory as follows
// /config/bootstrap.php
define('APP_INSTANCE_NAME', strtolower(gethostname()));
and later in the bootstrap file, i did the following:
Configure::load('app_' . APP_INSTANCE_NAME, 'default');
with this change, the configuration that gets loaded is based on the server hostname and I dont have to relocate the config folder. Hope this helps someone with cakephp3
Thanks to jason and greg's comments which motivated me to read the comments more carefully.
I'm trying to configure Netbeans 8 to upload and test a simple php project. Here is the relevant setup.
Required project url:
http://services.mydomain.com/index.php
In the Project Properties-> Run Configuration
Project url: http://services.mydomain.com
Index File: index.php
Location of index.php via FTP:
ftp://services.mydomain.com/public_html/services/
As you can see I'm starting the FTP upload from a different place in the directory structure.
On the server
FTP directory: ~/ (This is the initial directory for FTP)
Web directory: ~/public_html/services/
In my project I have the folder structure:
Source Files
-> config
-> public_html
--> services
----> index.php
I want to keep this setup so I can have some configuration setting outside the web directory in ~/config. Also I don't have admin on server so can't change the initial directories anyway.
The problem is Netbeans is doing validation on the Index File location it wants to see the public_html/services/ in the Index File field (because this is where it is in the project) This gives the URL:
http://services.mydomain.com/public_html/services/index.php
Which is wrong.
The error I am getting is "Index File must be a valid URL".
Does anyone know of a way to turn this validation off so I can manually set my own URLs.
I am using NetBeans 8.2, but this should work on earlier versions. Also, you can look at the following blog for Path Mapping, but I didn't need that.
To solve this:
Open the Project Properties dialog.
Select the Sources page.
In the Web Root directory path, click Browse...
Navigate to the directory that is your website root and click Select Folder. In my case it was the "public" directory in the Laravel project directory.
Click OK.
Hope this helps someone else.
I am using NetBeans 12.6. For my Laravel project I created New Project in NetBeans "PHP Application with Existing Sources".
My index file located in my-project/public/index.php
So, I defined in the last step of my project configuration in NetBeans:
Project URL: http://local.my-project.com/
Index File: public/index.php
The directory structure of my project is like this:-
/var/www/includes/
/var/www/classes/
/var/www/public/css/
/var/www/public/js/
/var/www/public/index.php
The webroot is /var/www/public, so accessing the test domain localhost.dev would serve the files inside the public directory and hence would run /var/www/public/index.php. No need to access like localhost.dev/public/index.php
The problem is when I create the project in Netbeans, I have to set the index file so that the project can be debugged using xdebug and Netbeans.
So when adding the project I provided /var/www as Project source folder (Sources Folder) as the includes and classes are in this folder. In the next project configuration screen (Choose Project > Name and Location > file path is taken as Run Configuration), I'm asked for the Project URL and the index file. Since the index.php file is actually under the /var/www/public/, when I browse the file and select it, the url to index page is taken as localhost.dev/public/index.php instead of just localhost.dev/index.php. This is preventing me from debugging the project.
Can anyone please point out how to add projects to Netbeans when all the source files are not in web root and the project is to be debugged using xdebug.
I think its a bad practice to put all the project files directly in /var/www.
I think you will never see that in real deployed projects. So my first recommendation will be to change the way you are structuring your project. If that's not possible, in Netbeans select /var/www/public as the Project folder.
If Netbeans need references to the folders in /var/www, create symbolic folders inside public pointing to those in /var/www.
The last resource you have is to create a rewrite rule in Apache to make localhost.dev/public be the same as localhost.dev. You can look for this in Apache documentation.
I have a similar set up with one minor difference: my setup uses a remote site on my local development server. On the "Run Configuration" window of the project properties, I set "Run As" to "Remote Web Site (FTP, SFTP)". I don't think this affects the information in my answer, but I'm mentioning it just in case.
Go to the "Sources" window of your project properties, find the entry for "Web Root", click "Browse" and select the /var/www/public directory. That should cause xDebug to use localhost.dev/index.php. You'll notice when you go to the "Run Configuration" window and browse for the Index File that the browse window will start in "public" rather than "www".
An important note about this type of configuration that caused me a great deal of frustration.
When using xDebug, you'll want to be able to set breakpoints in and work with the files outside of the web root (public) directory. Because you've set the web root to /var/www/public, you won't be able to work with the files in /var/www/includes or /var/www/classes.
The thing you need to do is to add the files outside of your web root to the Global Include Path.
There are two methods for adding directories to your Global Include Path, which one you use depends on how you've configured your project.
In your case, the external directories are included in your project, so you need to add them via the "Options" interface. Go to Tools->Options and select the "PHP" tab, then add the /var/www/includes and /var/www/classes folders to the Global Include Path.
The other method for adding files to the Global Include Path is for files that are located outside of your project source folder. For directories like /var/folder_outside_www/, you use the "PHP Include Path" window in the project properties.
I haven't found a better way but I use this steps:
Menu:Project Properties -> Link:Run Configuration -> Button:Advanced
Debug URL, choose: Ask Every Time
Path Mapping, Server Path: http://localhost.dev/ ,Project Path: /var/www/public/
Now, when you start Debugging process, Netbeans will display Specify URL pop-up which you can change from http://localhost.dev/public/index.php into http://localhost.dev/index.php
Set /var/www/public as project folder (contain netbeans project folder) and include in project properties /var/www/includes/ and /var/www/classes/ as global include directories. Or best way use PHPStorm.
I recently downloaded cakephp-1.3.4. I set it up on my web server. I followed the advanced installation settings. My folder structure is as follows.
/common/
cakephp/
app/
etc...
/htdoc/
The /htdoc folder is the webroot; cakephp resides in the common folder.
I have configured the paths in index.php to point to this folder structure. I have the app up and running. I created a layout, the app has picked it up (along with all the css and images - all that works).
I created a posts_controller.php in cakephp/app/controllers/. Now when I try to access the following page: http://localhost/posts. I get a message that the controller cannot be found and that I should create a app/controllers/posts_controller.php (it already exists!).
Also the strange thing is using the default pages_controller works. I created an about.ctp and dropped it in app/views/pages/about.ctp. Vising http://localhost/pages/about shows up as expected.
SOLUTION:
Sam helped me solve this problem (see the long comment thread below). The problem was I had set relative paths for my ROOT folder. This messed things up. The solution is to either directly set an absolute path or call realpath with your relative path for it to be resolved into the right absolute path.
Make sure your controller class is named correctly (should be PostsController) and inherits from AppController (not strictly necessary but good practice).