Fatal Error trying to run Install command from Terminal in cPanel

Fatal Error trying to run Install command from Terminal in cPanel

by Ryan Tanner -
Number of replies: 24
Hello all...

Due to some site stability issues, I'm looking to rebuild our Moodle site on a VPS

I obtained my code via git, and have been attempting to run the install command - which returns the following:
"sudo -u trainingfsgv /usr/bin/php install.php

PHP Fatal error:  Uncaught Error: Undefined constant "STDOUT" in /home/trainingfsgv/public_html/moodle/lib/clilib.php:35

Stack trace:

#0 /home/trainingfsgv/public_html/moodle/lib/clilib.php(249): cli_write('               ...')

#1 /home/trainingfsgv/public_html/moodle/admin/cli/install.php(300): cli_logo()

#2 {main}

  thrown in /home/trainingfsgv/public_html/moodle/lib/clilib.php on line 35

Content-type: text/html; charset=UTF-8


<br />

<b>Fatal error</b>:  Uncaught Error: Undefined constant &quot;STDOUT&quot; in /home/trainingfsgv/public_html/moodle/lib/clilib.php:35

Stack trace:

#0 /home/trainingfsgv/public_html/moodle/lib/clilib.php(249): cli_write('               ...')

#1 /home/trainingfsgv/public_html/moodle/admin/cli/install.php(300): cli_logo()

#2 {main}

  thrown in <b>/home/trainingfsgv/public_html/moodle/lib/clilib.php</b> on line <b>35</b><br />

[trainingfsgv@57 cli]$"

Looking through the related files, this looks to be around the ASCII logo for Moodle - but don't know enough to say if that is what is correlated with the error or not. 

Server info as below:
"cPanel Version 110.0 (build 6)

Apache Version 2.4.57

MySQL Version 8.0.33

Architecture x86_64

Operating System linux

Shared IP Address [Redacted]

Path to Sendmail /usr/sbin/sendmail

Path to Perl /usr/bin/perl

Perl Version 5.26.3

Kernel Version 4.18.0-425.19.2.el8_7.x86_64"

I've been working through server requirements, and making sure that related PHP packages are all installed via the WHM panel

Have selected PHP 8.0 for this site, and installed the packages for that version of PHP (At least, pretty sure I got them all....)

Very much appreciate any assistance in getting past this error to run the installer smile

Average of ratings: -
In reply to Ryan Tanner

Re: Fatal Error trying to run Install command from Terminal in cPanel

by Ken Task -
Picture of Particularly helpful Moodlers
Which Linux distro (Ubuntu/Rocky/RHEL/?)
Looks like el8 - CentOS Enterprise version 8.


Which moodle version?  4.1 good choice as it is long term support version.

Begin with end in mind ...
We want a moodle running https with a fully qualified domain name.

So set up server with a FQDN first and apache with a valid cert (many hosting providers offer and have instructions for LetsEncrypt.

Do the above first, then moodle.

When it comes to sudo - I tend to use sudo -s (you will be prompted for the login you have for the account used seen ni cPanel) - prompt will change to root>

You can reset ownerships/permissions after moodle is installed and running.

But you may not have root access and don't need to sudo as the user you logged onto with trainingfsgv should have access to anything on the accounts home directory ... including public_html

Check that you have the php extensions you need - including php-cli.

From public_html, issue which php
That shows a path to the php executable for php-cli ...
using the full path issue /full/path/php -i

You should see php-cli for version 8.

also check php extensions

php -i
and
php -m

If all of the above checks out, not get moodle code via git - which you have done
and it resides in moodle directory.

From the moodle code directory:

php admin/cli/install.php

And if you get to the point of wanting to tweak somethings ... DB/other, WHM controls and you will see config/ini files with comments in them telling you not to edit directly.

IS DB for the moodle compliant ... utf8mb4 character set and utf8mb4_unicode_ci collation?  You probably should use the cPanel tool for creating DB and DB user as that puts a prefix in front of DB name ... normally it's the account login - trainingfsgv_moodle.   User for that DB needs to have all privs.

Location of moodledata directory ... /home/trainingfsgv/moodledata ?

'SoS', Ken

In reply to Ken Task

Re: Fatal Error trying to run Install command from Terminal in cPanel

by Ken Task -
Picture of Particularly helpful Moodlers
And some more ...
From what I can recall, one has to use cPanel tools to set php version + extensions per domain.

And, with moodle 4.1 might use php 8.1

WHM with cPanel on allocated server is kinda a confusing setup.
WHM rules the roost and there are some PHP tweaks that WHM controls and can't go over maxes set by it in the allocated (cPanel) servers.

Does your setup have Terminal icon per domain on WHM - icon says login as root?   or are you using cPanel's Terminal?

'SoS', Ken

In reply to Ken Task

Re: Fatal Error trying to run Install command from Terminal in cPanel

by Ryan Tanner -
I can manage the PHP in WHM, have been using cPanel in the account for the domain
In reply to Ken Task

Re: Fatal Error trying to run Install command from Terminal in cPanel

by Ryan Tanner -
I see I have the cgi-fcgi vs. cli discrepancy as described here: https://stackoverflow.com/questions/41491697/composer-install-error-in-argument-1-char-2-option-not-found-r

But neither command is a solution for me.

From the moodle code directory,
php admin/cli/install.php
returns
The configuration file config.php already exists. Please use admin/cli/install_database.php to upgrade Moodle for this site.

Correct on the location of the moodledata directory

Would next step be to run 
php admin/cli/install_database.php
from the moodle code directory? 
In reply to Ryan Tanner

Re: Fatal Error trying to run Install command from Terminal in cPanel

by Ken Task -
Picture of Particularly helpful Moodlers
Not sure your Stackoverflow reference applies here.

config.php file contains the parameters for your DB and site.

Check it for the DB user, DB name, DB password.
Prior to installing, you should have used a cPanel tool to create the DB - which has customerlogin_ prefix added in front of the name you gave the DB (probably you named it moodle).
The DB had to be created as well in advance of the installer run and should have character set utf8mb4 with collation utf8mb4_unicode_ci.   The collation is also referenced in the DB array of the config.php file ... so check that also.

Using the user and password seen in the DB array, see if database is really there:

mysql -u [DBuserasinconfig] -p[DBpassasinconfig]
That should get you to a mysql> prompt.
From the mysql> prompt type: show databases; [ENTER]
Be sure to use the ';' at the end of the command.
Do you see the DB named as the DB in config.php?

If so, then try the command to install the DB from your code directory.

cd /home/[customerid]/public_html/moodle/
you replace [customerid] above with the real customerid.
Then issue:
php admin/cli/install_database.php [ENTER]

the first part of that command should be finding/using php-cli and the version you setup in cPanel for the site/domain.

At this point that can't hurt!

Additional note/questions/comment... you began by saying 'for performance reasons' you've moved to a VPS from same provider.   Your provider's 'caddie' is WHM with your shared account already copied to the SAME server.
Here's how to know that:
Is the IP address:port used to access your WHM the same as the IP address:port used to access the cPanel?

If you are coming from shared hosting you are now having to learn provider's 'caddie' setup ... the cPanel and where that account resides in /home/customerid/public_html/ is in a 'user jail' - which isn't the same as other dedicated server setups where apache root is in /var/www/   There are many references in Moodle docs for a true VPS/dedicated server that you need to translate to your 'user jail' in /home/cutomerid/public_html

Not all providers are the same ... and sharing where/with what provider you host won't be a security issue!

'SoS', Ken

In reply to Ken Task

Re: Fatal Error trying to run Install command from Terminal in cPanel

by Ryan Tanner -
The install.php command fails, stating "Database tables already present ; CLI installation cannot continue."

Different IPs between WHM and cPanel currently

I've been going through every piece of setup documentation I can find for Moodle, and part of the challenge is none of them quite line up with the environment I'm working with.

Countless 'Softaculous' and 'Installatron' tutorials, less for the work I'm trying to do (at least with the search terms I've come up with so far)
In reply to Ryan Tanner

Re: Fatal Error trying to run Install command from Terminal in cPanel

by Leon Stringer -
Picture of Core developers Picture of Particularly helpful Moodlers

STDOUT is a constant built into PHP so if you're getting Undefined constant "STDOUT" there's something wrong with your PHP environment.

What do you get for the following commands?:

$ /usr/bin/php -r 'fwrite(STDOUT, "Testing\n");'
Testing
$ /usr/bin/php -v
PHP 8.0.26 (cli) (built: Nov 22 2022 17:44:09) ( NTS gcc x86_64 )
Copyright (c) The PHP Group
Zend Engine v4.0.26, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.26, Copyright (c), by Zend Technologies

I've included test output from my system.

Average of ratings: Useful (1)
In reply to Ryan Tanner

Re: Fatal Error trying to run Install command from Terminal in cPanel

by Ryan Tanner -
Thanks for the support suggestions all!

I was able to access the web installer once I had my site online, and it completed without issue.

Based on the lines of code it was referencing, I really think it might have been an issue with the cPanel terminal having an issue with trying to pass the lines for the ascii Moodle logo?

If that's just not a possible thing, happy to be corrected - but given how smoothly the install went, and the lines referenced in the error code, that's my current conclusion

EDIT: NOPE. Wrong conclusion to make. Still a problem, regardless of the site running! 
In reply to Ryan Tanner

Re: Fatal Error trying to run Install command from Terminal in cPanel

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
Hi

You wrote:
> Due to some site stability issues, I'm looking to rebuild our Moodle site on a VPS

So, you gave up the previous try on GoDaddy Hosting - Moodle Stability and Issues?
In reply to Visvanath Ratnaweera

Re: Fatal Error trying to run Install command from Terminal in cPanel

by Ryan Tanner -
Not so much 'gave up', as I didn't have access to the things that needed tweaking in the old set-up, and thus could not resolve the intermittent connection error issues. Was having too much of an impact on end users to keep going on that setup
In reply to Ryan Tanner

Re: Fatal Error trying to run Install command from Terminal in cPanel

by Rick Jerz -
Picture of Particularly helpful Moodlers Picture of Testers
Sorry about being so late into your situation. I saw some comments about GoDaddy, and folks here know I use a GoDaddy VPS, so I thought I could help a little. If I am off-base, there is no need to reply to me. It won't hurt my feelings.

Tell me, exactly what kind of hosting package do you have? Is it a VPS? Or a hosted server?
Which version of Moodle do you wish to install?
Are you somewhat experienced in installing Moodle? Or is this a little new to you?
Is your server Linux?
Does your WHM offer "EasyApache 4?"
Are you trying to install it using Softaculous or from scratch? Just trying to make sure.

Your answer to these questions will help me know what other issues you might encounter.

I am running my Moodle 4.2 (latest) on a GoDaddy VPS, I have PHP 8.0.28, MariaDB 10.6.12, CENTOS 7.9, WHM 110.0.2, and Apache 2.4.57. I use WHM and cPanel. Everything appears to work fine, so this is why I wonder what kind of server you have.

Incidentally, I don't use GIT to install my Moodle, I do it the other way.

I am not a GoDaddy or Moodle support person, just a teacher who has used Moodle and Godaddy for over 10 years.
In reply to Ryan Tanner

Re: Fatal Error trying to run Install command from Terminal in cPanel

by Ryan Tanner -
Not sure if I reply this way if it will notify all - but here's where I'm at - don't have a solid background in these environments, and very much in the position of teaching myself as I go, so apologize if I use any incorrect verbiage.

I was consistently running into problems trying to run commands from the terminal, and from what I could glean from information here, as well as further reading from where those comments led me - it had to do with my php environment



I was trying to figure out how to get my environment from cgi-fcgi to cli, but made no headway.

It seemed like I should still be able to do what I needed to do, so kept digging through whatever documentation or similar use cases I could find.

I've gotten lost in this all a couple times, so have worked through the process from scratch a couple times

I've at this point I've got a clean install up and running with all greens in the server/enviornment check

The difference was changing how I was invoking (?) php... running any of the commands where I saw, for example, "sudo -u www-data /usr/bin/php install.php" in the moodle documentation - I would instead input /usr/local/bin/php and the actions would complete. 

I'm sure there are many glaring things that would jump out to folks more educated on this stuff, but doing my best lol

Near as I can tell, I think I'm all good now?
In reply to Ryan Tanner

Re: Fatal Error trying to run Install command from Terminal in cPanel

by Ken Task -
Picture of Particularly helpful Moodlers
Your account on GD is in a 'user jail'.
/home/trainingfsgv/
trainingfsgv is your cPanel logi?

and all files folders in public_html belong to that user: trainingfsgv
public_html/ is your web server's document root.

You do not need to use sudo.

So the command you issued earlier:

sudo -u trainingfsgv

would fail, because you were already logged on as that user.

Docs where you saw www-data as user were for Ubuntu ... not el8.

The kernel Version information you shared:
Kernel Version    4.18.0-425.19.2.el8_7.x86_64"

Shows el8 - which is CentOS Enterprise release version 8
which is close to what was part of Red Hat Family.


The php that runs from the web is not the same php that runs from command line. In order to run php from command line, php-cli would have to be installed via package manager ... which in el8 is either yum or dnf (dandified yum)

Your screen shot shows PHP 8.19 (cgi-fcgi) which is the web based PHP.
php cli would show PHP 8.19 (cli).

I responded once in this thread:
https://moodle.org/mod/forum/discuss.php?d=447123#p1796945

But got no response to that posting .... oh, well!

IF you have php-cli installed ...
After you click Terminal and you are at the command prompt:
cd public_html/moodle/ (am assuming there is a moodle directory there.
Then issue:
which php
The command which will show which PHP is found via command line.
It will show a path.
To see if that's php-cli, issue:
/path/as/seen/php -v

replace /path/as/seen/ with the path seen with the 'which php' command.

If that one is php-cli for the version of PHP you need to run your Moodle,
you are good to go.

From:
/home/trainingfsgv/public_html/moodle/
(again assuming moodle code acquire by git is in the moodle directory)
To get there:
cd /home/trainingfsgv/public_html/moodle/
and issue:
php admin/cli/install.php
From what you said you entered:
/usr/local/bin/php

You should have been prompted for the same information the web based install would prompt for and after agreeing to the license, the install begins
by installing the tables in the blank/empty database for moodle you created
in cPanel MySQL Tools for the moodle.

Your are on the right path ... *by far* moodle is much easier to update and upgrade via command line git.   Fewer moving parts means less prone to human error.

BTW, have been know to do a look see ... for free!   And all I would need in a private message on this system is:
The url to your cpanel, the login, and the password.
Not a 'black hat' ... think there are users on this system that will verify that! smile

Yours, in the 'Spirit of Sharing' (SoS),
Ken
 

In reply to Ken Task

Re: Fatal Error trying to run Install command from Terminal in cPanel

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
The first sentences in OP is
> I'm looking to rebuild our Moodle site on a VPS

From where comes the 'jail'?
In reply to Visvanath Ratnaweera

Re: Fatal Error trying to run Install command from Terminal in cPanel

by Ken Task -
Picture of Particularly helpful Moodlers
@Mr. V:
"From where comes the 'jail'?"

Not all VPS's are the same!   This thread is all abouit environment.  And Moodle docs cannot provide docs to cover them all with specifics to each provider.

In OP's case, using cPanel and clicking terminal icon, one finds oneself @ /home/accountname .... and inside that directory a public_html.
So that's not logging in as root and 'accountname' may not be part of sudoers group (those accounts that can su to root nor use sudo commands).

That means OP cannot install software with native package manager (in OP's case since server is running el8, that's yum or dnf.  OP can use cPanel/WHM tools to choose PHP version per domain/server that's allocated from WHM and which/what extensions to PHP are turned on or available to a domain/server.

On a *true* VPS (Linux Standards Base), Apache home directory is typically in /var/www/ and user can su to root then use /var/www/ as main area for web services.  In RedHat family OS's apache user is 'apache or apache2' ... in Debian based (which includes Ubuntu) that's typically www-data.

Now if that's not a 'jail' I don't know what is! smile

WHM ...

"What is WebHost Manager (WHM)? cPanel's WebHost Manager (WHM) is a web application that provides administrative control of your Virtual Private Server (VPS) or Dedicated server. You use WHM with cPanel to create individual accounts, add domains, manage hosting features, and perform basic maintenance."

In some WHM setups there are sections of tools for each domain (other server that's been allocated).   And in those sections of tools, an icon for 'Root access'.
Using that method of access does mean OP can install software via native package manager ... like php extensions that may not have been installed.

So the OP has what used to be called a 'Reseller' account ... using WHM can setup other servers each has a cPanel that OP's 'customers' could access.
In other words, OP is a mini-provider to him/herself!

'SoS', Ken


In reply to Ken Task

Re: Fatal Error trying to run Install command from Terminal in cPanel

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
So it means, the OP has shifted to a VPS, and gave it (the CLI) up immediately by inserting this thing called Cpanel? Now you have to talk Cpanel, his Cpanel?
In reply to Visvanath Ratnaweera

Re: Fatal Error trying to run Install command from Terminal in cPanel

by Ken Task -
Picture of Particularly helpful Moodlers
From WHM, OP allocated a server with specs - memory space cpu's etc and along with that an operating system (Debian/Ubuntu/RedHat Enterprise/CentOS).

That allocated server has a cPanel which the customer uses.
Ya see, in this case, the OP is both  'reseller' AND 'customer' to himself!

cPanel has a Terminal icon ... and that puts one in a web based shell with the account that is not part of sudoers group.   That access is 'jailed' and does change somewhat what one does to install a moodle.

For that I would check for the existence of git:

whereis git

If present, there is potential for the most efficient way to install moodle - even though OP will have to use cPanel tools for MySQL/MariaDB and cPanel tool for setting up cron for the moodle.

So it's a combo .. cPanel tools for somethings, Terminal for others.

Whenever am invited in for a look see via cPanel, I issue the following command to check environment:

uname -an
whoami
pwd
sudo -s (this one will more than likely fail)
env |grep PATH - I do this one to see if there is a /home/customerlogin/bin/ listed.    If so, then OP has limited ability to install software in that jail.

If I see  public_html diretory, via ls I change into that directory and ls -l
Is there already an .htaccess file?

Then the typical things for PHP:
php -v
php -m
php -i

Knowing that cPanel has a tool (like Easy Apache [a misnomer] or MultiPHP) that allows the OP to choose php version per domain.

I also see if mysql or mariadb is setup (believe it or not) with no root password:

mysql -u root -p'' [ENTER]

All of the above can generally be described in Moodle docs but not the specifics - which is what OP was seeking.

'SoS', Ken

In reply to Ken Task

Re: Fatal Error trying to run Install command from Terminal in cPanel

by Ryan Tanner -
"In OP's case, using cPanel and clicking terminal icon, one finds oneself @ /home/accountname .... and inside that directory a public_html.
So that's not logging in as root and 'accountname' may not be part of sudoers group (those accounts that can su to root nor use sudo commands)."

I am able to manage the sudoers via WHM, and have added my 'accountname' to that list.
In reply to Ryan Tanner

Re: Fatal Error trying to run Install command from Terminal in cPanel

by Ken Task -
Picture of Particularly helpful Moodlers
"I am able to manage the sudoers via WHM, and have added my 'accountname' to that list."

OK, good.   Not needed really - but ... ya got it ... if you needed to install software via package manager that would come in handy!

So have you found your hosting providers docs/faqs/tutorials info yet?

Remember that the focus of these forums is Moodle! smile

'SoS', Ken



In reply to Ken Task

Re: Fatal Error trying to run Install command from Terminal in cPanel

by Ryan Tanner -
Hi Ken, 

Sorry - there is a lot of volume in your responses, and given I'm not familiar with much of the jargon, and some of which just doesn't seem to apply to my use-case, that it is sometimes difficult to reply

"Your account on GD is in a 'user jail'.
/home/trainingfsgv/
trainingfsgv is your cPanel logi?"

I don't have to login to cpanel, I just open cpanel from my whm account, or from the account we own the domains/hosting on. 

"Docs where you saw www-data as user were for Ubuntu ... not el8."
If these instructions for installing moodle, which is what I was referencing, are for Ubuntu, I'm not sure where that is clear? 
https://docs.moodle.org/402/en/Installing_Moodle

"The php that runs from the web is not the same php that runs from command line. In order to run php from command line, php-cli would have to be installed via package manager ... which in el8 is either yum or dnf (dandified yum)

Your screen shot shows PHP 8.19 (cgi-fcgi) which is the web based PHP.
php cli would show PHP 8.19 (cli).

I responded once in this thread:
https://moodle.org/mod/forum/discuss.php?d=447123#p1796945

But got no response to that posting .... oh, well!"

Ok - but that response started with suggesting the stack overflow link I shared didn't apply, but within that thread was this exact discrepancy between cgi-fcgi and cli. So I was kind of confused by your response - and I was trying to reference that link for guidance on how I could change my environment to cli. 

the command
which php 
gave me the /usr/local/bin/php that worked in issuing the commands for my installation. 

I actually did need sudo commands to perform many operations. 

"From:
/home/trainingfsgv/public_html/moodle/
(again assuming moodle code acquire by git is in the moodle directory)
To get there:
cd /home/trainingfsgv/public_html/moodle/
and issue:
php admin/cli/install.php
From what you said you entered:
/usr/local/bin/php"

I completed this as per your instructions in a previous comment and had replied, as it returns
"The configuration file config.php already exists. Please use admin/cli/install_database.php to upgrade the Moodle for this site."

Had been hoping for your guidance on if that was the appropriate next step! This was in the same comment that had referenced the Stack Overflow link sad



In reply to Ryan Tanner

Re: Fatal Error trying to run Install command from Terminal in cPanel

by Ken Task -
Picture of Particularly helpful Moodlers
@Ryan

Because Moodle is just an application that can be installed on a LAMP (Linux/Apache/MySQL(MariaDB)/PHP(perl/python) server documentation for installing Moodle begins with the assumption that the installer has experience at admin of a LAMP server.
As I mentioned before, there is NO way Moodle docs could cover how to setup a LAMP/LEMP/whatever environment for *every* provider that exist on the planet - there are just too many of them .. and they all have their twerks.

Learning your server's environment(s) is what you are doing now ... yes, it's confusing, if one doesn't start with the docs/faqs/etc provided by your hosting provider - learning about WHM/cPanel and the differences in those, for you, comes before Moodle.

Hosted with GoDaddy?
This might help start you off on your journey!

So with some 'rabbit hole' visits you have finally arrived at having a moodle up and running, correct?   And along the way, you've learned a lot about your setup.   It's  a journey ... never ending! smile

'SoS', Ken





In reply to Ken Task

Re: Fatal Error trying to run Install command from Terminal in cPanel

by Ryan Tanner -
Hi Ken,

Still unclear - when
"/usr/local/bin/php admin/cli/install.php"
returns
"The configuration file config.php already exists. Please use admin/cli/install_database.php to upgrade the Moodle for this site."


Would next step be to run
"/usr/local/bin/php admin/cli/install_database.php"
from the moodle code directory?
In reply to Ryan Tanner

Re: Fatal Error trying to run Install command from Terminal in cPanel

by Ken Task -
Picture of Particularly helpful Moodlers
To be honest, have never ever seen
"The configuration file config.php already exists. Please use admin/cli/install_database.php to upgrade the Moodle for this site."

but from what it then tells you:

"...Please use admin/cli/install_database.php to upgrade the Moodle for this site."

Then yes ...
run
/usr/local/bin/php admin/cli/install_database.php from moodle code directory ... only IF ... ONLY IF .... /usr/local/bin/php -v
shows the version of php (cli) you need for your site - which I believe you said you selected 8.0 of PHP.

'SoS', Ken