Vishal
Posted on November 15th
How to install Composer on Ubuntu
"How to install Composer on Ubuntu"
Ubuntu
Ubuntu, an open source operating system based on Debian is widely favored for its user interface and robust community backing. It was also known for its user-friendliness, providing the GNOME desktop environment by default. It provides APT (Advance package manager) package manager for handling the system and it is very easy to use it provides regular updates. Ubuntu is suitable for personal use, development, servers, and educational purposes
Features
- Regular Updates and Release: Ubuntu Follows a biannual release cycle. It is released it new update on every April and October. There are long-term Support (LTS) versions that are released
- User-friendly interface: Ubuntu provides a modern graphical user interface (GUI) using GNOME. Ubuntu offers Kubuntu (KDE) and Lubuntu (LXQt).
- Software and Package Management: Ubuntu uses the APT package management system and offers a large number of repositories and software packages. Users can easily install and update the software from the Ubuntu App Center and using command lines such as sudo apt install package-name
- Security: Ubuntu is known for strong security practices, including regular updates, a dedicated security team, a built-in firewall, and encryption tools
- Community Support; Ubuntu boasts an engaged community that provides documentation, forums and support resources for users.
Introduction
Composer serves as an open source tool, for managing dependencies in PHP projects while Laravel stands out as a PHP framework. By handling libraries packages and dependencies Composer streamlines version testing. Ensures project consistency.
Features of Composer
- Autoloading: The composer can automatically generate an autoload file to include classes
- Version Control: The composer makes sure that the correct version of libraries is used in the project
- Dependency Management: Composer resolves and installs the necessary library and packages for the project.
- Packagist: Composer works very closely with Packagist, the default package repository for PHP, where developers can find and publish packages easily.
Step 1 - Installing PHP
PHP, also known as Hypertext Preprocessor is a known server-side scripting language used for web development. Its reputation lies in its user nature and simplicity allowing developers to craft websites and apps effortlessly. PHP seamlessly integrates with HTML, CSS, and JavaScript while supporting databases, like MySQL and PostgreSQL. This language is the driving force behind content management systems such as WordPress, Drupal and Joomla. Boasting documentation and a thriving community PHP provides an array of frameworks (such as Laravel and Symfony) and libraries that enrich its capabilities making it a versatile and robust tool, for constructing web applications.
Features of PHP
- Flexibility: It supports a wide range of databases including MySQL, PostgreSQL, and SQLite
- Simplicity: it is very simple and easy to understand, which helps beginners to learn
- Open-Source: PHP is open-source and free to use, which makes it a cost-efficient for web developers.
- Integration: PHP can easily work with various web technologies like HTM, CS, JavaScript, and AJAX.
- Community Support: A large number of developers contribute to PHP and provide documentation, libraries, and frameworks
First, run this command to find out the latest version packages and dependencies:
sudo apt update
About sudo
Sudo (SuperUser do) is a command in Linux that allows users to run commands with privileges that only root users have. It helps users to do tasks with administrative power without logging in as the root user.
Features
- Privilege Management: Allows authorized users to execute commands with elevated privileges.
- Logging: Logs all sudo commands to /var/log/auth.log, which is useful for auditing and troubleshooting.
- Temporary Elevation: Users can perform administrative tasks without staying in a privileged shell.
About APT
apt (Advance Package Tool) is a command line tool to download, update, and remove packages from Debian-based Linux distributions, like Ubuntu. it makes managing software very easy. apt is the front-end for dpkg, the Debian package manager
Feature
- Package Management: apt make handling package (install, update, and remove) very easy
- Dependency Resolution: it automatically handles dependencies and ensures that all necessary packages are installed and updated
- Search Functionality:
Then, run this command to install PHP packages:
sudo apt install php-cli
You might see some prompt then type y and press Enter
To verify, that your PHP is installed successfully, check its version with this command:
php -v
Output
PHP 8.2.10 ...
Step 2 - Download and Install Composer
Make sure you are in your home directory and curl is installed in your system
About cURL
sudo (short for "superuser do") is a command-line program available on Unix-like operating systems, including Linux, and macOS, that allows an authorized user to execute commands with the protection of another user privileged, usually superuser (root) . Provides access to controlled basic-level functions. Sudo logs every command and requires user authentication, increasing security by reducing the risk of accidental configuration changes and unauthorized access. Sudo license settings are managed through the /etc/sudoers file, which allows user rights and command functions to be managed.
Why use cURL
- It's portable and supported by almost every operating system
- It can be run directly from the command line, which makes it faster and easy
- cURL is mainly used in scripting for automatic processes like downloading files, testing API endpoints, and transferring data between servers.
- cURL is used for checking API endpoints and web services. It helps to debug errors by showing details about request and response information
- it’s a very lightweight tool that does not require heavy dependencies or installation.
Install cURL
If curl is not installed on your system, run this command:
sudo apt install curl
To make sure, check the version of the curl:
curl --version
Output:
curl 8.2.1 (x86_64-pc-linux-gnu) ...
Use this command to move to your home directory.
cd ~
Run this
curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php
After installing, verify that your downloaded installer matches the SHA-384 hash:
HASH=`curl -sS https://composer.github.io/installer.sig`
if you want to verify the obtained value, run this:
echo $HASH
Output
dac665fdc30fdd8ec78b38b9800061b4482413ff2e3b6u88543c636f7cd84f6db92658d43a81e5503cda447da73c7e5b6
Now run the following command, as provided in the Composer download page, to verify that the installation script is safe to run:
php -r "if (hash_file('SHA384', '/tmp/composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
Output
Installer verified
If you get an output Installer corrupt then download the installer script again,
When everything is done run this:
composer
Output
______
/ ____/___ ____ ___ ____ ____ ________ _____
/ / / __ / __ /__ / __ / __ / ___/ _ / ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ /
____/____/_/ /_/ /_/ .___/____/____/___/_/
/_/
Composer version 2.5.8 2023-06-09 17:13:21
If you get this it means you have successfully downloaded Composer on your pc
