Search The Hostwinds Guides Knowledge Base

Install LAMP Stack on CentOS 7

Share This Article

One of the most simple and barebones solutions you can have for having a fully fledged and widely supported web stack with both server-side code and database functionality, is with the LAMP Stack.

There are four primary components of the LAMP stack:

  • Linux: the operating system environment
  • Apache: webserver service to handle HTTP requests
  • MySQL: the database engine
  • PHP: scripting language that executes server-side

This guide goes over how to install the LAMP stack with a basic configuration on CentOS 7 and is intended for Hostwinds clients with a Cloud VPS or Dedicated Server.

Install Apache

To install Apache on CentOS 7, you will want to install the httpd package using the yum package manager:

After installing Apache, you will want to make sure that it is started by running:

You can then set Apache to automatically start on boot by running:

Install MySQL

To install the latest release of MySQL (at the time of writing this article, this is version 8.0), first we need to add the MySQL repo for yum to reference:

Then we can install MySQL:

Next, start and enable MySQL at boot:

Finally, with the installation, a temporary password was given to the root MySQL user. To get this password run:

You should receive output like such:

Copy or write down the password and then run the following command to specify a new password:

You will be prompted to provide the old, temporary password followed by providing a new password for the root user.

Install PHP

To install the latest version of PHP (which at the time of writing this article is PHP 7.3), first you must install/enable the Remi and EPEL yum repositories:

Once enabled, then you can install PHP:

[notification type=”alert-warning” close=”false”]Or you can install the default version included in the base yum repos (PHP 5.4) just by running yum install php. However, as PHP 5.4 has reached its End of Life, it is typically not recommended to use this version.[/notification]


Create Directory for Your Site

We will need a location to store the files for the site. The default location for sites is /var/www/, so let’s create a subdirectory in their for our site:

Then let’s create subdirectories specifically for our site’s public facing files, and a directory to contain logs for our site.

Create VirtualHost

To now make your site accessible publicly using Apache, you need to create an Apache VirtualHost configuration for it.

First, navigate to the folder /etc/httpd/conf.d/ and create a new .conf file for your site (i.e. Then add the following configuration details to the file, replacing ‘’ with your domain.

ServerName and ServerAlias will specify what domains are set to use this configuration. In this example, we have the base domain and the www subdomain.

DocumentRoot specifies the folder location where the site’s files can be found. This should be the folder you created to store your site’s files in the previous step.

ErrorLog and CustomLog specify log files for any errors or requests to be logged in. These should go into the log directory that was created in the previous step.

The shown <Directory> tag is optional, and just enables listing directory contents, instead of giving a 403 error, when no index file is found. The path specified in the tag should match the DocumentRoot.

Restart Apache

To reload Apache with this new configuration in place, simply run:

If that gives you any errors, double check your configuration file and folder paths to make sure the folders exist and there are no typos. You can also view the error report by running:

Upload Site Files

Now that your LAMP stack is fully configured, all that is left to do is create/upload the files to your site into the document root folder that was specified in your configuration.

As a test, you can create a file called index.php within /var/www/ and add the following code to it:

Then when you navigate to your IP or domain (if your domain’s DNS is pointed to the server), you will be shown a PHP Info page detailing the PHP configuration on the server.

Related Articles