PHP 7 - Installation on Linux/Unix

If you plan to install PHP on Linux or any other variant of Unix, then here is the list of prerequisites −

Now, here are the steps to install Apache and PHP5 on your Linux or Unix machine. If your PHP or Apache versions are different then please take care accordingly.

Step 1

If you have not already done so, unzip and untar your Apache source distribution. Unless you have a reason to do otherwise, /usr/local is the standard place.

gunzip -c apache_2.4.x.tar.gz
tar -xvf apache_2.4.x.tar

Step 2

Build the apache Server as follows

cd apache_2.4.x
./configure --prefix=/usr/local/apache --enable-so
make install

Step 3

Unzip and untar your PHP source distribution. Unless you have a reason to do otherwise, /usr/local is the standard place.

gunzip -c php-7.x.tar.gz
tar -xvf php-7.x.tar
cd php-7.x

Step 4

Configure and Build your PHP, assuming you are using MySQL database.

./configure --with-apxs=/usr/sbin/apxs \
make install

Step 5

Install the php.ini file. Edit this file to get configuration directives −

cd ../../php-7.x
cp php.ini-development /usr/local/lib/php.ini

Step 6

  • Tell your Apache server where you want to serve files from, and what extension(s) you want to identify PHP files A .php extension is standard, but you can use .html, .phtml, or whatever you want.

    • Go to your HTTP configuration files (/usr/local/apache/conf or whatever your path is)

    • Open httpd.conf with a text editor.

    • Search for the word DocumentRoot (which should appear twice), and change both the paths to the directory you want to serve files out of (in our case, /home/httpd). We recommend a home directory rather than the default /usr/local/apache/htdocs because it is more secure, but it does not have to be in a home directory. You will keep all your PHP files in this directory.

  • Add at least one PHP extension directive, as shown in the first line of the code that follows. In the second line, we have also added a second handler to have all HTML files parsed as PHP.

AddType application/x-httpd-php .php
AddType application/x-httpd-php .html

Step 7

Restart your server. Every time you change your HTTP configuration or php.ini files, you must stop and start your server again.

cd ../bin
./apachectl start

Step 8

Set the document root directory permissions to world-executable. The actual PHP files in the directory need only be world-readable (644). If necessary, replace /home/httpd with your document root below −

chmod 755 /home/httpd/html/php

Step 9

Open a text editor. Type: <?php phpinfo(); ?>. Save this file in your Web server's document root as info.php. Start any Web browser and browse the file. You must always use an HTTP request ( or http://localhost/info.php or rather than a filename (/home/httpd/info.php) for the file to be parsed correctly.

You will see a long table of information about your new PHP installation message Congratulations!