DEV Community


Posted on • Updated on

Add a LAMP Stack to a server with Centos OS

Log in as root


add a new user with sudo privileges

[root@myserver ~]# adduser admin
[root@myserver ~]# passwd admin
Changing password for user admin.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[root@myserver ~]# usermod -aG wheel admin

change from root to new user

[root@myserver ~]# su - admin
[admin@myserver ~]$ sudo ls -la /root

[sudo] password for admin:

update Centos

[admin@myserver ~]$ sudo yum update

add apache

[admin@myserver ~]$ sudo yum install httpd

start apache

[admin@myserver ~]$ sudo systemctl start httpd.service

add mariadb

[admin@myserver ~]$ sudo yum install mariadb-server mariadb

start mariadb

[admin@myserver ~]$ sudo systemctl start mariadb

secure mariadb

[admin@myserver ~]$ sudo mysql_secure_installation

system will ask these questions. answer with y

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!
Cleaning up...

let system start maria db

[admin@myserver ~]$ sudo systemctl enable mariadb.service

add php and mysql

[admin@myserver ~]$ sudo yum install php php-mysql

restart apache

[admin@myserver ~]$ sudo systemctl restart httpd.service

install nano editor

[admin@myserver ~]$ sudo yum install nano

add php info file so you can check your installation

[admin@myserver ~]$ sudo nano /var/www/html/info.php

info page is at http://youripaddress/info.php

that's it. go to your ip address and you should have the apache start page

Top comments (2)

lmuzquiz profile image
lmuzquiz • Edited

You might want to add the word "Centos" on the title to clarify it's a Centos server, . Instructions may vary if the server is Ubuntu, Debian, not to mention any other kind of server which is not Linux

jrohatiner profile image

Thanks for pointing that out. I will definitely do that!