How to install Lamp for Centos 6


SUBMITTED BY: Guest

DATE: Jan. 7, 2015, 4:58 a.m.

FORMAT: Text only

SIZE: 9.0 kB

HITS: 929

  1. About LAMP
  2. LAMP stack is a group of open source software used to get web servers up and running. The acronym stands for Linux, Apache, MySQL, and PHP. Since the server is already running CentOS, the linux part is taken care of. Here is how to install the rest.
  3. Set Up
  4. 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.
  5. Step One—Install Apache
  6. Apache is a free open source software which runs over 50% of the world’s web servers.
  7. To install apache, open terminal and type in this command:
  8. sudo yum install httpd
  9. 1
  10. sudo yum install httpd
  11. Once it installs, you can start apache running on your VPS:
  12. sudo service httpd start
  13. 1
  14. sudo service httpd start
  15. That’s it. To check if Apache is installed, direct your browser to your server’s IP address (eg. http://12.34.56.789). The page should display the words “It works!” like this.
  16. How to find your Server’s IP address
  17. You can run the following command to reveal your server’s IP address.
  18. ifconfig eth0 | grep inet | awk '{ print $2 }'
  19. 1
  20. ifconfig eth0 | grep inet | awk '{ print $2 }'
  21. Step Two—Install MySQL
  22. MySQL is a powerful database management system used for organizing and retrieving data on a virtual server
  23. To install MySQL, open terminal and type in these commands:
  24. sudo yum install mysql-server sudo service mysqld start
  25. 1
  26. 2
  27. sudo yum install mysql-server
  28. sudo service mysqld start
  29. During the installation, MySQL will ask you for your permission twice. After you say Yes to both, MySQL will install.
  30. Once it is done installing, you can set a root MySQL password:
  31. sudo /usr/bin/mysql_secure_installation
  32. 1
  33. sudo /usr/bin/mysql_secure_installation
  34. The prompt will ask you for your current root password.
  35. Since you just installed MySQL, you most likely won’t have one, so leave it blank by pressing enter.
  36. Enter current password for root (enter for none): OK, successfully used password, moving on...
  37. 1
  38. 2
  39. Enter current password for root (enter for none):
  40. OK, successfully used password, moving on...
  41. Then the prompt will ask you if you want to set a root password. Go ahead and choose Y and follow the instructions.
  42. CentOS automates the process of setting up MySQL, asking you a series of yes or no questions.
  43. It’s easiest just to say Yes to all the options. At the end, MySQL will reload and implement the new changes.
  44. 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!
  45. 1
  46. 2
  47. 3
  48. 4
  49. 5
  50. 6
  51. 7
  52. 8
  53. 9
  54. 10
  55. 11
  56. 12
  57. 13
  58. 14
  59. 15
  60. 16
  61. 17
  62. 18
  63. 19
  64. 20
  65. 21
  66. 22
  67. 23
  68. 24
  69. 25
  70. 26
  71. 27
  72. 28
  73. 29
  74. 30
  75. 31
  76. 32
  77. 33
  78. 34
  79. 35
  80. 36
  81. 37
  82. By default, a MySQL installation has an anonymous user, allowing anyone
  83. to log into MySQL without having to have a user account created for
  84. them. This is intended only for testing, and to make the installation
  85. go a bit smoother. You should remove them before moving into a
  86. production environment.
  87. Remove anonymous users? [Y/n] y
  88. ... Success!
  89. Normally, root should only be allowed to connect from 'localhost'. This
  90. ensures that someone cannot guess at the root password from the network.
  91. Disallow root login remotely? [Y/n] y
  92. ... Success!
  93. By default, MySQL comes with a database named 'test' that anyone can
  94. access. This is also intended only for testing, and should be removed
  95. before moving into a production environment.
  96. Remove test database and access to it? [Y/n] y
  97. - Dropping test database...
  98. ... Success!
  99. - Removing privileges on test database...
  100. ... Success!
  101. Reloading the privilege tables will ensure that all changes made so far
  102. will take effect immediately.
  103. Reload privilege tables now? [Y/n] y
  104. ... Success!
  105. Cleaning up...
  106. All done! If you've completed all of the above steps, your MySQL
  107. installation should now be secure.
  108. Thanks for using MySQL!
  109. Step Three—Install PHP
  110. PHP is an open source web scripting language that is widely used to build dynamic webpages.
  111. To install PHP on your virtual private server, open terminal and type in this command:
  112. sudo yum install php php-mysql
  113. 1
  114. sudo yum install php php-mysql
  115. Once you answer yes to the PHP prompt, PHP will be installed.
  116. PHP Modules
  117. 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:
  118. yum search php-
  119. 1
  120. yum search php-
  121. Terminal then will display the list of possible modules. The beginning looks like this:
  122. 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
  123. 1
  124. 2
  125. 3
  126. 4
  127. 5
  128. 6
  129. 7
  130. 8
  131. 9
  132. php-bcmath.x86_64 : A module for PHP applications for using the bcmath library
  133. php-cli.x86_64 : Command-line interface for PHP
  134. php-common.x86_64 : Common files for PHP
  135. php-dba.x86_64 : A database abstraction layer module for PHP applications
  136. php-devel.x86_64 : Files needed for building PHP extensions
  137. php-embedded.x86_64 : PHP library for embedding in applications
  138. php-enchant.x86_64 : Human Language and Character Encoding Support
  139. php-gd.x86_64 : A module for PHP applications for using the gd graphics library
  140. php-imap.x86_64 : A module for PHP applications that use IMAP
  141. 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.
  142. yum info <i>name of the module</i>
  143. 1
  144. yum info <i>name of the module</i>
  145. Once you decide to install the module, type:
  146. sudo yum install <i>name of the module</i>
  147. 1
  148. sudo yum install <i>name of the module</i>
  149. You can install multiple libraries at once by separating the name of each module with a space.
  150. Congratulations! You now have LAMP stack on your droplet!
  151. We should also set the processes to run automatically when the server boots (php will run automatically once Apache starts):
  152. sudo chkconfig httpd on sudo chkconfig mysqld on
  153. 1
  154. 2
  155. sudo chkconfig httpd on
  156. sudo chkconfig mysqld on
  157. Step Four—RESULTS: See PHP on your Server
  158. Although LAMP is installed on your virtual server, we can still take a look and see the components online by creating a quick php info page
  159. To set this up, first create a new file:
  160. sudo nano /var/www/html/info.php
  161. 1
  162. sudo nano /var/www/html/info.php
  163. Add in the following line:
  164. <?php phpinfo(); ?>
  165. 1
  166. 2
  167. 3
  168. <?php
  169. phpinfo();
  170. ?>
  171. Then Save and Exit.
  172. Restart apache so that all of the changes take effect on your virtual server:
  173. sudo service httpd restart
  174. 1
  175. sudo service httpd restart
  176. Finish up by visiting your php info page (make sure you replace the example ip address with your correct one): http://12.34.56.789/info.php
  177. It should look similar to this.
  178. http://nowquestion.net/questions/how-to-install-linux-apache-mysql-php-lamp-stack-on-centos-6

comments powered by Disqus