How to Install PHP on an Apache Web Server in Linux


In this article, we show how to install PHP on an apache web server on a linux machine.

So the apache web server is a type of server that is widely used on the web.

Apache powers over 50% of websites on the web.

It can run versatile scripting languages such as PHP, Perl, etc.

In this article, we will show how to install PHP on an apache web server using the Ubuntu linux operating system.

PHP is of course a dynamic scripting language that can generate dynamic output for a website, based on whatever variables are used.

To install on the apache web server in linux, we first want to make sure our linux server is up to date.

To do this, we run the following two lines of code below.

These two lines perform the necessary updates and upgrades to the linux system.

Now we are ready to install PHP on the apache web server.

This is done by the following line shown below.

This line above will install the latest version of PHP (which as of this writing is PHP 7.1).

This should look something such as shown below.

Installing PHP 7.1 on apache web server in linux

Once this has been successfully installed, you can now run PHP on the web server.

How can you test this?

If you're in the home directory (/), then you can type in the following line.

What this line does is it creates a PHP file, called test.php

Now you can just write some PHP code in this file, such as that shown below.

Now this line will output "Hello David" in HTML h1 tags.

You can then close out of this file by pressing Ctrl+X and making sure that you save the file.

Now if you go to a web browser and type in the IP address followed by /test.php (IP address/test.php), you should see this test PHP file.

And this is how you can install PHP and run a test page of PHP code on an apache server in Ubuntu linux.

Related Resources

How to Randomly Select From or Shuffle a List in Python

HTML Comment Box is loading comments...