X
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.
This wikiHow teaches you how to install the latest version of PHP on your Ubuntu Linux computer.
Steps
-
1Make 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:
- Click , then click the tool icon in the drop-down menu.
- Click Details.
- Click the About tab.
- Check the version number next to the "Ubuntu" heading at the top of the window.
- Update if necessary by clicking Check for updates and following any on-screen prompts.
-
2Open 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.
-
3Tell Terminal to install PHP. Type the following code into Terminal, then press ↵ Enter:[1]
sudo apt-get install php
-
4Enter 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.
-
5Confirm the installation. Type in y when prompted, then press ↵ Enter. PHP will begin installing.
-
6Verify that PHP installed correctly. Once you're able to type again, enter the following code:
php -v
-
7Look 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.
-
8Install 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
-
9Check 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
-
10Set 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.Thanks!


























































