Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
How to Install PHP 7 on Ubuntu Linux 14.04 LTS
PHP is a server-side scripting language designed for web development but also used as a general-purpose programming language. Originally created by Rasmus Lerdorf in 1994, the PHP reference implementation is now produced by The PHP Group. The latest version PHP is PHP7 and it provides 2x faster performance and 50% better memory consumption than PHP version 5.6. This article explains "How to install PHP7 on Ubuntu Linux".
Prerequisites: Ubuntu 14.04 LTS system with sudo privileges and internet connection.
Before installing PHP7, you should need to install a PPA called ondrej/php. This allows you to co-install PHP versions 5.6 and 7.0.
Configuring a PPA for co-installable PHP 5.6 + 7.0
To configure a PPA, use the following command −
$ sudo add-apt-repository ppa:ondrej/php
The sample output should be like this −
Co-installable PHP versions: PHP 5.6, PHP 7.0 and batteries included. You can get more information about the packages at https://deb.sury.org For PHP 5.6 use: ppa:ondrej/php5-5.6 For PHP 5.5 use: ppa:ondrej/php5 For PHP 5.4 use: ppa:ondrej/php5-oldstable BUGS & FEATURES: This PPA now has a issue tracker: https://deb.sury.org/pages/bugreporting.html PLEASE READ: If you like my work and want to give me a little motivation, please consider donating: https://deb.sury.org/pages/donate.html WARNING: add-apt-repository is broken with non-UTF-8 locales, see https://github.com/oerdnj/deb.sury.org/issues/56 for workaround: # LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php ...........................
To update the package index, use the following command −
$ sudo apt-get update
Installing PHP 7.0
For listing all PHP packages, use the following command −
$ sudo apt-cache search php7
To install PHP7, use the following command −
$ sudo apt-get install php7.0
The installation will automatically handle dependencies and may remove older PHP 5.x versions. You can also install specific modules like php7.0-mysql, php7.0-curl, or php7.0-gd as needed.
Configuring Nginx with PHP 7
If you're using Nginx, you'll need to configure it to work with PHP 7 FPM. First, ensure Nginx is installed −
$ sudo apt-get install -y nginx
Edit the Nginx configuration file −
$ sudo vi /etc/nginx/sites-available/default
Add the following PHP configuration block −
# Pass all .php files onto a php-fpm/php-fcgi server.
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
Save and reload the nginx server −
$ sudo service nginx reload
Testing PHP 7 Installation
Create a test file to verify PHP 7 is working correctly −
$ sudo vi /var/www/html/test.php
Add the following content −
<?php
phpinfo();
?>
Access the test file in your browser −
http://localhost/test.php
You should see the PHP information page showing PHP version 7.0.x.
Conclusion
You have successfully installed PHP 7 on Ubuntu 14.04 LTS using the ondrej/php PPA. PHP 7 offers significant performance improvements over PHP 5.6, making it an excellent choice for web development projects.
