RackNerd Billboard Banner

How to Install PHP on Ubuntu

PHP is one of the most popular server-side scripting languages, powering platforms like WordPress, Laravel, and Drupal. If you’re setting up a web server on Ubuntu, installing PHP is one of your first steps.

This guide walks you through installing PHP on Ubuntu, testing it, and making sure it’s ready for your projects.


Step 1: Update Your Package List

Before installing any software, it’s a good idea to update your system’s package index. Open your terminal and run:

sudo apt update && sudo apt upgrade -y

This ensures you get the latest package versions and security patches.


Step 2: Install PHP

To install PHP, run:

sudo apt install php -y

This will install the latest PHP version available in Ubuntu’s default repositories. If you need a specific version, you can use:

sudo apt install php8.2 -y

(Replace 8.2 with the version you need.)


Step 3: Install Common PHP Extensions

Many applications require PHP extensions for extra functionality. Some common ones are:

sudo apt install php-cli php-mysql php-zip php-gd php-mbstring php-curl php-xml php-bcmath -y

This covers the most used extensions for frameworks and CMS platforms.


Step 4: Verify the Installation

Check your PHP version with:

php -v

You should see output like:

PHP 8.2.x (cli) (built: ...)
Copyright (c) The PHP Group
Zend Engine v4.2.x, Copyright (c) Zend Technologies

Step 5: Configure PHP (Optional)

You can edit the PHP configuration file to adjust settings like memory limits, upload sizes, and execution time:

sudo nano /etc/php/8.2/apache2/php.ini

(Replace 8.2 with your version.)
After making changes, restart Apache or Nginx:

sudo systemctl restart apache2
# or
sudo systemctl restart nginx

Step 6: Test PHP in Your Web Server

Create a test file in your web root:

sudo nano /var/www/html/info.php

Add this line:

<?php phpinfo(); ?>

Save and exit. Then, open your browser and visit:

http://your_server_ip/info.php

If you see the PHP info page, you’ve successfully installed PHP.


Final Thoughts

Installing PHP on Ubuntu is quick and straightforward. With PHP installed and configured, you’re ready to run powerful web applications and frameworks. Remember to remove the info.php file after testing—it can expose sensitive server details.


Tip: If you’re setting up a complete web server, check out our guides on installing Apache/Nginx and MySQL to create a full LAMP or LEMP stack.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
RackNerd Billboard Banner
© 2025 Computer Everywhere
Your Everyday Guide to the Digital World.
Terms of Service | Privacy Policy
Copy link