Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

Install PHP with Dependencies

Premium
9 min read

We're getting closer to actually installing our Laravel project. But Laravel is a PHP framework, and guess what - we don't have PHP installed on the server yet. Let's fix this.

  1. Time to review our requirements once again, and determine which Ubuntu packages we need to install:

As per Laravel requirements:

  • BCMath PHP Extension - php8.1-bcmath - provides arbitrary-precision arithmetic
  • Ctype PHP Extension - php8.1-common - checks whether a character or string falls into a certain character class according to the current locale
  • cURL PHP Extension - php8.1-curl - allows you to connect and communicate to many different types of servers with many different types of protocols
  • DOM PHP Extension - php8.1-xml - allows you to operate on XML documents through the DOM API with PHP
  • Fileinfo PHP extension - php8.1-common - functions in this module try to guess the content type and encoding of a file
  • JSON PHP Extension - Always available - implements the JavaScript Object Notation (JSON) data-interchange format
  • Mbstring PHP Extension - php8.1-mbstring - provides multibyte specific string functions that help you deal with multibyte encodings
  • OpenSSL PHP Extension - openssl - library for symmetric and asymmetric encryption and decryption
  • PCRE PHP Extension - Always available - PHP Core library with JIT support
  • PDO PHP Extension - php8.1-common - defines a lightweight, consistent interface for accessing databases
  • Tokenizer PHP Extension - php8.1-common - interface to the PHP tokenizer
  • XML PHP Extension - php8.1-xml - implements support for DOM, SimpleXML, XML, and XSL

And additional dependencies for our demo project...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (29 h 14 min)

You also get:

54 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

E
Eidmohd89 ✓ Link copied!

I am just trying to install php. I get the following errors. I tried this on ubuntu-bionic-18.04-amd64-server. I got the same error on later versions of Ubuntu. How can I get these issues.

apt-get install --no-install-recommends php7.3 php7.3-{bcmath,cli,common,curl,fpm,gd,mbstring,mysql,xml,zip} openssl composer Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package php7.3 E: Couldn't find any package by glob 'php7.3' E: Couldn't find any package by regex 'php7.3' E: Unable to locate package php7.3-bcmath E: Couldn't find any package by glob 'php7.3-bcmath' E: Couldn't find any package by regex 'php7.3-bcmath' E: Unable to locate package php7.3-cli E: Couldn't find any package by glob 'php7.3-cli' E: Couldn't find any package by regex 'php7.3-cli' E: Unable to locate package php7.3-common E: Couldn't find any package by glob 'php7.3-common' E: Couldn't find any package by regex 'php7.3-common' E: Unable to locate package php7.3-curl E: Couldn't find any package by glob 'php7.3-curl' E: Couldn't find any package by regex 'php7.3-curl' E: Unable to locate package php7.3-fpm E: Couldn't find any package by glob 'php7.3-fpm' E: Couldn't find any package by regex 'php7.3-fpm' E: Unable to locate package php7.3-gd E: Couldn't find any package by glob 'php7.3-gd' E: Couldn't find any package by regex 'php7.3-gd' E: Unable to locate package php7.3-mbstring E: Couldn't find any package by glob 'php7.3-mbstring' E: Couldn't find any package by regex 'php7.3-mbstring' E: Unable to locate package php7.3-mysql E: Couldn't find any package by glob 'php7.3-mysql' E: Couldn't find any package by regex 'php7.3-mysql' E: Unable to locate package php7.3-xml E: Couldn't find any package by glob 'php7.3-xml' E: Couldn't find any package by regex 'php7.3-xml' E: Unable to locate package php7.3-zip E: Couldn't find any package by glob 'php7.3-zip' E: Couldn't find any package by regex 'php7.3-zip'

PK
Povilas Korop ✓ Link copied!

I saw your comment on the later lesson, so does it mean you successfully installed PHP?

SJ
Stephenson Jacob ✓ Link copied!

For people having same problem. Ubunto version should be check if it's compatible with what php version. I fixed mine by changing php version. For me it was PHP8.3.

root@ip-172-31-44-101:~# apt-get install --no-install-recommends php8.3 php8.3-{bcmath,cli,common,curl,fpm,gd,mbstring,mysql,xml,zip} openssl composer

if continuing with this will have 502 bad gateway php8.1 should be change to php8.3 in this code.

location ~ .php$ { fastcgi_pass unix:/var/run/php/php8.1-fpm.sock; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; include fastcgi_params; }

GK
Gavin Kimpson ✓ Link copied!

Not overly important - but my phpinfo file is correctly showing FPM/FastCGI (nginx) but when going to the top level domain (e.g remove the phpinfo.php from the URL) I am seeing an Apache2 Default page?

Any idea why this is as I have stopped Apache?