O'Reilly logo

Ubuntu Server Cookbook by Uday R. Sawant

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Serving dynamic contents with PHP

In this recipe, we will learn how to install PHP and set it to work alongside the Apache web server. We will install PHP binaries and then the Apache module mod_php to support PHP-based dynamic contents.

Getting ready

You will need access to a root account or an account with sudo privileges.

The Apache web server should be installed and working properly.

How to do it…

Follow these steps to serve dynamic contents with PHP:

  1. Install PHP7 and the Apache module for PHP support:
    $ sudo apt-get update
    $ sudo apt-get install -y php7.0 libapache2-mod-php7.0
    
  2. Check if PHP is properly installed and which version has been installed:
    $ php -v
    
  3. Create index.php under the public_html directory of our site:
    $ cd /var/www/example.com/public_html ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required