Deploy LAMP on CentOS7

Many open source p[projects require LAMP with database and database user ready to go. Here we will look at basic commands on CentOS7 to get it up and running quickly.

After CentOS7 installed update all packages

yum update -y

Install apache web server

yum install httpd

Start service and enable it to start on boot

systemctl start httpd.service
systemctl enable httpd.service

Install MariaDB database server

yum install mariadb-server mariadb

Start mysql services

systemctl start mariadb

Secure mysql installation


Enable MariaDB to start on boot

systemctl enable mariadb.service

Install PHP with mysql support

yum install php php-mysql

Restart apache web server

systemctl restart httpd.service

Open necessary firewall ports for example http

firewall-cmd --zone=public --permanent --add-service=http
firewall-cmd --reload

And finally create database and user. See example below.

create database mydb;
grant usage on *.* to mydbuser@localhost identified by 'mypassword';
grant all privileges on mydb.* to user@localhost ;

Remote MariaDB server

In some cases you may need to install database server on different system that your web server. Here is some basic steps to get it done.
yum install mariadb-server mariadb

1. Install mysql

yum install mariadb-server mariadb
systemctl enable mariadb
systemctl start mariadb

2. Edit configuretion file and add following directive

vi /etc/my.cnf
bind-address =

3. Create database and grant remote access to user

create database db_name;
grant usage on *.* to 'username'@'192.168.0.%' identified by 'Password';
grant all privileges on db_name.* to 'username'@'192.168.0.%' ;

4. Open firewall ports

firewall-cmd --zone=public --permanent --add-port=3306/tcp
firewall-cmd --reload