• 0
Votes
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 195

Backtrace:

File: /home/u125378470/domains/lawhelpguru.org/public_html/application/views/question.php
Line: 195
Function: _error_handler

File: /home/u125378470/domains/lawhelpguru.org/public_html/application/controllers/Questions.php
Line: 416
Function: view

File: /home/u125378470/domains/lawhelpguru.org/public_html/index.php
Line: 315
Function: require_once

There's a shell script that works partially when in a bootstrap script in Amazon Linux EC2 instance (script as user data setted before instance launching). And I still doesn't know why it not works when as a bootstrap script.

The script does the following:

  • Updates operating system packages
  • Installs Apache2 webserver
  • Sets the webserver to start everytime the system is booted
  • Installs PHP with amazon installer utility
  • Restarts the webservice
  • Downloads and installs Composer
  • Installs WordPress using Composer

This is the script:

#!/bin/bash

echo Bootstrap script starting at $(date) >> /home/ec2-user/log-bootstrap.txt
echo Updating OS and installing webserver at $(date) >> /home/ec2-user/log-bootstrap.txt
yum update -y
yum install httpd -y
chkconfig httpd on
service httpd start
echo Installing PHP at $(date) >> /home/ec2-user/log-bootstrap.txt
amazon-linux-extras install php7.4 -y
service httpd restart
echo Installing Composer at $(date) >> /home/ec2-user/log-bootstrap.txt
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
chmod +x /usr/local/bin/composer
echo The composer version is $(/usr/local/bin/composer --version) >> /home/ec2-user/log-bootstrap.txt
echo Installing Wordpress. Time: $(date) >> /home/ec2-user/log-bootstrap.txt
cd /var/www/html
/usr/local/bin/composer create-project johnpbloch/wordpress .

shutdown -P +5

The intent is to do everything in the machine at startup time by user data script.

The script works until the Composer installation. But the line echo The composer version is $(/usr/local/bin/composer --version) >> /home/ec2-user/log-bootstrap.txt was the first line showing some problem. It does not executes the part of $(/usr/local/bin/composer --version). It saves the echo in the file, but where it whould print the composer version remains empty.

But further analysis shows that Composer has been succesfully installed. I can put exact same remaining lines from script and everything works great, but just when I access the machine through ssh and execute the remaining code. Installing WordPress using composer works as well. Composer does not works only when it is in the user data script.

I tried to simulate the problem by two ways:

  1. Printed the whole script in the clipboard and past direct in the terminal, after a ssh login in the machine.

  2. Created a shell script file with this exact content, send to the machine through scp and executes it inside the machine.

In both cases the script works perfectly! And I did not forget to change to sudo before trials to simulates something more similar when the machine is executing the bootstraping script.

Does someone knows how to install and run composer in the same script for an Amazon machine in the user data? Why just the Composer does not works only if it is in an user data script from Amazon instance, although Composer was successfully downloaded and remains executable when access machine through ssh?