This wikiHow teaches you how to install the latest version of PHP on your Ubuntu Linux computer.

Steps

  1. 1
    Make sure that your version of Ubuntu is up-to-date. As of August 2018, the most recent version of Ubuntu Linux is 18.04. You can check your version of Ubuntu by doing the following:
  2. 2
    Open Terminal. Click the Terminal app icon, which resembles a black box, on the left side of the desktop. This will open the Terminal window.
    • You can also just press Alt+Ctrl+T to open Terminal.
  3. 3
    Tell Terminal to install PHP. Type the following code into Terminal, then press Enter:[1]
    sudo apt-get install php
    
  4. 4
    Enter your password when prompted. Type in the password you use to log into your computer, then press Enter.
    • Neither your password nor stand-in characters will display in Terminal when you type.
  5. 5
    Confirm the installation. Type in y when prompted, then press Enter. PHP will begin installing.
  6. 6
    Verify that PHP installed correctly. Once you're able to type again, enter the following code:
    php -v
    
  7. 7
    Look for a confirmation message. You should see a verification message inside Terminal that reads something like "PHP 7.2.7-0ubuntu0.18.04.2 (cli) (built: [date]) (NTS)". This confirms that PHP finished installing correctly.
  8. 8
    Install common PHP modules if needed. If you're working with PHP in an environment that requires add-ons, you can install commonly used ones by entering the following code into Terminal and then pressing Y and pressing Enter:
    sudo apt-get install php-pear php-fpm php-dev php-zip php-curl php-xmlrpc php-gd php-mysql php-mbstring php-xml libapache2-mod-php
    
  9. 9
    Check for additional modules if you like. You can look up a list of available modules by entering the following code:
    apt-cache search --names-only ^php
    
  10. 10
    Set PHP 7.2 as the default version. If you want to use PHP 7.2 as your computer's default version, do the following:
    sudo update-alternatives --set php /usr/bin/php7.2
    

Warnings

  • The steps for installing PHP on older versions of Ubuntu (e.g., 16.04) differ from the steps in this article.

About This Article

JL
Written by:
Tech Specialist
This article was written by Jack Lloyd. Jack Lloyd is a Technology Writer and Editor for wikiHow. He has over two years of experience writing and editing technology-related articles. He is technology enthusiast and an English teacher. This article has been viewed 5,487 times.
How helpful is this?
Co-authors: 9
Updated: March 29, 2019
Views: 5,487
Categories: PHP