Install Apache, MySQL, PHP on CentOs 6

LAMP stack is the most powerful open source solution on the web. LAMP stands for Linux, Apache, MySQL and PHP. In this article we are going to install these on CentOs 6. So We already have Linux running centOs. We will work on the next three in this article.

For installation you have to login on the terminal with root privileges. Otherwise you will need to use sudo with every command.


To install Apache type this command in terminal

    sudo yum install httpd

You can skip sudo if you are logged in as root. Above command will install apache and will create a directory /var/www/html Next make Apache to restart on server Reboot

    sudo chkconfig httpd on

Now start Apache with following command

    sudo service httpd start

You can now navigate on the browser with your IP or Domain (If it is mapped to the IP).

You will now see a page running Apache like below. This page will be removed when you upload your index file in /var/www/html


Now Install PHP with following command

    sudo yum install php php-mysql

Above command will install php and php-mysql module. You can check its version with php -v command. You can install multiple modules in one command separated by space like we did in the above command. You will need some dependencies to work with php. So install them as well.

    sudo yum install gd gd-devel php-gd php-xml

Now restart Apache with following command

    sudo service httpd restart

So as of now we have installed Apache and PHP. Let us proceed further and install MySQL.


Install MYSQL with following command

    sudo yum install mysql-server

Next make Apache to restart on server Reboot

    sudo chkconfig mysqld on

Now start MySQL with following command

    sudo service mysqld start

This will display info something like this

    Initializing MySQL database:  Installing MySQL system tables...
    Filling help tables...
    To start mysqld at boot time you have to copy
    support-files/mysql.server to the right place for your system
    To do so, start the server, then issue the following commands:
    /usr/bin/mysqladmin -u root password 'new-password'
    /usr/bin/mysqladmin -u root -h li1256-197 password 'new-password'
    Alternatively you can run:
    which will also give you the option of removing the test
    databases and anonymous user created by default.  This is
    strongly recommended for production servers.
    See the manual for more instructions.
    You can start the MySQL daemon with:
    cd /usr ; /usr/bin/mysqld_safe &
    You can test the MySQL daemon with
    cd /usr/mysql-test ; perl
    Please report any problems with the /usr/bin/mysqlbug script!
                                                               [  OK  ]
    Starting mysqld:                                           [  OK  ]

As it says above let us now set a root MySQL password. Type the following command in terminal.

    sudo /usr/bin/mysql_secure_installation

Above command will display something like this in terminal and will ask some questions to fill in. Fill in what it asks including root password. mypwd@123 is the sample password used below. Choose a secure password for root.

    Enter current password for root (enter for none):
    OK, successfully used password, moving on...
    Set root password? [Y/n] Y
    New password: mypwd@123
    Re-enter new password: mypwd@123
    Remove anonymous users? [Y/n] y
    Disallow root login remotely? [Y/n] y
    Remove test database and access to it? [Y/n] y
    Reload privilege tables now? [Y/n] y
     ... Success!

    Cleaning up...

    All done!  If you've completed all of the above steps, your MySQL
    installation should now be secure.
    Thanks for using MySQL!

And now we are done with MyQL installation too. So our LAMP stack stack is ready to use. In next article I will explain how do we connect to this MySQL Server, and Create user and grant privileges.
Install Apache, MySQL, PHP on CentOs 6 Install Apache, MySQL, PHP on CentOs 6 Reviewed by Altaf Hussain on December 22, 2015 Rating: 5

No comments:

Altaf Web. Powered by Blogger.