Pages

How to install php 7.0.0 in ubuntu

 

To install PHP 7.0 (or a version compatible with ^7.0.0) on Ubuntu, you can follow these steps. Note that PHP 7.0 is no longer officially supported, so you’ll need to add a repository that provides older PHP versions, such as Ondřej Surý's PPA.


Step 1: Add the Required PPA

Add Ondřej Surý's PPA repository, which maintains older PHP versions:

sudo add-apt-repository ppa:ondrej/php
sudo apt update

Step 2: Install PHP 7.0

Install PHP 7.0 and the necessary extensions:

sudo apt install php7.0

To install common PHP extensions for PHP 7.0, you can use:

sudo apt install php7.0-cli php7.0-fpm php7.0-mysql php7.0-xml php7.0-curl php7.0-mbstring php7.0-zip php7.0-bcmath

Step 3: Verify the Installation

Check the installed PHP version:

php -v

You should see output similar to:

PHP 7.0.x (cli) (built: ...)

Step 4: Configure PHP for Web Server (Optional)

If you are using a web server like Apache or Nginx, you need to enable PHP 7.0 for it.

For Apache:

  1. Disable the current PHP module (if any):

    sudo a2dismod php8.1
    
  2. Enable PHP 7.0:

    sudo a2enmod php7.0
    
  3. Restart Apache:

    sudo systemctl restart apache2
    

For Nginx:

Ensure the fastcgi_pass directive in your Nginx configuration points to the PHP 7.0 FPM socket, e.g., /run/php/php7.0-fpm.sock.

Restart PHP-FPM and Nginx:

sudo systemctl restart php7.0-fpm
sudo systemctl restart nginx

Step 5: Install Dependencies for Laravel (Optional)

To ensure compatibility with Laravel, install required PHP 7.0 extensions:

sudo apt install php7.0-tokenizer php7.0-json php7.0-openssl php7.0-pdo php7.0-fileinfo php7.0-mbstring

Notes:

  • PHP 7.0 is end-of-life, meaning it no longer receives security updates. It's highly recommended to use a supported PHP version (like PHP 8.x) for new projects.
  • If you must use PHP 7.0 for legacy applications, consider isolating it in a container or VM for security.


No comments:

Post a Comment