How to Update PHP and Composer Versions Using SSH CLI Without Sudo on Hostinger
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):
-
Open your
.bashrcfile to set a new alias:nano ~/.bashrc -
Add or update the alias for PHP:
alias php=/opt/alt/php82/usr/bin/php -
Save the file and reload it:
source ~/.bashrc -
Verify the updated PHP version:
If the output shows PHP 8.2 (or your desired version), the update was successful.php --version
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
-
Create a
bindirectory in your home folder if it doesn’t exist:mkdir -p ~/bin -
Move
composer.pharto thebindirectory:mv composer.phar ~/bin/composer
2.3 Add Composer to Your PATH
-
Open your
.bashrcfile:nano ~/.bashrc -
Add the following line to include
~/binin your PATH:export PATH="$HOME/bin:$PATH" -
Save the file and reload the shell configuration:
source ~/.bashrc -
Verify the Composer version:
-
composer --versionIf 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
composerfile has execute permissions: -
chmod +x ~/bin/composer -
Ensure
~/binis 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.
0 Comments
Like 0