CentOS Tutorial – Install LAMP Stack on CentOS 7

CentOS Tutorial – This quick tutorial will show you how to install LAMP on CentOS 7. LAMP stands for Linux Apache MySQL and PHP, a great combination to build a powerful web server and web applications on top of Linux system. 

Steps to install LAMP on CentOS 7

Step 1. Update CentOS

First we need to make sure our system is up to date.

yum update

Step 2. Install Apache web server

yum install httpd

Now start and enable Apache

systemctl start httpd
systemctl enable httpd

Test the web server

Open a web browser and point to the CentOS IP address and you should see something like this

Step 3. Install MariaDB

Now we can start install MariaDB Server using this command

yum install mariadb mariadb-server

Start MariaDB service and enable it during startup

systemctl start mariadb
systemctl enable mariadb

Secure MariaDB installation

mysql_secure_installation

Follow on screen wizard to complete this step. You will be asked to enter the root password which is empty (simply press enter) and then you can specify a new password for root user.

Now make sure MariaDB is up and running

systemctl status mariadb

Output:

[root@localhost ~]# systemctl status mariadb
● mariadb.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)
   Active: active (running) since Rab 2017-05-24 05:59:59 EDT; 2min 11s ago
  Process: 16225 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS)
  Process: 16145 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS)
 Main PID: 16224 (mysqld_safe)
   CGroup: /system.slice/mariadb.service
           ├─16224 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
           └─16381 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysq...

Mei 24 05:59:56 localhost.localdomain mariadb-prepare-db-dir[16145]: which wi...
Mei 24 05:59:56 localhost.localdomain mariadb-prepare-db-dir[16145]: database...
Mei 24 05:59:56 localhost.localdomain mariadb-prepare-db-dir[16145]: strongly...
Mei 24 05:59:56 localhost.localdomain mariadb-prepare-db-dir[16145]: See the ...
Mei 24 05:59:56 localhost.localdomain mariadb-prepare-db-dir[16145]: MySQL ma...
Mei 24 05:59:56 localhost.localdomain mariadb-prepare-db-dir[16145]: You can ...
Mei 24 05:59:56 localhost.localdomain mariadb-prepare-db-dir[16145]: cd '/usr...
Mei 24 05:59:56 localhost.localdomain mysqld_safe[16224]: 170524 05:59:56 mys...
Mei 24 05:59:56 localhost.localdomain mysqld_safe[16224]: 170524 05:59:56 mys...
Mei 24 05:59:59 localhost.localdomain systemd[1]: Started MariaDB database se...
Hint: Some lines were ellipsized, use -l to show in full.

Step 4. Install PHP

Now we need to install PHP on our system use this command instead

yum install php php-mysql

Output

[root@localhost ~]# yum install php php-mysql
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: centos.biz.net.id
 * extras: repo.apiknet.co.id
 * updates: repo.apiknet.co.id
Resolving Dependencies
--> Running transaction check
---> Package php.x86_64 0:5.4.16-42.el7 will be installed
--> Processing Dependency: php-common(x86-64) = 5.4.16-42.el7 for package: php-5.4.16-42.el7.x86_64
--> Processing Dependency: php-cli(x86-64) = 5.4.16-42.el7 for package: php-5.4.16-42.el7.x86_64
---> Package php-mysql.x86_64 0:5.4.16-42.el7 will be installed
--> Processing Dependency: php-pdo(x86-64) = 5.4.16-42.el7 for package: php-mysql-5.4.16-42.el7.x86_64
--> Running transaction check
---> Package php-cli.x86_64 0:5.4.16-42.el7 will be installed
---> Package php-common.x86_64 0:5.4.16-42.el7 will be installed
--> Processing Dependency: libzip.so.2()(64bit) for package: php-common-5.4.16-42.el7.x86_64
---> Package php-pdo.x86_64 0:5.4.16-42.el7 will be installed
--> Running transaction check
---> Package libzip.x86_64 0:0.10.1-8.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

======================================================================================================================================================
 Package                              Arch                             Version                                   Repository                      Size
======================================================================================================================================================
Installing:
 php                                  x86_64                           5.4.16-42.el7                             base                           1.4 M
 php-mysql                            x86_64                           5.4.16-42.el7                             base                           101 k
Installing for dependencies:
 libzip                               x86_64                           0.10.1-8.el7                              base                            48 k
 php-cli                              x86_64                           5.4.16-42.el7                             base                           2.7 M
 php-common                           x86_64                           5.4.16-42.el7                             base                           564 k
 php-pdo                              x86_64                           5.4.16-42.el7                             base                            98 k

Transaction Summary
======================================================================================================================================================
Install  2 Packages (+4 Dependent packages)

Total download size: 4.9 M
Installed size: 18 M
Is this ok [y/d/N]:

Restart Apache

systemctl restart httpd

Check if PHP correctly installed

Create new file called info.php under /var/www/html directory

nano /var/www/html/info.php

Now paste this line to it

<?php phpinfo(); ?>

Now open web browser and type the server ip address with info.php. For example in my case:

http://10.34.0.215/info.php

Done, now we have a working LAMP Server on CentOS 7 server. Thanks for reading this how to install LAMP on CentOS 7 Server. Cheers

1 Comment

  1. Thanks for your personal marvelous posting!
    I seriously enjoyed reading it, you happen to be a great author.
    I will be sure to bookmark your blog and may come back later on.
    I want to encourage you to ultimately continue your great job, have
    a nice morning!

3 Trackbacks / Pingbacks

  1. How to install Owncloud 10 on CentOS 7.3 Server - Free Linux Tutorials
  2. CentOS Tutorial - How to install PHPMyAdmin on CentOS 7.3
  3. Arch Linux Tutorial to install LAMP Server on Arch Linux 2017 Server

Leave a Reply