We now have a youtube channel. Subscribe!

How to install PHP on Linux/Unix System

How to install PHP on Linux/Unix System

Hello folks! Welcome back to a new section of our tutorial on PHP. In this tutorial guide, we are going to be discussing about how to install PHP on Linux/Unix System.

If you plan installing PHP on Linux or any other variant of Unix, then here is the list of prerequisites -

  • A working PHP-supported database, if you intend utilizing one (For example MySQL, Sybase, Oracle etc.)
  • And any other supported software to which PHP must connect (mail server, JDK, BCMath package, etc.)
  • An ANSI C compiler

Steps to Install Apache and PHP on Linux

The following below are the simple steps to install Apache and PHP5 on your Linux/Unix System. If your Apache or PHP versions are different from the once used in this tutorial guide, then take care accordingly.

  • If you have not already done so, unzip and then extract your Apache source distribution. Unless you intend to do otherwise, /usr/local is the standard place.

gunzip -c apache_1.3.x.tar.gz
tar -xvf apache_1.3.x.tar

  • Build the Apache server as follows -

cd apache_1.3.x
./configure --prefix=/usr/local/apache --enable-so
make install

  • Unzip and extract your PHP source distribution. Unless maybe you have a reason to do otherwise, /urs/local is the standard place.

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

  • Configure and then Build your PHP, assuming you are utilizing the MySQL database.

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

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

cd ../../php-5.x
cp php.ini-dist /usr/local/lib/php.ini

  • Now inform your Apache server where you want to serve files from, and what extension(s) you want to recognize a PHP file as; .php is the standard but you can use .html, .phtml or any other thing that you are comfortable with.
    • Go to your HTTP configuration files i.e. (/usr/local/apache/conf or anything your path is)
    • Open httpd.conf making use of a text editor
    • Look for the word DocumentRoot (which should show twice), and then change both paths to the directory you want to serve files out of (in our case we used the /home/httpd). We recommend a home directory instead of the default /usr/local/apache/htdoc because it is very much secured, also it doesn't have to be a home directory. You will keep all your PHP files in this directory.
  • Now add at least one PHP extension directive, as it is shown in the first line of code that follows. In the second line, we have also included a second handler to have all HTML files parsed as PHP.

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

  • Restart your Server. Every time that you change your HTTP configuration or the php.ini files, you must stop and restart your server.

cd ../bin
./apachectl start

  • Now set the document root directory permissions to world-executable. The actual PHP files in the directory need only be world-readable (644 directory and file permission). If needed, replace /home/https with your document root below -

chmod 755 /home/httpd/html/php

  • Open a text editor and then type: <?php phpinfo(); ?>. Then save this file in your Web server's document root as info.php.
  • Open any Web browser and browse the file. You must always make use of an HTTP request. For example, use (http://www.domain.com/info.php or http://localhost/info.php or better still instead a filename (/home/httpd/info.php) for the file to be parsed correctly.

You should see a long table of information about your new PHP Installation message.

Alright guys! This is where we are rounding up for this tutorial post. In our next tutorial guide, we are going to be discussing about PHP Installation on Mac OS X with Apache.

Feel free to ask your questions where necessary and we will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.

Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.

Thanks for reading and bye for now.

Post a Comment

Hello dear readers! Please kindly try your best to make sure your comments comply with our comment policy guidelines. You can visit our comment policy page to view these guidelines which are clearly stated. Thank you.
© 2023 ‧ WebDesignTutorialz. All rights reserved. Developed by Jago Desain