If you're simply looking to execute some custom scripts that are completely standalone (i.e. they don't interact with the Craft application in any way), those files should live somewhere below your public web root (i.e. the
public folder, or wherever your
index.php file resides). It isn't possible to have Craft route PHP files from the
However, the problem with reading/executing arbitrary PHP files from the public root, is that Craft basically "hijacks" all requests to anything below that folder, and routes those requests to
index.php. In order to read or execute an arbitrary PHP file below the public root, you'll need to override Craft's URL routing, for example by using
RewriteRule directives in your
.htacesss file if you're using Apache (also see this related thread).
On the contrary, if your custom PHP scripts do need to interact with Craft in any way, you'll need to write a custom plugin.
Fortunately, Craft plugins are relatively simple to build (as long as you're familiar with PHP, of course). You can use the excellent Plugin Factory to quickly scaffold a bare-bones plugin with a thoroughly commented codebase or use the Business Logic plugin as a starting point. Downloading other available plugins and looking at their source code is probably not a bad idea, either.
In any case, before digging in you should definitely skim through the official docs on plugin development. By far, the most important thing to know about Craft plugins is how they are structured and what the various moving parts do. That knowledge will also give you a nice overview of what a plugin's capabilities are, and how you'd go about implementing a certain feature in your own plugin.
One thing that the official docs doesn't really mention, which might be relevant to your use case, is how you make use of third party scripts or libraries. There are lots of ways to skin that particular cat, but the headline is that using using Composer if you can is the best option, though a simple
require() call in your plugin's main class'
init method will of course also work.
Also, keep in mind that when you're using third party scripts inside a Craft plugin, you will need to deal with namespacing.
The upcoming Craft 3 release adds another option for running PHP business logic – Yii2 Modules.