---
slug: CentOS 6 Web Server Setup  LAMP Stack Installation Guide
title: CentOS 6 Web Server Setup  LAMP Stack Installation Guide
authors: [slorber, yangshun]
tags: [hola, docusaurus]
---

<!-- truncate -->

import CodeBlock from '@site/src/components/CodeBloack';

<div className="head">Setting Up Your Website: A Beginner's Guide to LAMP on CentOS</div>

<div className="text">The LAMP stack is a group of tools used to set up websites. LAMP stands for Linux, Apache, MySQL and PHP.</div>
<div className="text"><ol><li>Linux: It's like the foundation of your website. CentOS is already there, serving as the base.</li><li>Apache: Think of Apache as a traffic cop for your website. It directs visitors to the right places.</li><li>MySQL: MySQL is a storage place for your website's information. It keeps everything organized.</li><li>PHP: PHP is a language that helps your website do things – like showing dynamic content.</li></ol></div>

<div className="text">Since your server is on CentOS, you just need to add Apache, MySQL, and PHP to make your website work.</div>

<div className="head">Getting Started: Accessing Your Virtual Server</div>

<div className="text">To follow along with this guide, you need special access to your virtual private server. It's a bit like having a key to your online space. If you're not sure how to get this key, check out the Initial Server Setup Tutorial for simple instructions.</div>

<div className="head">Step One: Introducing Apache to Your Server</div>

<div className="text">Let's start by adding Apache to your server. Apache is like a free tool that helps your website be seen by lots of people. To get it, open the terminal and type in this special command:</div>

<CodeBlock code={`sudo yum install httpd`} /><br/>

<div className="text">After it's done installing, you can make Apache start working on your online space (VPS):</div>

<CodeBlock code={`sudo service httpd start`} /><br/>

<div className="text">All done! To see if Apache is set up, just open your internet browser and go to your server's address (like http ://12.34.56.789). If everything's good, a page saying 'It works!' should show up, just like that!</div>

<div className="text" style={{ fontSize:'28px' }}>Locating Your Server: Finding Its Special Address</div>

<div className="text">Wondering where to find your server's address? Just use this simple command to uncover it:</div>

<CodeBlock code={`ifconfig eth0 | grep inet | awk '{ print $2 }'`} /><br/>


<div className="head">Step Two: Bringing in MySQL for Your Website's Data</div>
<div className="text">Next up is MySQL, a powerful system that helps keep your website's information organized on your online space. <br/><br/>To get MySQL, go to the terminal and type in these special commands:</div>

<CodeBlock code={`sudo yum install mysql-server sudo service mysqld start`} /><br/>

<div className="text">As MySQL installs, it might ask for your permission twice. Just say 'Yes' both times, and MySQL will finish setting up.</div><br/>

<div className="text">After the installation is complete, you'll get to choose a special password for the main access point, kind of like locking the door to your MySQL space:</div>

<CodeBlock code={`sudo /usr/bin/mysql_secure_installation`} /><br/>

<div className="text">The prompt might ask for a password you don't have yet, called the 'root password.'</div><br/>

<div className="text">Since MySQL is brand new, you can just press 'Enter' without typing anything to leave it empty.</div>

<CodeBlock code={`Enter current password for root (enter for none): OK, successfully used password, moving on...`} /><br/>

<div className="text">After that, the system will ask if you want to create a password. Choose 'Y' for 'Yes' and follow what it says.<br/><br/>
CentOS makes it easy by asking you simple 'Yes' or 'No' questions.<br/><br/>
Just say 'Yes' to everything it asks. When you're done, MySQL will finish up and put all the new stuff in place</div>



<CodeBlock code={`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!`} /><br/>

<div className="head">Step Three: Bringing in PHP for Dynamic Webpages</div>

<div className="text">Now, let's add PHP, a tool that helps create dynamic webpages, to your online space.</div><br/>

<div className="text">To get PHP, go to the terminal and type in this special command:</div>

<CodeBlock code={`sudo yum install php php-mysql`} /><br/>

<div className="text">After you say 'Yes' to the PHP question, PHP will finish installing.</div>



<CodeBlock code={`Exploring PHP Tools: Libraries and Modules`} /><br/>

<div className="text">PHP comes with extra tools called libraries and modules that can enhance your server. To see what tools are available, just type.</div>

<CodeBlock code={`yum search php-`} /><br/>

<div className="text">After typing that, the terminal will show you a list of different modules. It will look something like this:</div>

<CodeBlock code={`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`} /><br/>


<div className="text">If you want to know more about what each tool does, type the following command in the terminal. Just replace the name of the tool with the one you're curious about.</div>

<CodeBlock code={`yum info name of the module`} /><br/>

<div className="text">If you've chosen a tool you want to add, type the following command:</div>

<CodeBlock code={`sudo yum install name of the module`} /><br/>

<div className="text">You can add several tools together by typing their names with spaces in between.<br/><br/>
Great job! Your online space now has the complete LAMP stack!<br/><br/>
To make things even easier, let's set it up so that everything starts running automatically when your server starts (PHP will start as soon as Apache does):</div>

<CodeBlock code={`sudo chkconfig httpd on sudo chkconfig mysqld on`} /><br/>


<div className="head">Step Four: Checking PHP on Your Server</div>
<div className="text">Even though LAMP is now installed on your online space, you can still check out its parts by making a simple PHP info page.</div><br/>

<div className="text">To do this, let's start by creating a new file:</div>

<CodeBlock code={`sudo nano /var/www/html/info.php`} /><br/>

<div className="text">Now, let's add the following line:</div>

<CodeBlock code={`<?php phpinfo(); ?>`} /><br/>

<div className="text">After adding the line, save your work and close the file.<br/><br/>
Now, let's make sure all the changes apply to your online space. Restart Apache on your server:</div>

<CodeBlock code={`sudo service httpd restart`} /><br/>

<div className="text">To wrap up, check your PHP info page by opening this link in your browser (remember to use your own server's IP address instead of the example): http ://12.34.56.789/info.php</div><br/>


<div className="con">Conclusion:</div>


<div className="text">Great job setting up your website base with CentOS 6 and the LAMP stack! You've got the essentials – Apache, MySQL, and PHP – ready for dynamic websites.</div>

<div className="text"><strong>Ready for more? Explore extra features, keep your server safe and connect with fellow web builders online.</strong></div><br/>

<div className="text">Keep coding and creating on your CentOS 6 server! Happy coding!</div>










