How to Build a LAMP Stack on Centos 7 (Linux, Apache, MySQL, PHP)

To build a dynamic web application, you need what has been coined a “stack” – which is developer lingo for an integrated set of software that has all of the components your application needs.

Most stacks have the same types of components and differ mainly in which pieces of software they use for those components. For example, we’ll look at LAMP (which this article covers):

Component LAMP Software
Operating system Linux (e.g. CentOS)
Web server Apache
Database MySQL
Programming language PHP
If you’re astute, maybe you noticed that LAMP is just an acronym for the software the stack uses.

In this guide, we’ll walk you through installing all of these components (except for Linux, which is already installed as your OS when you create the server).

Install Apache

Before you begin any installation, make sure that your software is up to date:
sudo yum update
Install Apache:
sudo yum install httpd
Start Apache:
sudo systemctl start httpd.service
Set Apache to start on server boot:
sudo systemctl enable httpd.service
Verify that Apache is installed by going to:
http://your server’s IP address.
If Apache is installed, the Apache Test Page displays.
GoDaddy Cloud Server customers can use Find your server’s IP.

Install MySQL

Install MariaDB, which is a community-developed fork of MySQL:
sudo yum install mariadb-server mariadb
Start the service:
sudo systemctl start mariadb
Set MySQL to start on server boot:
sudo systemctl enable mariadb.service
Run this command to finish setting up the installation:
sudo mysql_secure_installation
You will be asked for the root password. Because you didn’t set it earlier, press Enter to set a password now.
Type “Y” to set the root password.
Enter and confirm the new password.
You will be asked more questions as part of the security configuration. It is a best practice to respond “Y” to these system prompts
Install PHP

Install PHP:
sudo yum install php php-mysql
Enter “Y” to install.
Restart Apache:
sudo systemctl restart httpd.service
Install PHP modules

If your applications requires any PHP modules, you can install them now.

View available PHP modules:
yum search php-
The list displays the available PHP modules. To view the description of a specific package, use the following command:
yum info the name of the package you want to use
Install the package you want:
sudo yum install the name of the package you want to use
Test PHP processing on Apache

Create a new PHP file under the /var/www/html directory:
sudo vim /var/www/html/info.php
When the file opens, type in the following code:

Save and close the file:
:wq!
To verify it worked, type this URL in your browser:
http://your server’s IP address/info.php
A page displays with the PHP version, extensions, build date, and other information.

1 Comment

Leave a Reply

Your email address will not be published.


*