PHP - Installation

    PHP Installation

    You can easily install PHP on different platforms with this tutorial in very easy steps.

    Installing PHP on Linux/UNIX

    If you are installing PHP on the Linux system, then you should be prepared with- PHP source distribution, Apache source, PHP compatible database, C compiler, and Gnu utility.

    • We are starting with installing Apache and PHP. First, unzip your Apache at the default location /usr/local if you have not thought of other locations.
    gunzip -c apache_1.3.x.tar.gz
    tar -xvf apache_1.3.x.tar
    • Second, start building an Apache server.
    cd apache_1.3.x
    ./configure --prefix=/usr/local/apache --enable-so
    make
    make install 
    • Third, unzip your PHP source at the same location as Apache.
    gunzip -c php-5.x.tar.gz
    tar -xvf php-5.x.tar
    cd php-5.x
    • Fourth, if you are using MySQL database, below is the command to configure and build PHP.
    ./configure --with-apxs=/usr/sbin/apxs \
                --with-mysql=/usr/bin/mysql
    make
    make install
    • Next, install the PHP.INI file in order to make changes to get configuration directives.
    cd ../../php-5.x
    cp php.ini-dist /usr/local/lib/php.ini
    • Now you can make changes to the file extension and from which location to want to get your files picked up.
    1. Open HTTP config file from /usr/local/apache/conf and open httpd.conf with a text editor.
    2. Look out for DocumentRoot and change the directory path from where the files will be served. Using the home directory will be a secure option and you can keep all your files there.
    3. Add the below code there-
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php .html

    After making changes to HTTP config files or .ini files, you have to stop and restart the server to make the changes permanent.

    cd ../bin
    ./apachectl start 
    • Now change the root directory permission to full access, but the files within that directory will be read-only.
    chmod 755 /home/httpd/Html/php
    • Open a text file and save it in the web browser document as info.php with the below content
    Type: <?php phpinfo(); ?>
    • If you want to parse the file correctly, then you have to use the file with an HTTP request instead of a file name like http://localhost/info.php.

    Installing PHP on MAC OS

    Though Mac OS comes with Apache and PHP, you need to make some changes to make it work with new featured extensions. You can either install binary or the source. Follow the below steps to start the installation process-

    • Open the Apache file to make the below changes (as root authorization)
    sudo open -a TextEdit /etc/httpd/httpd.conf
    • Uncomment a few of the lines
    Load Module php5_module
    AddModule mod_php5.c
    AddType application/x-httpd-php .php
    • You can either comment out the directory path block, or you can choose your other location to serve the file.
    • Restart your web server.
    sudo apachectl graceful
    • Open a text file and save it in the web browser document as info.php with the below content.
    Type: <?php phpinfo(); ?> 
    • If you want to parse the file correctly, then you have to use the file with an HTTP request instead of a file name like http://localhost/info.php.

    Installing PHP on Windows

    You have to prepare yourself with some prerequisites before you install PHP on Windows- PHP compatible web server (IIS), PHP compatible database (MySQL or Oracle), and PHP-Windows binary distribution and unzip feature to extract files.

    • Now follow the below steps to ensure the installation of Apache and PHP on your windows system.
    • Unzip the binary files at the C:\PHP location of your system.
    • Copy the .dll files from the PHP directory to the system directory and also copy them to the web server module C:\PHP\Sapi\php5isapi.dll.
    • Then we have to copy one of the files, either php.ini-dist or php.ini-recommended, to your Windows directory (C:\Winnt or C:\Winnt40) and now rename it with php.ini. now, you have to open and make some changes to this file in a text editor in order to get configuration directives; New users should set error reporting to E_ALL on their development machines.
    • Restart your WWW service Services under the control panel, which can be found in the start menu. Search for IIS Admin Service, stop and start it. Once the service gets stopped, click World Wide Web Publishing Service to Start it. After this, you may reboot the system as this start and stop will not solve your purpose.
    • Open a text file and save it in the web browser document as info.php with the below content.
    Type: <?php phpinfo(); ?> 
    • If you want to parse the file correctly, then you have to use the file with an HTTP request instead of a file name like http://localhost/info.php.

    People are also reading: