May 2024
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  

Categories

May 2024
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  

LAMP server on centos 7

LAMP server on centos 7

LAMP is a group of open source softwares installed together to build a webserver. LAMP refers to Linux (Operating system), Apache (Web service), MySQL/MariaDB (Database) , PHP (Programming language).
This guide helps you to install LAMP server on centos 7.
Before starting installation, you need to setup Static IP and hostname .
You can also refer this guide – Setup network on centos 7 to setup static ip and hostname.
Install LAMP server on centos 7.
1. Apache installation.
2. Mysql installation.
3. PHP installation.
4. Testing all together.
let’s start

Apache installation
Step 1 » Update the repositories.
[root@clusterserver1 ~]# yum check-update

[root@clusterserver1 ~]# yum update

[root@clusterserver1 ~]# yum install httpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.vodien.com
* epel: mirrors.vinahost.vn
* extras: mirror.vodien.com
* updates: mirror.vodien.com
Package httpd-2.4.6-31.el7.centos.x86_64 already installed and latest version
Nothing to do
[root@clusterserver1 ~]#

Apache installation
Step 1 » Update the repositories.

[root@clusterserver1 ~]# systemctl start httpd.service
[root@clusterserver1 ~]# systemctl star^Chttpd.service
[root@clusterserver1 ~]# systemctl enable httpd.service
[root@clusterserver1 ~]# systemctl status httpd.service
httpd.service – The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled)
Active: active (running) since Sun 2015-04-12 03:30:50 SGT; 6min ago
Main PID: 25200 (httpd)
Status: “Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec”
CGroup: /system.slice/httpd.service
??25200 /usr/sbin/httpd -DFOREGROUND
??25201 /usr/sbin/httpd -DFOREGROUND
??25202 /usr/sbin/httpd -DFOREGROUND
??25203 /usr/sbin/httpd -DFOREGROUND
??25204 /usr/sbin/httpd -DFOREGROUND
??25205 /usr/sbin/httpd -DFOREGROUND

Apr 12 03:30:50 clusterserver1 httpd[25200]: AH00558: httpd: Could not reliably determine the server’s fully qualified domain …essage
Apr 12 03:30:50 clusterserver1 systemd[1]: Started The Apache HTTP Server.
Apr 12 03:37:16 clusterserver1 systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.

By default, Apache will listen on port 80. you need to exclude from firewall.
you can simply exclude http service from firewall.

firewall-cmd –permanent –add-service http
or you can exclude using port number. Below command will be useful for ports other than 80

firewall-cmd –permanent –add-port=8080/tcp

Step 5 » Now restart firewall service.
systemctl restart firewalld.service

apache

 

 

MySQL installation.

Start installing MariaDB, MySQL drop-in replacement.
[root@clusterserver1 ~]# yum install mariadb-server mariadb
[root@clusterserver1 ~]# systemctl start mariadb
[root@clusterserver1 ~]#
[root@clusterserver1 ~]# mysql_secure_installation
/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found

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):
ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)
Enter current password for root (enter for none):
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] n
… skipping.

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!

PHP installation.
Install PHP and other recommended packages.
yum install php php-mysql

Additional packages are required if you would like to install phpmyadmin .

yum install php-gd php-pear php-mbstring php-pgsql

Now restart apache service

systemctl restart httpd.service

 

[root@clusterserver1 html]# cat phpinfo.php
<?php phpinfo(); ?>

apache2

[root@clusterserver1 html]# cat dbtest.php
<?php
$con = mysql_connect(“localhost”,”root”,”test123″);
if (!$con)
{
die(‘Could not connect: ‘ . mysql_error());
}
else
{
echo “Congrats! connection established successfully”;
}
mysql_close($con);
?>

 

apache3

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>