Installing Apache2 with PHP5 and MySQL Support on Fedora 17 (LAMP)

If you have a website that needs a Dedicated or a Virtual Private  Server, but due to any reason you’re using an unmanaged service, you may have to perform some core installations yourself.

One such installation will be of Apache, which is required for your PHP based applications to run smoothly. Since, PHP requires MySQL, and security and robustness are the basic requirement for any website, you must make sure that you have the latest versions of both.

When it comes to the operating system, you have choices among CentOs, Ubuntu Fedora and a few more. However, this guide will focus on installing Apache on Fedora with PHP and MySQL and we’ll take all latest versions i.e. Apache2, PHP5, MySQL for PHP5 and Fedora 17.

Disclaimer: The first thing to keep in mind is that the hostname used in this guide is server1.example.com and IP address 192.168.0.100. These settings may differ for each person and will have to be modified where needed.

Instructions

  • 1

    Installing MYSQL5


    - To install MYSQL, run the script below:

    “yum install mysql mysql-server”

    - In the next step, system startup links have to be created for MYSQL. This is to make it start whenever the system loads. These links can be created by these codes:

    “systemctl enable mysqld.service”

    “systemctl start mysqld.service”

    Now run the script below:

    “mysql_secure_installation”

    MySQL would be installed on your web server.

  • 2

    Securing MYSQL5


    Once MYSQL5 has been installed, you should always remember to set a password for it. Failure to do so will allow anybody to access your database.  The process of setting up a password for the root user is explained below;

    “[root@server1 ~]# mysql_secure_installation”

    - You will have to log in to the root user. If you’re a new user who has not set a root password yet, the password will be blank and you just have to press enter. But for existing users, the current password has to be typed for the root user.

    Once that is done, you will see something similar to this;

    “Set root password? [Y/n].” Press  enter.
    “New password:” – type in your new password
    “Re-enter new password:” – re-enter your password

    A confirmation message will then appear, stating that your password has been updated.

  • 3

    Remove Anonymous Users


    It is by default that MYSQL installation is done through an anonymous user. This gives anyone the privilege to log in, without the need to have a user account created. The purpose of this is to make the installation process easy and smooth but they should be removed.

    “Remove anonymous users? [Y/n]” – Press enter

    The root should normally be allowed to only connect through ‘localhost’. This is so nobody can guess your root password.

    “Disallow root login remotely? [Y/n]” – Press enter.

  • 4

    Remove Test Database


    It is by default that MYSQL has a database titled ‘test’ and which can be accessed by anyone. You should remove this too. Below is how the information will appear when you’re removing the database titled ‘test’.

    “Remove test database and access to it? [Y/n]” – Press enter.

    “ Dropping test database...

    ... Success!

    - Removing privileges on test database...

    ... Success!”
    It is now time to reload the privilege table so all the changes made can take effect.

    Reload privilege tables now? [Y/n] – Press enter.

    After MYSQL has been installed, it is now time to install Apache2.

  • 5

    Installing Apache 2


    Since Apache2 is acquired as a Fedora package, it can be installed with;

    “yum install httpd”

    Now the system has to be configured so Apache2 can start automatically as soon as you boot your system. This can be done by;

    “systemctl enable httpd.service”

    To start Apache use;

    “systemctl start httpd.service”

    After these steps have been done, you should type http://192.168.0.100 in your web browser. An Apache2 placeholder page will appear.

    FYI: Apache’s default document root on Fedora is, “/var/www/html” and the configuration file is, “/etc/httpd/conf/httpd.conf”. Any additional configurations can be accessed through, “/etc/httpd/conf.d/” directory.

  • 6

    Installing PHP5


    This is the final step in Installing Apache2 With PHP5 And MySQL Support On Fedora 17 (LAMP).

    “Yum install php”

    Once this is done, Apache has to be restarted using.

    “systemctl restart httpd.service”

  • 7

    Testing PHP


    Now comes the testing phase where you acquire details about the PHP installed earlier.

    The document root of the default website is, “/var/www/html.” A small PHP file (info.php) has to be created in the directory. This file will be called in a browser. This file will have details about the PHP installed, including its version.

    “i /var/www/html/info.php”

    This file now has to be called in a browser. (for example; http://192.168.0.100/info.php).

    A window will appear with all the information about the PHP and as will be evidence, PHP will be working through the Apache 2.0 Handler.

    This can be seen under the heading of, “API line”. A list of enabled modules in PHP5 will be seen. But it will be noticed that MYSQL will not be listed there, showing no MYSQL support in PHP5 yet. This is where our next step comes in...

  • 8

    Getting MySQL Support In PHP5


    php-mysql package has to be installed to get MYSQL to support PHP. You can also install other PHP modules since they might be required for a few applications. The available0 PHP modules can be searched through the procedure explained below;

    “yum search php”

    After choosing the ones you want, these modules can be installed by;

    “yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-magickwand php-mbstring php-mcrypt php-mssql php-shout php-snmp php-soap php-tidy”

    Once that is done, Apache2 has to be reloaded using.

    “systemctl restart httpd.service”

    After the modules have been installed, type http://192.168.0.100/info.php again in your web browser. The same page will open which opened earlier, but this time it will have the different modules that you have installed – including the MYSQL one.

  • 9

    Installing PHPmyadmin


    Installing phpmyadmin will allow you to manage your MYSQL database.

    Type, “yum install phpmyadmin”

    Once installed, it has to be configured and Apache’s configurations have to been changed so phpmyadmin allows different connections.

    “vi /etc/httpd/conf.d/phpMyAdmin.conf”

    Then a code has to be typed. It is laid out below;

    # phpMyAdmin - Web based MySQL browser written in php
    #
    # Allows only localhost by default
    #
    # But allowing phpMyAdmin to anyone other than localhost should be considered
    # dangerous unless properly secured by SSL

    Alias /phpMyAdmin /usr/share/phpMyAdmin
    Alias /phpmyadmin /usr/share/phpMyAdmin

    #
    #
    # # Apache 2.4
    #
    # Require ip 127.0.0.1
    # Require ip ::1
    #
    #
    #
    # # Apache 2.2
    # Order Deny,Allow
    # Deny from All
    # Allow from 127.0.0.1
    # Allow from ::1
    #
    #

    # Apache 2.4

    Require ip 127.0.0.1
    Require ip ::1

    # Apache 2.2
    Order Deny,Allow
    Deny from All
    Allow from 127.0.0.1
    Allow from ::1

    # These directories do not require access over HTTP - taken from the original
    # phpMyAdmin upstream tarball
    #

    Order Deny,Allow
    Deny from All
    Allow from None
    Order Deny,Allow
    Deny from All
    Allow from None
    Order Deny,Allow
    Deny from All
    Allow from None

     

    # This configuration prevents mod_security at phpMyAdmin directories from
    # filtering SQL etc. This may break your mod_security implementation.
    #
    #
    #
    # SecRuleInheritance Off
    #
    #

    After doing that, Apache has to be restarted again.

    “systemctl restart httpd.service”

    Now you will be able to see phpmyadmin under, ‘http://192.168.0.100/phpmyadmin/’

     

Leave a Reply

Your email address will not be published. Required fields are marked *


eight + = 10