Saturday, September 12, 2020

How to install PHP on Linux/Unix System



Hello dear readers! welcome back to another section of my 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 types of Unix, then here is the list of prerequisites -

  • A working PHP-supported database, if you intend using one (For example MySQL, Sybase, Oracle etc.)
  • And any other supported software 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 steps for installing Apache and PHP5 on your Linux/Unix System. If your Apache or PHP versions are not the same with the once used in this tutorial guide, then take care accordingly.

  • If you haven't already done so, unzip and 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
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 using the MySQL database.

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

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

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

RECOMMENDED: An Overview of PHP

  • Now tell 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.
    • Now go to your HTTP configuration files i.e. (/usr/local/apache/conf or anything your path is)
    • Open httpd.conf with a text editor
    • Search for the word DocumentRoot (which should display twice), and change both paths to the directory you want to serve files out of (in our case we used the /home/httpd). We also recommend you use 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. This is the directory that all your PHP files will be kept.
  • 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 added 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 a world-executable. The actual PHP files in the directory need only be world-readable (644). If necessary, replace the /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 http://127.0.0.1/info.php) rather than using a filename (/home/httpd/info.php) in order for the file to be parsed correctly.

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


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

Feel free to ask your questions where necessary and i 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.
Share:

0 comments:

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.