PHP is one of the most used languages when it comes to programming dynamic web sites. If you are a web developer, or just hosting a website that requires PHP, you will need to install the software on your server in order for your website to make use of its PHP code.
PHP is also required by various content management systems, including the most popular one in the world, WordPress. In this tutorial, we will take you through the step by step instructions to install PHP on Ubuntu Linux.
In this tutorial you will learn:
- How to install PHP on Ubuntu Linux
- How to verify proper installation of PHP
- How to install additional PHP modules
|Category||Requirements, Conventions or Software Version Used|
|Other||Privileged access to your Linux system as root or via the
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
How to install PHP on Ubuntu Linux step by step instructions
- Start by opening a command line terminal on your Ubuntu system and typing the following commands to install PHP from your system’s package manager.
$ sudo apt update $ sudo apt install php
This will install the latest PHP package available from Ubuntu’s software repository, along with some additional, related packages in most cases. If you do not already have a web server installed, Apache will also be installed with PHP, as indicated in our screenshot below.
- After PHP has been installed, you can use the following command to verify that it works properly.
$ php -version
- A better way to ensure that PHP works on your web server is to use the
phpinfofunction, but inside of a php file. The perk of this method is that all the information will be formatted nicely for us and viewable inside a browser. We have a full guide on how to create a phpinfo.php page, but it basically just involves saving a PHP file with the following line of code and then accessing it from your browser.
- Note that you may need to install additional PHP modules later. Some are required by WordPress, such as those below:
$ sudo apt install php-mysql php-curl php-xml php-mbstring php-imagick php-zip php-gd
In this tutorial, we saw how to install PHP on Ubuntu Linux. We also learned how to verify proper installation of PHP by accessing a test page in web browser, and how to install additional modules that are used in some content management systems. This should be everything you need in order to get started with developing PHP websites or hosting them on your server.