Tutorials for centos 7
User avatar
By adm_3ch
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 Ch-center 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:
Code: Select all
yum install httpd
After installing Apache, you will want to make sure that it is started by running:
Code: Select all
systemctl start httpd
You can then set Apache to automatically start on boot by running:
Code: Select all
systemctl enable httpd

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:
Code: Select all
yum localinstall
Then we can install MySQL:
Code: Select all
yum install mysql-community-server
Next, start and enable MySQL at boot:
Code: Select all
# systemctl start mysqld
# systemctl enable mysqld
Finally, with the installation, a temporary password was given to the root MySQL user. To get this password run:
Code: Select all
grep 'temporary password' /var/log/mysqld.log
You should receive output like such:
Code: Select all
2019-03-28T23:06:39.680264Z 1 [Note] A temporary password is generated for [email protected]: ************
Copy or write down the password and then run the following command to specify a new password:
Code: Select all
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:
Code: Select all
# yum install epel-release
# rpm -Uvh
Once enabled, then you can install PHP:
Code: Select all
yum --enablerepo=remi-php73 install php
Or you can install the default version included in the base yum repos (PHP 5.4) just by running =12px !important=12px !importantyum install php. However, as PHP 5.4 has reached its End of Life, it is typically not recommended to use this version.

ConfigurationCreate Directory for Your Site

Or you can install the default version included in the base yum repos (PHP 5.4) just by running
Code: Select all
yum install php
However, as PHP 5.4 has reached its End of Life, it is typically not recommended to use this version.

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:
Code: Select all
mkdir /var/www/
Then let’s create subdirectories specifically for our site’s public facing files, and a directory to contain logs for our site.
Code: Select all
# mkdir /var/www/
# mkdir /var/www/
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
Code: Select all
Create a new .conf file for your site (i.e. Then add the following configuration details to the file, replacing ‘’ with your domain.
Code: Select all
<VirtualHost *:80>
DocumentRoot /var/www/
ErrorLog /var/www/
CustomLog /var/www/ combined

# Enables directory listing when no index file is found
<Directory /var/www/>
Options +Indexes
 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:
Code: Select all
apachectl restart
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:
Code: Select all
systemctl status httpd

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:
Code: Select all
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.

Intel® Xeon 2.53GHz [...]