How to keep source and build folders in sync during debugging? - php

Recently, updated a PHP project to use source folder and build folder. We're using Gulp to build the project from the 'src' folder to the 'build' folder after pulling the 'src' folder and project configuration files from our Git repo.
project_root
|
├── src
|
├── build
|
└── {project configuration files}
Both frontend and backend developers are currently running the 'gulp watch' we've setup to keep our 'src' and 'build' folders in sync.
One of this biggest annoyances we've encountered is while debugging our project in the browser we often open the offending file where an error is reported and tinker with the code until it works in browser. However, more times than I'd like to count, we make the change to a file in the 'build' folder while debugging and then we have to manually make the change in the 'src' folder (which is often overlooked at first).
Is there any way to fix this workflow issue?
Dueling Watchers Approach
I thought about making a two file watchers to detect changes in the 'build' and 'src' folders respectively. When either watch detects a change, turn off the other folders watcher, process the changed files and sync up the other folder, then turns the other folder's watcher back on.
(This seems like the sledge-hammer approach.)
IDE Approach
We PHPStorm and Sublime Text 3 depending on the developer. In Sublime Text, I simply exclude the 'build' folder from the project so I don't accidentally open it by default. (However, I accidentally open 'build' folder files when debugging the PHP too often.)
Other
Perhaps the way we're handling project structure in general needs work. Frontend and backend development is often done in concert. Any suggestions?

After flailing my arms wildly at this problem for a few hours after posting this I found an answer to my own problem.
Turns out the best way to handle this is to use the IDE Approach and create path mappings for your project:
PHPStorm (documentation)
Settings » PHP » Servers
Check the 'use path mappings' selection.
In our case we mapped the '../src' folder to '../build'
Sublime Text with 'Xdebug Client' package
Preferences » Package Settings » Xdebug » Settings - User
Add the following to your Xdebug.sublime-settings file:
{
"path_mapping": {
"C:/wamp/www/your-project/build" : "C:/wamp/www/your-project/src"
}
}
Once your path mappings are setup, you can successfully set a breakpoint in a php file in your '../src' folder run your debugging session and the file in your '../build' folder will breakpoint at the same location.

Related

What is the ".phpintel" folder at the top of the Laravel file structure?

I am just noticing that there is a .phpintel folder at the top of the Laravel file structure. Where did it come from, is it necessary and can I gitignore it?
phpintel is a common sublime plugin. PHP code scanner and analyzer for code intelligence within PHP projects.
It creates .phpintel directory like .idea for Phpstorm and it should be included to .gitignore list of project and contains local project related settings and history for it.
You can ignore any hidden (and generated) data
You will find phpintel ignored in many .gitignore project file, such as:
postmark-php/.gitignore
Zizaco/entrust/.gitignore
...

Is there a way to create an Eclipse project excluding the project name in the path?

Not sure how I can explain this better as I am a beginner to Eclipse application.
I have my web directory set up for php pages. For example, /home/www/phpsite. All the source files exist here.
However, whenever I create a project (say 'myProject') and test any files from the existing path, it includes the project folder in the path name:
/home/www/phpsite/myProject/index.php
and this results 'Not Found' error.
How can I run my php pages in /home/www/phpsite/index.php? The project folder name is always included in testing web pages.
I am not trying to use the workspace directory created by Eclipse. I'd like to code and modify pages directly from Eclipse to my web directory.
Thanks
Follow these steps:
Setup www as your workspace
From the menu: File -> Import -> General -> Existing Folder.....
Promote to project:
Choose project type: PHP
Browse for "phpsite" and finish.

Is there a better alternative to relocate cakephp3 config folder

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.

How to add project to Netbeans when all source files are not in webroot?

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.

How do I add CodeIgniter System folder to Eclipse Project - Ubuntu

I am trying to get started with the PHP MVC framework, CodeIgniter. I am using the following article to setup my dev environment:
http://hetal.wordpress.com/2009/09/04/working-with-eclipse-and-code-igniter/
I am trying to add the CI 'System' folder to a new project in Eclipse. I am doing this by selecting 'New Php Project' and then 'Create project from existing source'. I am pointing it to the system folder as instructed.
I get an an error:
Parent of resource: /var/www/CI/System/.project is marked read-only.
The details says, "Permission Denied".
I have tried running Eclipse using gksudo but then I don't have PHP plugins installed etc.
It's saying that it only has read access to the /System/ folder, and therefore it does not have permission to write the .project file.
chmod the /System/ directory and try to import it into Eclipse again.
chmod og=rw /var/www/CI/System/
/* Gives the owner & group read & write access */
You're attempting to have Eclipse write files (i.e. the Eclipse .project) to a directory that it doesn't have permission to do so. It appears you're trying to write to the actual /var/www/ directory.
Normally the way I do it is to have CodeIgniter in my development directory/eclipse workspace and then make a soft-link in the /var/www/ that points to the Code Igniter I have setup in my development environment.
In response to comment
%> cd /var/www/
%> ln -s /home/jsmith/eclipse/workspace/CodeIgniter CI
This will create a soft link named /var/www/CI that points to the CodeIgniter you have in your home directory. (or where ever you typically put your development files) This will allow the web server to serve and use the CodeIgniter files that are under your control in your directory which you have full permissions on.

Categories