J

PHP and Composer are the most essential tools in the web development world. PHP is a server-side language used to create enterprise-level web applications while the composer is a dependency manager for PHP. Composer is used to installing a lot of PHP frameworks like Laravel, Symfony, Codeigniter, and many more. While composer is widely used to install PHP frameworks, it needs PHP as a dependency, meaning PHP should be installed before we use and install composer. Let's see first how to install PHP on linux mint.

PREREQUISITES?

  • You will require sudo privilages on your system.

PART 01: HOW TO INSTALL PHP?

Installing PHP on linux mint is very simple.

1. Press Ctrl + Alt + T to open the terminal and update packages.

Copied!
sudo apt update

2. Remove any existing PHP installation if you already have any.

Replace the 7.* with you php version. You can check your php version by typing php -v in the terminal.

Copied!
sudo apt-get purge php7.* sudo apt-get autoclean sudo apt-get autoremove

You can enable a disable PHP version by running sudo a2enmod php5.6. Similarly, you can enable any php version by running sudo a2dismod php7.2. Don't forget to replace the version with your php version.

3. Adding a PPA repository

This step is very important, we will be adding a PPA repository. The PPA is maintained by Ondřej Surý, a Debian developer who has been packaging PHP for Debian since PHP 5. After adding this repository, you will be able to install any php version from PHP version 5 and above.

Copied!
sudo add-apt-repository ppa:ondrej/php

4. Installing Latest Version Of PHP

Now, you can install any version of PHP, you just need to replace you version no with 8.2. Currently at the time of writing this blog current version of PHP is 8.2.5 and the below command will install the latest version which is 8.2.5 wheather we specify .5 at the end or not.

Copied!
sudo apt-get install php8.2

5. Install Important Eextensions

Here, we will be installing important PHP extensions that are usually required to run PHP smoothly. Don't forget to replace 8.2 with the version number of PHP you have currently installed.

Copied!
sudo apt install php8.2-common php8.2-mysql php8.2-xml php8.2-xmlrpc php8.2-curl php8.2-gd php8.2-imagick php8.2-cli php8.2-dev php8.2-imap php8.2-mbstring php8.2-opcache php8.2-soap php8.2-zip php8.2-intl -y

6. Test your PHP installation

There are multiple ways to test the PHP installation.

Copied!
php -v

If it will output like this with version number, it means you have successfully installed PHP on your system.

If you want to check weather PHP is running smoothly or it has issues. Simply, make a php file and run it through the terminal.

Copied!
sudo nano test.php

Copy the below code and paste it into the terminal

Copied!
echo "hello world";

Now, press Ctrl + X and hit Enter. Your file will be saved. Run the following command.

Copied!
php test.php

If it outputs something like this, you have successfully installed PHP.

PART 02: HOW TO INSTALL COMPOSER?

In order to install composer you must have installed PHP.

2. Download The Installer

We will download the installer in our current directory.

Copied!
sudo php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

3. Checking File Hash

We can check hash manually by clicking here. But we will by using the below command to check the file hash.

Copied!
sudo php -r "if (hash_file('sha384', 'composer-setup.php') === '55ce33d7678c5a611085589f1f3ddf8b3c52d662cd01d4ba75c0ee0459970c2200a51f492d557530c71c15d8dba01eae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

4. Running The Installer

You have to run the installer using the below command in order to install composer.

Copied!
sudo php composer-setup.php

5. Removing The Installer

Finally we will remove the installer to cleanup some things.

Copied!
sudo php -r "unlink('composer-setup.php');"

6. Adding Composer to Our PATH

We have installed composer but we will not able to use it. We have to add it to our PATH.

Copied!
sudo mv composer.phar /usr/local/bin/composer

7. Testing Composer Installation

In order to test the composer installation, just run the following command.

Copied!
composer

If you see something like that in the terminal, it means that composer has been successfully installed.

PART 03: HOW TO INSTALL APACHE2 ON LINUX MINT?

1. Installing Apache

Apache or NginX server is ususally used with PHP to server client side requests. Just run

Copied!
sudo apt install apache2

Open your browser and goto http://localhsot, if you see something like this in the browser. Apache has been installed successfully.

2. Adding your user to the user group

Copied!
sudo usermod -a -G www-data mudassar id mudassar groups mudassar

3. Granting permissions to the group

Copied!
sudo chgrp -R www-data /var/www/html
M. Mudassar
M. Mudassar
Sr. Software Engineer

As a software engineer, I take great pride in my ability to innovate and create efficient solutions. The satisfaction of seeing my code come to life and delivering products that exceed expectations is what drives me. I'm constantly learning and expanding my skill set to stay up-to-date with the latest trends and technologies. Collaboration is key in the software development process, and I thrive in diverse teams. Whether it's debugging existing code or developing new applications, I approach each project with enthusiasm and dedication, always striving to learn and improve.