Installing the Lamp Stack on a Cloud Server with Centos 7 Minimal Installation

For Cloud Servers with a CentOS 7 minimal installation

This article explains how to install a LAMP stack on a Cloud Server with a CentOS 7 minimal installation.

A LAMP stack consists of the Linux operating system and the software applications Apache, MySQL/MariaDB and PHP. These are installed together to host dynamic websites and web applications on a server.

How to install a LAMP stack:

Requirements

  • Before installing the LAMP stack, make sure that your server has sufficient hardware capacity.

  • You have installed the minimum version of the CentOS 7 operating system on your server.

Installing Apache

Proceed as follows to install Apache:

  • To check if an update is available for CentOS 7, type the command below:
    yum update

  • To install Apache, enter the following command:
    yum install httpd The following message appears:
    Total download size: 3.0 M Installed
    size: 10 M Is
    this ok [y/d/N]

  • Enter[ y ] and press [Enter].

    Apache will be installed.

  • To start Apache, type the command below:
    systemctl start httpd.service

  • To verify that Apache was successfully installed and started, enter the public IP address of your server in the following format in your web browser:

    http://YOUR-SERVER-IP-ADDRESS
    Example: http://123.234.123.255

    If you see a test page, Apache was successfully installed.

  • To automatically restart Apache when the server is restarted, enter the following command:
    systemctl enable httpd.service

Installing MariaDB

  • To install MariaDB, enter the following command:
    yum install mariadb-server mariadb The following message is displayed:
    Total download size: 21 M Installed
    size: 110 M Is
    this ok [y/d/N]

  • Enter [y] and press [Enter].

    MariaDB is installed.

  • To start MariaDB, enter the following command:
    systemctl start mariadb

  • To run a security script that removes some dangerous default settings and restricts access to the database system, enter the following command: mysql_secure_installation
    After entering the command, you will be prompted for a password. Since you have not yet defined a password for MariaDB, you can skip this point. To do this, press Enter. You will then be asked if you want to set the root password.

  • Enter [y] and press [Enter].

  • Enter a new root password, repeat it, and then press [Enter].

    The following message is displayed:
    By default, a MariaDB installation has an anonymous user, allowing anyone
    to log into MariaDB 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]

  • To remove anonymous users, enter [y] and press [Enter].

    The following message is displayed:
    Disallow root login remotely? [Y/N]

  • Enter [y] and press [Enter], and

    The following message is displayed:
    Remove test database and access to it?

  • Enter [y] and press [Enter]

    The following message is displayed:
    Reload privilege tables now?

  • To reload the authorization tables, enter [y]. To confirm the entry, press [Enter].

  • To enable MariaDB on boot, enter the following command:
    systemctl enable mariadb.service

Installing PHP

To install the PHP scripting language, proceed as follows:

  • To install the PHP-MySQL package, type the following command:
    yum install php php-mysql

  • The following message is displayed:Total download size: 4.9 M
    Installed size: 18 M
    Is this ok [y/d/N]:

  • To continue the installation, enter [y]. Then press [Enter].

  • To restart the Apache web server, type the following command:
    systemctl restart httpd.service

Installing PHP Modules

To extend the functionality of PHP, you can install additional modules.

To display the available options for PHP modules and libraries, type the following command:
yum search php-
To get detailed information about a PHP module, type the command below:

yum info package_name

Example:

yum info php-embedded.x86_64

To install the desired PHP modules, type the following command:

yum install package1 package2

Example:

yum install php-cli.x86_64 php-devel.x86_64 php-dba.x86_64

To proceed with the installation, enter [y]. Then press [Enter].

Test PHP

To test if PHP has been installed correctly, create a script with the editor. This must be stored in the directory /var/www/html.

  • To create the script in the /var/www/html directory, type the following command:
    vi /var/www/html/info.php The vi editor opens.

Note

The vi editor has an insert mode and a command mode. You can open the insert mode using the [i] key. In this mode,  the characters entered will immediately be inserted in the text in this mode. To switch to command mode, press the ESC key. When you are in command mode, key presses will be understood as commands.

Note

Vi cannot be stopped in insert mode. For that reason, you must always switch to command mode to exit vi.

  • Press [i] and enter the following PHP code:
    <?php phpinfo(); ?>

  • To enter the command mode, press [ESC]. Then type the :wq command to save the text and close the editor.

  • To test whether the contents of the PHP script are displayed, call the corresponding URL in the following format in your web browser:

    http://MY-SERVER-IP-ADDRESS/info.php

  • To remove the displayed page, enter the following command:
    rm /var/www/html/info.php