CodeIgniter + Command Line + Cron + Cpanel - php

SOLVED:
Crap... why is it always you figure something out right AFTER you finally decided to ask for help!!
If anyone else is having this problem, try running from /usr/local/bin/php instead of /usr/bin/php to get codeigniter to pick up on the URI segments.
QUESTION
I have the latest installation of codeigniter and everything seems to be working fine locally. I recently put my files on my server and everything except my cron command is working.
When I try to call a controller through cron (as described here: http://codeigniter.com/user_guide/general/cli.html), I am not getting the controller. Instead, the output I get is simply my default controller (login page).
This worked fine locally and the index.php IS getting called because I'm getting emailed the output from the default page.
Someone asked a similar question here: CodeIgniter Cron Job on Shared Hosting? Responders suggested that it was a problem with Cpanel (which is what i'm now trying to use to set up the cron job), but talking to my hosting provider, they said the whole command is being run. Nevertheless, CI isn't grabbing the URI for the controller. I also checked to make sure the base_url is set correctly (which is proven by the file working fine through a URL call).
Any thoughts? I just can't seem to figure out why it's not grabbing the URI when in command line format: /usr/bin/php index.php controller_class method

This was the answer:
Use /usr/local/bin/php instead of /usr/bin/php to get codeigniter to pick up on the URI segments.

Here is solution first you need to find path from phpinfo document_root path
php5 /home/abc/public_html/index.php folder_name controller_name function_name
It's 100% working

I'm glad you got it working Mike. I ran into similar problems and ended up using the CI Cron Job Bootstrapper on a recent project that was running on a cPanel host. I'm just posting this incase it helps someone else.

For me this is what worked:
php54 -f /home/{cpanel_user}/public_html/index.php controller function

Related

PHP script not looking in includes folder

I have a new install. Ubuntu 22.04, Apache2, PHP 8.1 and I'm trying to use PHPMailer. My test page with phpinfo all looks good and shows the includes directory /usr/share/php. My form and script are in a subfolder of my document root and it loads fine. But when I fill out the form and the script starts it errors out unable to find PHPMailer. It's only looking in the subfolder the script is in, not the global includes directory. I don't want to put the mod in every form folder and I know it's supposed to work from the includes folder. Is this an Apache or php config issue? Or something I have to specify in the vhost?
Just verifying and closing out with the answer
I found the issue early today. Thanks to bad/tired eyes, I wasn't seeing the leading dot so it was looking for ./usr... Once i fixed that i was able to sort out the Ubuntu method of calling it from the libphp-phpmailer pkg autoload.php. I was able to get the script working with a few code corrections. The only thing I didn't sort out was PHPMailer:ParseAdresses but i only had a few recipients for this form so it wasn't that big an issue. My form is back online and my managers are happy 😊

PHP 404 Error Message

I have begun learning PHP using an eBook. The following strange results are happening: Per the book I have created two simple PHP files. They are named phpinfo.php and hello.php. Both files show in the user root directory. Both files show when I use the ls command in my mac terminal.
When I try to run them in my browser only the first one runs. The second results in a 404 error, File Not Found. How is this possible? Could an internal file mistake cause this?
Thanks
Thank you all. It was suggested that it would be easier to delete everything including the app and start over. So I did and then downloaded MAMP. That worked.

FuelPHP "invalid data source name" error

I'm trying to set up a FuelPHP app, and I've run into a puzzling problem. Every time the app tries to connect to the database, I get the following error:
Fuel\Core\Database_Exception [ Error ]: invalid data source name
I've set FUEL_ENV to "stage" in Apache's VirtalHost configuration and the database credentials in fuel/app/config/staging/db.php seem to be correct: I can log in to PhpMyAdmin using the same username and password. I'm stumped as to what else to try - any advice would be much appreciated.
In case it helps, I'm using FuelPHP 1.4 on an Amazon EC2 instance running Ubuntu 12.04 LTS on which I've installed MySQL and PHP via apt-get. I have another app (on another instance) running an older version of FuelPHP (1.2.1) which runs with no problems.
Incidentally, this question is probably closely related to this one, but I'm asking it as a separate question because the problem I'm having is not limited to the command line.
Ok, this has taken far too long to get to the bottom of, but it turns out to be simple to fix: for some reason, in FuelPHP 1.4 the stage environment's config directory is called staging (in previous versions it was stage).
I don't know whether this is a directory naming mistake, or whether this is a new name and something somewhere in FuelPHP hasn't been updated to use it, but I found changing the directory's name to 'stage' fixed the problem.
I had the same issue when running unit tests with FuelPHP's oil utility. If you're running into this issue, it most likely is a configuration issue.
To debug, somewhere in the code that isn't working put something like the following to see what environment FuelPHP is trying to use:
<?php
echo "env: " . Fuel::$env;
exit;
In my case, it showed it was trying to use the 'Test' environment. Since I didn't have a 'test' folder in my app's config folder, it was failing.
In most versions of FuelPHP, however you have the Fuel::$env set in your .htaccess file will work throughout all versions of FuelPHP. However in older versions, you may run into this issue.
You can either edit the bootstrap.php file and manually set the FuelPHP environment how you want, or setup the environment that it's trying to use.
Apache web server: SetEnv FUEL_ENV DEVELOPMENT Hope this helps someone
For those of you who none of this worked make sure of two things
there are multiple db.php files /fuel/app/config/development/db.php. check environment as #Chad Hutchins mentioned and double check the username and password is correct
Make sure /var/mysql/mysql.sock exists. In my case I was using /Applications/XAMPP/xamppfiles/var/mysql/mysql.sock so i needed to create a symlink. Followed the instructions here
Hope that helps someone

Using PHP to execute ssh/command line properly

So I need a bit of help in regards to ssh/command lines being run from php.
Out of the gate - yes exec is enabled on the server - its our own dedicated box
The setup. I have created a script that uses cpanel's api to create sub domains
for a particular account. That's all fine and dandy and everything works as expected.
Now - we have a wildcard SSL installed as well.
The long and short of it is this. Under the present conditions if you pulled up:
https://user.domain.com you would only see the top root directory for the account,
NOT the directory it should be in. But if you use it without the https - it does what
it should. Now it's a dedicated box with HostGator and they had this script they
installed for me to do what needs to be done - and that works as expected.
The script HostGator installed is located at:
/var/cpanel/userdata/account/mdssl
So the line they gave me to run the script and do what it should do is as follows:
./mdssl clone domain.com user.domain.com
So my question is - because I have never really worked with shell stuff
inside of php, would the following line be a workable example of how to execute the script?
shell_exec('/var/cpanel/userdata/account/mdssl clone domain.com user.domain.com');
or do I just need the exec command? And should the opening line be any different?
I just need to tap that line using php and pass the 'user' field to it and have the
script do its thing to clone the setup for the SSL so that the wildcard features work
properly and the users account lands in the proper directory it should.
Any insight is appreciated! :)
Thank you very much.
I've only used exec() or system()
They're always tricky and tend not to behave as expected.
I would start off with
ini_set("display_errors", 1);
exec('/var/cpanel/userdata/account/mdssl clone domain.com user.domain.com', $output);
var_dump($output);
See what the output says or if a PHP error is occurring.
You may also need to escape out of the current directory of whatever default you're in with ../ and make sure apache user has access to mdssl (or whatever user your system uses). You may need to sudo it.

PHP CodeIgniter 404 on deploy

Oooops I did it again.
My site worked perfectly locally
My development machine is a windows WAMP2 setup
My server is a CentOS 5.5 APACHE 2.2 PHP5 seup
I'm getting a 404 on the codeigniter site that I've deployed, and I really can't make out what's wrong, so please help me find the error.
It's the root url. I haven't set up dns so it's just the ip address of the server. It was showing the standard apache page before I uploaded codeigniter. I've looked over the config file, and it looks ok. Could it be a file permissions error? i have set chmod o+rw in the whole /var/www/html dir. the error_log in the httpd shows nothing
I've tried testing if it was the mod_rewrite module, but I created a test directory with a .htaccess file with RewriteEngine ON that didn't give me an error, so that can't be it.
In codeigniter I've set the log_threshold to 4 in the config, but I don't get any log messages, so I can't really make out if it's a pre-> codeigniter error, but I really don't think it is, as it's loading my Error view, still Why isn't there any log being written, what's it about?
Any help would be extremely appreciated as I'm running on fumes to get this working...
Update
Thanks to #jondavidjohn I have discovered that hitting the controller directly IE:
http://addr/index.php/GeoController/markers/
Will provide me with a controller specific error saying:
unable to locate your model "modelname"
SOLVED
Thanks to #jondavidjohn, and #timdream for giving me the clues to solve this one. It was a naming problem, I had filenames that were camelcased, and they can only be small from what I understand now, so the ROUTE was innefective in that it lead to Site, but should've lead to site although I had a Site.php I had to change it and the route to site.php
make sure you have the correct settings in system/application/config/config.php.. pay special attention to
$config['base_url'] = "http://www.example.com";
Make sure you are putting in the root domain of your site, also check your routing config and make sure you have the correct default controller set in system/application/config/routes.php
I recently started using a fresh install of codeignitor 3.0 and had no problems on my dev server (Windows) then when I moved to my live server (Linux) I started getting a 404 error.
The reason for this is that in 3.0 you are meant to capitalise the first letter of your controllers/models and also the file name.
e.g.
class Test_model extends CI_Model {
Test_model.php
Hope this helps some people who end up here!
For reference:
http://www.codeigniter.com/userguide3/installation/upgrade_300.html
$config['uri_protocol'] could also play a part. It's default to AUTO, which looks for environment variable that contains the actual URL automatically.
I had a web app that fails when I switch to php-cgi from mod_php for my server. Changing the config to REQUEST_URI solves the issue. I found the valve by digging phpinfo() outputs, you could try to do that.
My first bet is that you were developing this and modified the .htaccess file.
HOWEVER, if you went from a Windows -> Linux system change (dev on Win, prod on nix) then you have to keep the Controller names in mind, if a file on windows was "Home.php", and you used "home.php" in the config as your default route, then it will fail.. as there is no "home.php" file.
Home.php != home.php
Linux is case sensitive. Check that out, it might be a simple thing but could cause snags.
Again I am just guessing due to lack of details.

Categories