If you’re trying to configure PHP into your Ubuntu Linux, you definitely wouldn’t need an explanation about what PHP or Ubuntu is. So, let’s get our geek on and dive in!
There are two ways to install PHP on your Ubuntu.
Before you begin:
Make sure you’re logged in as a user with Sudo privileges.
This one is pretty simple. All you need to do is:
Add deb http://security.ubuntu.com/ubuntupool/main/p/php5/ hardy- security main
in your /etc/apt/sources.list
This is a little more complex and involves everything from downloading PHP to finally setting it up.
Step 1. Download
If you have tried downloading before, you already know getting PHP for you Ubuntu isn’t as easy as downloading your favorite movies or songs. So, here’s a detailed instruction on how you can obtain the PHP for Ubuntu.
- First, go to packages.ubuntu.com
- As soon as you open the site, you’ll see a list of packages. Don’t be confused with or hung up on all the packages, scroll down to search package directories.
- Now, fill the search form.
Distribution: Select your Ubuntu Version
Don’t restrict your search by ticking on Show only the exact matches.
- Then, click search.
You will find a list of suits that matches your Ubuntu Version.
Find libapache2-mod-php7.4, then click on your Ubuntu version (It’s a link).
- The link will take you to another page. Look for Download libapache2-mod-php7.4. If you’re using a 64 bit AMD Processor, click on amd64. If you’re using an Intel processor, click on i386.
- You will, then finally be directed to a page that has a link http://security.ubuntu.com/ubuntu/pool/main/p/php5/libapache2-mod-php5_5.2.4-2ubuntu5.10_i386.deb. Click on that link and save the downloaded file.
Step 2. Install
Now, you have to install the PHP. Don’t freak out, it’s shorter and easier than the first step.
- Start the root terminal.
- Fire aptitude install php7.4 libapache2-mod-php7.4 command.
$sudo apt-get install php7.1
- As it is mandatory for you to have root privilege for installing PHP, you can use su or run it from the root terminal.
This command will show you the Current PHP Version.
- Use vi editor or text editor to open the page in the terminal .
- After that, copy-paste the php info <?php echo phpinfo(); ?> and save the file.
- Then, read and execute permissions for /var/www and all of its subdirectories and files.
- Then, restart the apache webserver with command /etc/init.d/apache2, if you’re using version 2. Change the command according to the version you are using.
Step 3. Test
Now that you have downloaded and installed PHP, it’s time to test it.
To test, open browser type URL, “HTTP://localhost/test.php”.
In the browser, you will see PHP info.
If PHP is installed, you’ll get ‘PHP successfully configured’ as an output.
We genuinely hope that this guide was useful to you. Feel free to leave your doubts in the comments section. We would be happy to help.