How to Setup LAMP ( Linux , Apache , Mysql , Php ) Server in Centos 7 / Redhat 7 / Fedora

Share on :

How to Setup LAMP ( Linux , Apache , Mysql , Php ) Server in Centos 7 / Redhat 7 / Fedora

LAMP Linux Apache Mysql Php Server in one of the most used web server setup to host dynamic websites in linux. We can host any dynamic Website or CMS websites like WordPress , Wix , Drupal and many more with this setup.

Now Lets Install these Softwares one by one.

Apache:-

1) Install the httpd Package.

------< for Centos 7 / Rhel 7 >------
yum install httpd -y
-------< Fedora >------
dnf install httpd -y

2) Start and enable the Service.

systemctl start httpd
systemctl enable httpd

3) Apply the firewall rule.

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

4) Open your Web Browser.

http://<your_ip>

Our Apache Web Server is Displaying the Test Page or Default Page which means our Apache web server is up and running.

MySql :-

1) Install mariadb package.

------< for Centos 7 / Rhel 7 >------
yum install mariadb mariadb-server -y
-------< Fedora >------
dnf install mariadb mariadb-server -y

We have Installed two Packages to setup mysql one is mariadb which is a client package to access mysql server and maridb-server is the mysql server package it is used to setup mysql server.

2) Start and Enable the service.

systemctl start mariadb
systemctl enable mariadb

3) Apply the firewall rule.

firewall-cmd --permanent --add-service=mysql
firewall-cmd --reload

4) Configure Mysql.

Parameters used in setting up mariadb. According to your scenario you can setup using these parameters.

Set root password? [Y/n] - Y (To Setup Root Password to the database)
Remove anonymous users? [Y/n] - Y (To Remove Anonymous Users from database)
Disallow root login remotely? [Y/n] - Y (To Disallow Remote Root login to Database)
Remove test database and access to it? [Y/n] - Y (To Remove Test Database)
Reload privilege tables now? [Y/n] - Y (To Reload Priviege)

mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):Hit Enter
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!

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] Y
... Success!

Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.


Disallow root login remotely? [Y/n] Y
... Success!


By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.


Remove test database and access to it? [Y/n] Y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!


Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.


Reload privilege tables now? [Y/n] Y
... Success!


Cleaning up...


All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.


Thanks for using MariaDB!

Now Lets Connect to our Database.

mysql -u root -p
Enter password: Enter the Root Password
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.60-MariaDB MariaDB ServerCopyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MariaDB [(none)]>

PHP :-

1) Install php.

------< for Centos 7 / Rhel 7 >------
yum install php php-mysqlnd -y
-------< Fedora >------
dnf install php php-mysqlnd -y

We have Installed two packages one in php which is for supporting php in our apache web server and php-mysqlnd which will setup database integration.

2) Restart the Apache Server service and Mariadb server serivce.

systemctl restart httpd mariadb

We Have successfully configured LAMP Stack . Now Lets check .

Let's create a file index.php and check wheater it is working with our apache server.

Note:- The Document Root of Apache server is /var/www/html here we need to upload or copy our website content
vi /var/www/html/index.php
press i to get into insert mode

<?php
phpinfo();
?>

after making changes in the file press escape from keyboard and press :wq! to write and quite from file.

Open your Web Browser

http://<your_ip>

Our LAMP Stack is up and running and working fine.

Follow our Guided tutorial on YouTube :-

LAMP Stack in Centos , Red Hat , Fedora Linux

Share on :

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *