How can install PHP-Imap extension on Amazon linux 2023?

0

I'm going crazy to make a own project work on amazon ec2.

My project uses PHP IMAP extension and PHP 8.1.23, so I have read a lot of posts and I found the following one: [https://gist.github.com/napestershine/7d6073bf23ef8918b7b7001410be0c96](SH script to install it on amazon linux 2) however it does not work on amazon linux 2023.

It said:

[root@ip-my-ip-address www]# sh ./install-imap-extension.sh ./install-imap-extension.sh: line 4: sudo: command not found ./install-imap-extension.sh: line 5: sudo: command not found ./install-imap-extension.sh: line 6: sudo: command not found ./install-imap-extension.sh: line 7: sudo: command not found ./install-imap-extension.sh: line 8: sudo: command not found ./install-imap-extension.sh: line 11: php: command not found ./install-imap-extension.sh: line 13: wget: command not found ./install-imap-extension.sh: line 15: tar: command not found

carlos
asked 6 months ago810 views
2 Answers
0

A couple of things here, firstly the script has lots of sudo commands in lines 4-8 and 26-33, meaning it isn't intended to be run as root (because if it was, why bother with sudo), and also you've correctly identified this script is meant for AL2 and won't work on AL2023.

The giveaway for the latter is sudo amazon-linux-extras install epel -y because AL2023 doesn't support EPEL https://docs.aws.amazon.com/linux/al2023/ug/compare-with-al2.html#epel

profile picture
EXPERT
Steve_M
answered 6 months ago
0

Fresh answer, because my previous one was going down a rabbit hole.

The errors like ./install-imap-extension.sh: line 4: sudo: command not found and so on are because of the Linux shell's PATH being set in line 3 of the script - remove this line, as it's just wrong.

Secondly the presence of sudo in lines 4-8 and 26-33 suggest the script isn't intended to be run as root, but as a non-root user who has sudo-to-root privileges. And as this script is written for Amazon Linux 2, such a user would be ec2-user.

That's not to say it must not be run as root, most likely it will work as root if you got rid of PATH=pwd on line 3, just that it's not intended to be run as root.

As mentioned, the script is clearly meant to be run with Amazon Linux 2 as the target platform, and you're running Amazon Linux 2023. Which won't work because it relies on the presence of the EPEL software repository (rows 5 & 6) which is not supported on AL2023 https://docs.aws.amazon.com/linux/al2023/ug/compare-with-al2.html#epel

You're going to have to hack around a lot if you want to get the script into a position that it will work with AL2023. A few things that might progress it are in the comments under my previous answer, but I admit they do assume knowledge of Linux and YUM repos, etc. You might be better off reaching out to the creator of the original script and asking if they have any solution to getting the IMAP extension installed on AL2023, since you can't be the first person to have tried to do this.

The other alternative is to work on an Amazon Linux 2 EC2, but I guess that isn't an option for you or you would have done it already.

You may find something of value on the PHP on AL2023 webpage https://docs.aws.amazon.com/linux/al2023/ug/php.html

profile picture
EXPERT
Steve_M
answered 6 months ago
  • Thanks for your answer! Now I know why the script does not work but I would like to see how to install it on this amazon linux version, pls I need a solution (changing the linux version is not a solution)

  • The best person to ask for support on that script is the person that wrote it, and their contact details will be on their GitHub page. The re:Post community isn't a place for debugging somebody else's software, nor for hacking around to try and make it work on a system that it wasn't intended to work on.

    A few suggestions are offered above, based on a general understanding of Linux as I don't understand the finer details of what it is you need here. If they don't work for you or you can't follow them then the best place to ask for help would be a PHP fourm on somewhere like StackOverflow. There you are more likely to find people who really understand what it is you want to do, and even may have figured out how to get this to work on AL2023.

    Good luck.

  • Hi Steve, I ended up installing Amazon Linux 2 and I followed the next instructions: https://serverfault.com/questions/1032506/how-to-enable-imap-php-extension-on-aws-ec2-instance, however, when I try to the last step, that is, restart php-fpm I receive an error. Could you please, give me an answer to install PHP IMAP on Amazon Linux 2? (I will create a new question)

  • Sure, it would be best to ask this as a new question on here. It also looks like you are getting some traction from the contributors on the serverfault post you added a comment to.

    Have you reached out to the original author of the script?

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions