Install Apache HTTPD

yum install httpd

Start Apache service

systemctl start httpd.service

Enable HTTPD server as a system service

systemctl enable httpd.service

Install MySQL(MariaDB)

yum install mariadb-server mariadb

Start MariaDB service

systemctl start mariadb

Secure MySQL DB Installation


Trimmed version of screen logs:

MySQL Default root password is empty, When prompted, just enter to continue

[root@askdevops ~]# mysql_secure_installation
Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!
Remove anonymous users? [Y/n] Y
 ... Success!
Disallow root login remotely? [Y/n] Y
 ... Success!
Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!
Reload privilege tables now? [Y/n] Y
 ... Success!
All done!     
Thanks for using MariaDB!

Enable MySQL as a system service

systemctl enable mariadb.service

Install PHP and PHP-MySQL Libraries

yum install php php-mysql

Restart Apache to pick PHP installation

systemctl restart httpd.service

Test Apache & PHP installations

Create a phpinfo.php file:

echo '<?php phpinfo(); ?>' > /var/www/html/phpinfo.php

To test in commandline:

php /var/www/html/phpinfo.php

This would print a detailed information of LAMP server
To test using a web browser:


You may need to open the webserver port (PORT 80) if you are accessing it through a firewall enabled network (such as AWS EC2 etc)
Open port 80 in CentOS FirewallD

Database connection in PHP with mysqli example

To test PHP-MYSQL connectivity, the following php code is useful.
Replace username and password with appropriate username and password

# Database connection in PHP with mysqli example Script
$db_host = "localhost";
$db_user = "USERNAME";
$db_pass = "PASSWORD";

# Create MySQL connection
$conn = new mysqli($db_host, $db_user, $db_pass);

# Check MySQL connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
echo "MySQL Connected successfully";

Virtual host configuration

Apache virtual-host can be configured by creating a virtual host file, as shown below. In this example, I am creating a virtual host for www.askdevops.org

Create a file /etc/httpd/conf.d/www.askdevops.org.conf

<VirtualHost *:80>
    ServerName www.askdevops.org
    ServerAlias www.askdevops.org
    DocumentRoot /var/www/html/askdevops/public_html
    ErrorLog /var/www/html/askdevops_error.txt
Aug 11, 2017 by | 3 views
Articles for DevOps Geeks
MobaXterm Customization
CHMOD Explained!
Bash history powerful tips
Ubuntu bash from Windows