PHP is a popular framework used in popular open source content management systems.. How do you install it in Ubuntu?
If you’re going to be doing any kind of PHP development, you’ll almost always going to need PHP and a web server. WordPress, Joomla and other content management systems will require PHP and a web server to function.
This simple tutorial is going to show you how to install PHP on Ubuntu if you don’t already know how.
Since Apache2 is the most popular web server in used today, we’re going to be using it with PHP. We’ve already shown you how to install Apache2 in another tutorial.
Read this post below to learn how to install Apache2 on Ubuntu.
Student Assignment: Install and Configure Apache2 On Ubuntu
After installing Apache2, continue below to install PHP.
Step 1: Installing PHP on Ubuntu
To install PHP on Ubuntu, run the commands below.
sudo apt-get -y install php
The above commands install PHP and PHP module for Apache2. The module allows PHP to interact with Apache2. Without that module, PHP and Apache2 won’t be able to function together.
Step 2 : Other important PHP modules to install
The above commands install PHP and a single Apache2 module. However, if you’re going to be developing or working with most content management systems, there are other very important PHP modules to install.
Use the commands below to install those modules.
sudo apt-get -y install php-mysql php-curl php-gd php-pear php-imagick php-imap php-mcrypt php-recode php-tidy php-xmlrpc
Step 3: Testing PHP Installation
The last thing to do after installing PHP is to test it to make sure it’s functioning. To test it, create a test file called testphp.php in Apache2 root directory and add these lines in it, then save the file.
sudo nano /var/www/html/testphp.php
Add these line and save the file.
Next, open your browser and browse to the server IP or hostname, and to the test file and you should see a test page as shown below.
This is how to install PHP on Ubuntu servers.