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 maximum used net server setup to host dynamic websites in linux. We can host any dynamic Website or CMS web sites like WordPress , Wix , Drupal and plenty of greater with this setup.
Now Lets Install those Softwares one at a time.
How to Setup LAMP, 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.
Our Apache Web Server is Displaying the Test Page or Default Page because of this our Apache web server is up and walking.
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 Packages to setup mysql one is mariadb that is a client package to access mysql server and maridb-server is the mysql server package deal 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 situation you can setup the use of those parameters.
Set root password? [Y/n] – Y (To Setup Root Password to the database) Remove nameless customers? [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 get admission to 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)]>
How to Setup LAMP, 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 packages one in php that is for assisting php in our apache internet server and php-mysqlnd with the intention to setup database integration.
2) Restart the Apache Server provider and Mariadb server serivce.
systemctl restart httpd mariadb
We Have efficaciously configured LAMP Stack . Now Lets check .
Let’s create a record index.Personal home page and check wheater it’s far running 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
Our LAMP Stack is up and running and working fine.