LAMP on Centos 6.7



How To Install Linux, Apache, MySQL, PHP (LAMP) stack On CentOS 6

LAMP : LAMP stack is a group of open source software used for seting a web servers up and running.
The acronym LAMP stands for Linux, Apache, MySQL, and PHP. Since the server is already running CentOS.

Set Up

The steps in this tutorial require the user on the virtual private server to have root privileges. You can see how to set that up in the Initial Server Setup Tutorial in steps 3 and 4.

1.Install Apache

Apache is a free open source software.

To install apache, open terminal and type in this command:

# sudo yum install httpd
Loaded plugins: fastestmirror, security
Setting up Install Process
Loading mirror speeds from cached hostfile
 * base: centosmirror.go4hosting.in
 * epel: mirror.wanxp.id
 * extras: centosmirror.go4hosting.in
 * updates: centosmirror.go4hosting.in
epel/primary_db                                                                                                     | 5.8 MB     00:00
extras                                                                                                              | 3.4 kB     00:00
extras/primary_db                                                                                                   |  34 kB     00:00
updates                                                                                                             | 3.4 kB     00:00
http://centosmirror.go4hosting.in/centos/6.7/updates/x86_64/repodata/243464702a26e8b836fef55e29376b547f22c9bca0d68e385e6688be3fb9ba10-primary.sqlite.bz2: [Errno 12] Timeout on http://centosmirror.go4hosting.in/centos/6.7/updates/x86_64/repodata/243464702a26e8b836fef55e29376b547f22c9bca0d68e385e6688be3fb9ba10-primary.sqlite.bz2: (28, 'Operation too slow. Less than 1 bytes/sec transfered the last 30 seconds')
Trying other mirror.
updates/primary_db                                                                                                  | 3.3 MB     00:00
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.2.15-47.el6.centos.1 will be installed
--> Processing Dependency: httpd-tools = 2.2.15-47.el6.centos.1 for package: httpd-2.2.15-47.el6.centos.1.x86_64
--> Processing Dependency: apr-util-ldap for package: httpd-2.2.15-47.el6.centos.1.x86_64
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.2.15-47.el6.centos.1.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.2.15-47.el6.centos.1.x86_64
--> Running transaction check
---> Package apr.x86_64 0:1.3.9-5.el6_2 will be installed
---> Package apr-util.x86_64 0:1.3.9-3.el6_0.1 will be installed
---> Package apr-util-ldap.x86_64 0:1.3.9-3.el6_0.1 will be installed
---> Package httpd-tools.x86_64 0:2.2.15-47.el6.centos.1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================================================
 Package                           Arch                       Version                                    Repository                   Size
===========================================================================================================================================
Installing:
 httpd                             x86_64                     2.2.15-47.el6.centos.1                     updates                     830 k
Installing for dependencies:
 apr                               x86_64                     1.3.9-5.el6_2                              base                        123 k
 apr-util                          x86_64                     1.3.9-3.el6_0.1                            base                         87 k
 apr-util-ldap                     x86_64                     1.3.9-3.el6_0.1                            base                         15 k
 httpd-tools                       x86_64                     2.2.15-47.el6.centos.1                     updates                      77 k

Transaction Summary
===========================================================================================================================================
Install       5 Package(s)

Total download size: 1.1 M
Installed size: 3.6 M
Is this ok [y/N]: y   # It will ask for to weather to install it or not

Downloading Packages:
(1/5): apr-1.3.9-5.el6_2.x86_64.rpm                                                                                 | 123 kB     00:00
(2/5): apr-util-1.3.9-3.el6_0.1.x86_64.rpm                                                                          |  87 kB     00:00
(3/5): apr-util-ldap-1.3.9-3.el6_0.1.x86_64.rpm                                                                     |  15 kB     00:00
(4/5): httpd-2.2.15-47.el6.centos.1.x86_64.rpm                                                                      | 830 kB     00:00
(5/5): httpd-tools-2.2.15-47.el6.centos.1.x86_64.rpm                                                                |  77 kB     00:00
-------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                       68 kB/s | 1.1 MB     00:16
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : apr-1.3.9-5.el6_2.x86_64                                                                                                1/5
  Installing : apr-util-1.3.9-3.el6_0.1.x86_64                                                                                         2/5
  Installing : httpd-tools-2.2.15-47.el6.centos.1.x86_64                                                                               3/5
  Installing : apr-util-ldap-1.3.9-3.el6_0.1.x86_64                                                                                    4/5
  Installing : httpd-2.2.15-47.el6.centos.1.x86_64                                                                                     5/5
  Verifying  : httpd-tools-2.2.15-47.el6.centos.1.x86_64                                                                               1/5
  Verifying  : httpd-2.2.15-47.el6.centos.1.x86_64                                                                                     2/5
  Verifying  : apr-util-ldap-1.3.9-3.el6_0.1.x86_64                                                                                    3/5
  Verifying  : apr-util-1.3.9-3.el6_0.1.x86_64                                                                                         4/5
  Verifying  : apr-1.3.9-5.el6_2.x86_64                                                                                                5/5

Installed:
  httpd.x86_64 0:2.2.15-47.el6.centos.1

Dependency Installed:
  apr.x86_64 0:1.3.9-5.el6_2                         apr-util.x86_64 0:1.3.9-3.el6_0.1        apr-util-ldap.x86_64 0:1.3.9-3.el6_0.1
  httpd-tools.x86_64 0:2.2.15-47.el6.centos.1

Complete!



Once it install is completed, you can start apache running on your server.

# sudo service httpd start

Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
                                                           [  OK  ]


We can check if Apache is installed, direct your browser to your server’s IP address (eg. http://192.168.1.100 or http://your-server-ip-address).

apache on centos


How to find your Server’s IP address

You can run the following command to reveal your server’s IP address.

# ifconfig eth1 | grep inet | awk '{ print $2 }'
addr:192.168.87.140
addr:


2. Install MySQL

To install MySQL, open terminal and type in these commands:

# sudo yum install mysql-server
Loaded plugins: fastestmirror, security
Setting up Install Process
Loading mirror speeds from cached hostfile
 * base: centosmirror.go4hosting.in
 * epel: mirror.wanxp.id
 * extras: centosmirror.go4hosting.in
 * updates: centosmirror.go4hosting.in
Resolving Dependencies
--> Running transaction check
---> Package mysql-server.x86_64 0:5.1.73-5.el6_6 will be installed
--> Processing Dependency: mysql = 5.1.73-5.el6_6 for package: mysql-server-5.1.73-5.el6_6.x86_64
--> Processing Dependency: perl-DBD-MySQL for package: mysql-server-5.1.73-5.el6_6.x86_64
--> Running transaction check
---> Package mysql.x86_64 0:5.1.73-5.el6_6 will be installed
---> Package perl-DBD-MySQL.x86_64 0:4.013-3.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================================================
 Package                              Arch                         Version                                Repository                  Size
===========================================================================================================================================
Installing:
 mysql-server                         x86_64                       5.1.73-5.el6_6                         base                       8.6 M
Installing for dependencies:
 mysql                                x86_64                       5.1.73-5.el6_6                         base                       894 k
 perl-DBD-MySQL                       x86_64                       4.013-3.el6                            base                       134 k

Transaction Summary
===========================================================================================================================================
Install       3 Package(s)

Total download size: 9.6 M
Installed size: 27 M
Is this ok [y/N]:y  y   # It will ask for to weather to install it or not
Downloading Packages:
http://centosmirror.go4hosting.in/centos/6.7/os/x86_64/Packages/mysql-5.1.73-5.el6_6.x86_64.rpm: [Errno 12] Timeout on http://centosmirror.go4hosting.in/centos/6.7/os/x86_64/Packages/mysql-5.1.73-5.el6_6.x86_64.rpm: (28, 'Operation too slow. Less than 1 bytes/sec transfered the last 30 seconds')
Trying other mirror.
(1/3): mysql-5.1.73-5.el6_6.x86_64.rpm                                                                                                               | 894 kB     00:00
(2/3): mysql-server-5.1.73-5.el6_6.x86_64.rpm                                                                                                        | 8.6 MB     00:00
(3/3): perl-DBD-MySQL-4.013-3.el6.x86_64.rpm                                                                                                         | 134 kB     00:00
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                       256 kB/s | 9.6 MB     00:38
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : mysql-5.1.73-5.el6_6.x86_64                                       1/3
  Installing : perl-DBD-MySQL-4.013-3.el6.x86_64                                 2/3
  Installing : mysql-server-5.1.73-5.el6_6.x86_64                                      3/3
  Verifying  : perl-DBD-MySQL-4.013-3.el6.x86_64                                       1/3
  Verifying  : mysql-5.1.73-5.el6_6.x86_64                                             2/3
  Verifying  : mysql-server-5.1.73-5.el6_6.x86_64                                      3/3

Installed:
  mysql-server.x86_64 0:5.1.73-5.el6_6

Dependency Installed:
  mysql.x86_64 0:5.1.73-5.el6_6                       perl-DBD-MySQL.x86_64 0:4.013-3.el6

Complete!

To start the Mysql Server

# sudo service mysqld start
Initializing MySQL database:  Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
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 localhost.localdomain password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation

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 mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/bin/mysqlbug script!

                                                           [  OK  ]
Starting mysqld:                                           [  OK  ]


Once it is started,  you can set a root MySQL password:

# /usr/bin/mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!


In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n]
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables.. ... Success!


By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y    
... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y
 ... Success!

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

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!




3. Install PHP

PHP is an open source web scripting language that is widely used to build dynamic webpages.

# sudo yum install php php-mysql
Loaded plugins: fastestmirror, security
Setting up Install Process
Loading mirror speeds from cached hostfile
 * base: centosmirror.go4hosting.in
 * epel: mirror.wanxp.id
 * extras: centosmirror.go4hosting.in
 * updates: centosmirror.go4hosting.in
Resolving Dependencies
--> Running transaction check
---> Package php.x86_64 0:5.3.3-46.el6_6 will be installed
--> Processing Dependency: php-common(x86-64) = 5.3.3-46.el6_6 for package: php-5.3.3-46.el6_6.x86_64
--> Processing Dependency: php-cli(x86-64) = 5.3.3-46.el6_6 for package: php-5.3.3-46.el6_6.x86_64
---> Package php-mysql.x86_64 0:5.3.3-46.el6_6 will be installed
--> Processing Dependency: php-pdo(x86-64) for package: php-mysql-5.3.3-46.el6_6.x86_64
--> Running transaction check
---> Package php-cli.x86_64 0:5.3.3-46.el6_6 will be installed
---> Package php-common.x86_64 0:5.3.3-46.el6_6 will be installed
---> Package php-pdo.x86_64 0:5.3.3-46.el6_6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

============================================================================================================================================================================
 Package                                   Arch                                  Version                                       Repository                              Size
============================================================================================================================================================================
Installing:
 php                                       x86_64                                5.3.3-46.el6_6                                updates                                1.1 M
 php-mysql                                 x86_64                                5.3.3-46.el6_6                                updates                                 86 k
Installing for dependencies:
 php-cli                                   x86_64                                5.3.3-46.el6_6                                updates                                2.2 M
 php-common                                x86_64                                5.3.3-46.el6_6                                updates                                529 k
 php-pdo                                   x86_64                                5.3.3-46.el6_6                                updates                                 79 k

Transaction Summary
============================================================================================================================================================================
Install       5 Package(s)

Total download size: 4.0 M
Installed size: 13 M
Is this ok [y/N]: y
Downloading Packages:
http://centosmirror.go4hosting.in/centos/6.7/updates/x86_64/Packages/php-5.3.3-46.el6_6.x86_64.rpm: [Errno 12] Timeout on http://centosmirror.go4hosting.in/centos/6.7/ues/x86_64/Packages/php-5.3.3-46.el6_6.x86_64.rpm: (28, 'Operation too slow. Less than 1 bytes/sec transfered the last 30 seconds')
Trying other mirror.
(1/5): php-5.3.3-46.el6_6.x86_64.rpm                                                                                                                 | 1.1 MB     00:00
(2/5): php-cli-5.3.3-46.el6_6.x86_64.rpm                                                                                                             | 2.2 MB     00:00
(3/5): php-common-5.3.3-46.el6_6.x86_64.rpm                                                                                                          | 529 kB     00:00
(4/5): php-mysql-5.3.3-46.el6_6.x86_64.rpm                                                                                                           |  86 kB     00:00
(5/5): php-pdo-5.3.3-46.el6_6.x86_64.rpm                                                                                                             |  79 kB     00:00
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                       120 kB/s | 4.0 MB     00:34
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : php-common-5.3.3-46.el6_6.x86_64
  Installing : php-pdo-5.3.3-46.el6_6.x86_64
  Installing : php-cli-5.3.3-46.el6_6.x86_64
  Installing : php-5.3.3-46.el6_6.x86_64
  Installing : php-mysql-5.3.3-46.el6_6.x86_64
  Verifying  : php-mysql-5.3.3-46.el6_6.x86_64
  Verifying  : php-5.3.3-46.el6_6.x86_64
  Verifying  : php-pdo-5.3.3-46.el6_6.x86_64
  Verifying  : php-common-5.3.3-46.el6_6.x86_64
  Verifying  : php-cli-5.3.3-46.el6_6.x86_64

Installed:
  php.x86_64 0:5.3.3-46.el6_6                                                       php-mysql.x86_64 0:5.3.3-46.el6_6

Dependency Installed:
  php-cli.x86_64 0:5.3.3-46.el6_6                         php-common.x86_64 0:5.3.3-46.el6_6                         php-pdo.x86_64 0:5.3.3-46.el6_6

Complete!



PHP Modules

PHP also has a variety of useful libraries and modules that you can add onto your server. You can see the libraries that are available by typing:

# yum search php-

Terminal then will display the list of possible modules. The beginning looks like this:

php-bcmath.x86_64 : A module for PHP applications for using the bcmath library
php-cli.x86_64 : Command-line interface for PHP
php-common.x86_64 : Common files for PHP
php-dba.x86_64 : A database abstraction layer module for PHP applications
php-devel.x86_64 : Files needed for building PHP extensions
php-embedded.x86_64 : PHP library for embedding in applications
php-enchant.x86_64 : Human Language and Character Encoding Support
php-gd.x86_64 : A module for PHP applications for using the gd graphics library
php-imap.x86_64 : A module for PHP applications that use IMAP

To see more details about what each module does, type the following command into terminal, replacing the name of the module with whatever library you want to learn about.

# yum info name of the module

Once you decide to install the module, type:

# sudo yum install name of the module

You can install multiple libraries at once by separating the name of each module with a space.

We should also set the processes to run automatically when the server boots (php will run automatically once Apache starts):

# sudo chkconfig httpd on
# sudo chkconfig mysqld on

4. Checking the PHP on your Server

This can be done with a small .php file where we can check the httpd services with php

To set this up, first create a new file:

# sudo vi  /var/www/html/info.php
Add in the following line:

<?php
phpinfo();
?>

Then Save and Exit.

Restart apache so that all of the changes take effect on your virtual server:

# sudo service httpd restart


Finish up by visiting your php info page (make sure you replace the example ip address with your correct one): http://192.168.87.140/info.php

apache with php





















Keywords: LAMP, apache, httpd, mysql, mysqlsecureinstallation, php, apache with php, testing php on apache

Comments

Popular posts from this blog

Observium: Configuring Microsoft Windows 2008 Server SNMP Agent

AWS: Upgrade PV Drivers on Windows Instances

How to configure Incremental backups for MSSQL Database