Loading image

Blogs / Technology

How to Update PHP and Composer Versions Using SSH CLI Without Sudo on Hostinger

How to Update PHP and Composer Versions Using SSH CLI Without Sudo on Hostinger

  • showkat ali
  • 0 Comments
  • 233 View

Updating PHP and Composer versions on Hostinger using SSH CLI can be challenging, especially without sudo access. This guide simplifies the process and ensures you can work seamlessly within the limitations of shared hosting environments.

Introduction

When using Hostinger's shared hosting, you may encounter restrictions that prevent direct updates to software like PHP and Composer. By leveraging SSH and local configurations, you can still update these tools effectively. This guide will walk you through updating PHP and Composer step by step.


Step 1: Update PHP Version

Hostinger provides multiple PHP versions that can be selected through custom configuration. Follow these steps to update PHP:

1.1 Check Your Current PHP Version

Run the following command to check the current PHP version:

php --version

1.2 Update PHP Version

To use a newer version of PHP (e.g., PHP 8.2):

  1. Open your .bashrc file to set a new alias:

    nano ~/.bashrc

     

  2. Add or update the alias for PHP:

    alias php=/opt/alt/php82/usr/bin/php

     

  3. Save the file and reload it:

    source ~/.bashrc

     

  4. Verify the updated PHP version:

    php --version
    If the output shows PHP 8.2 (or your desired version), the update was successful.

     

 

Step 2: Update Composer Version

Composer is an essential tool for managing dependencies in PHP projects. Follow these steps to update Composer to the latest version:

2.1 Download Composer Installer

Run the following command to download the latest Composer installer:

curl -sS https://getcomposer.org/installer | php -- --2

This command downloads the composer.phar file to your current directory.

2.2 Move Composer to a Global Directory

  1. Create a bin directory in your home folder if it doesn’t exist:

    mkdir -p ~/bin

     

  2. Move composer.phar to the bin directory:

    mv composer.phar ~/bin/composer

     

 

2.3 Add Composer to Your PATH

  1. Open your .bashrc file:

    nano ~/.bashrc

     

  2. Add the following line to include ~/bin in your PATH:

    export PATH="$HOME/bin:$PATH"

     

  3. Save the file and reload the shell configuration:

    source ~/.bashrc

     

  4. Verify the Composer version:

  5.  

    composer --version

     

    If the output shows the latest version, Composer has been successfully updated.

 

Troubleshooting

PHP Version Not Updated

If PHP does not update:

  • Ensure the alias points to the correct path (e.g., /opt/alt/php82/usr/bin/php).

  • Check the active PHP binary using:

  • which php

Composer Not Working

If Composer fails to execute:

  • Verify the composer file has execute permissions:

  • chmod +x ~/bin/composer
  • Ensure ~/bin is in your PATH.

 

Conclusion

By following this guide, you can seamlessly update PHP and Composer versions on Hostinger using SSH CLI without needing sudo access. This approach empowers developers to maintain an up-to-date development environment even in shared hosting scenarios.

 

 

FAQs

1. Can I update PHP on Hostinger without SSH?

Yes, you can use Hostinger’s control panel to switch PHP versions without SSH access.

2. Why do I need to update Composer?

Composer updates improve performance, add features, and ensure compatibility with modern PHP versions and packages.

3. What if I don't have curl installed?

You can use wget as an alternative to download the Composer installer:

wget -O composer-setup.php https://getcomposer.org/installer
php composer-setup.php --2

 

Keep your tools updated for better performance and compatibility! If you face any issues, let us know in the comments below.

 

  • Technology
showkat ali Author

showkat ali

Greetings, I'm a passionate full-stack developer and entrepreneur. I specialize in PHP, Laravel, React.js, Node.js, JavaScript, and Python. I own interviewsolutionshub.com, where I share tech tutorials, tips, and interview questions. I'm a firm believer in hard work and consistency. Welcome to interviewsolutionshub.com, your source for tech insights and career guidance.

0 Comments

Post Comment

Recent Blogs

Recent posts form our Blog

The Power of Feedback: How Regular Check-Ins Can Transform Employee Performance and Engagement

The Power of Feedback: How Regular Check-Ins Can Transform Employee Performance and Engagement

rimsha akbar
/
Human Resource

Read More
Laravel 11 Cron Job Task Scheduling with Example

Laravel 11 Cron Job Task Scheduling with Example

showkat ali
/
Programming

Read More
Understanding Laravel's whereAny and whereAll: A Tutorial with SQL Examples

Understanding Laravel's whereAny and whereAll: A Tutorial with SQL Examples

showkat ali
/
Programming

Read More
Mastering Conditional Logic in Laravel with when() and unless() Methods

Mastering Conditional Logic in Laravel with when() and unless() Methods

Asfia Aiman
/
Programming

Read More
Seamless Python Deployment to AWS EC2 Using GitHub Actions

Seamless Python Deployment to AWS EC2 Using GitHub Actions

showkat ali
/
Programming

Read More
Polymorphic Relationships in Laravel: A Comprehensive Guide with Example

Polymorphic Relationships in Laravel: A Comprehensive Guide with Example

showkat ali
/
Programming

Read More