Welcome guys with our new exciting tutorial/ article we are going to learn how to install and configure LAMP stack on linux. LAMP Web Server basically hosts the site. In the real environment you need public IP to globally access the hosted site and it’s not a good practice to give the public IP directly to the server.
What does LAMP it stand for?
L – Linux
A – Apache
M – MySQL/MariaDB
P – PHP/Python/Perl
Now let’s talk about the web the World Wide Web; now a days you mostly search these below webs
Facebook, Gmail, Wikipedia, youtube and timesjobs???
What technologies do you think these sites are running on????
As you can see in below image facebook site is running on Linux server.
Gmail is also running on Linux which is BSD distro.
These all sites are running on Linux server and so on. I have discussed only few examples and most popular sites. All those famous and your favorite web application are running somehow on Linux/LAMP.
Why advanced and future web applications are running on LAMP???
- More Secure
- Open Source and Highly scalable
- Low Cost
- Great Performance
But then why are still few companies afraid to switch on it??
Because still difficult to find good and qualified people on LAMP platform. Big and great organizations are still hungry for people on LAMP. Let us begin with brief description of each element in LAMP stack.
Linux is very reliable and fastest Operating System and extremely powerful. It performs great even with less resources. It provides programming supports as well as secured environment. Linux Kernel does not crash easily and there is no or little issue of virus.
Apache web server is used for web hosting. Apache is open source software. With the help of Apache we can host multiple websites. Apache web server run on all major platforms (*nix, Windows, Mac) and it is the largest market share holder for web services since 1996 and still growing. The main purpose of Apache is to be design fast and high-performance web server. Apache have two web servers one is Apache HTTP Server and other one is Apache Tomcat. Here we are working on HTTP Server.
Daemon of Apache is httpd
HTTP port number is 80
Sites have data and it should be stored in database. MySQL database is very popular open source software with high performance, reliability and ease of use. MySQL is a relational database system with powerful features. (We will discuss in brief in next tutorial/ article because it is a vast topic).
PHP stand for Hypertext Preprocessor. PHP is a general purpose and server script language. The syntax of PHP similar as Perl and C that’s why easy to learn. It supports wide range of databases (ODBC). If you have knowledge regarding HTML (Hyper Text Markup Language) then you easily pick and work on the PHP programming language.
Installation of Apache Web Server (HTTP)
For installation of apache web server by using yum command. Syntax yum install httpd
[root@faraz ~]# yum install httpd Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: centos.mirror.net.in * extras: centos.mirror.net.in * updates: centosc6.centos.org Resolving Dependencies --> Running transaction check ---> Package httpd.x86_64 0:2.4.6-40.el7.centos will be installed --> Processing Dependency: httpd-tools = 2.4.6-40.el7.centos for package: httpd-2.4.6-40.el7.centos.x86_64 --> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-40.el7.centos.x86_64 --> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-40.el7.centos.x86_64 --> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-40.el7.centos.x86_64 --> Running transaction check
After installation you need to start the service of apache web server (httpd).
[root@faraz ~]# systemctl start httpd [root@faraz ~]# systemctl status httpd ? httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled) Active: active (running) since Wed 2016-04-13 11:49:19 PKT; 6s ago Docs: man:httpd(8) man:apachectl(8) Main PID: 5365 (httpd) Status: "Processing requests..." CGroup: /system.slice/httpd.service +-5365 /usr/sbin/httpd -DFOREGROUND +-5440 /usr/sbin/httpd -DFOREGROUND +-5441 /usr/sbin/httpd -DFOREGROUND +-5442 /usr/sbin/httpd -DFOREGROUND +-5443 /usr/sbin/httpd -DFOREGROUND +-5444 /usr/sbin/httpd -DFOREGROUND Apr 13 11:49:08 faraz.test.server systemd: Starting The Apache HTTP Server... Apr 13 11:49:19 faraz.test.server systemd: Started The Apache HTTP Server...
If you open the browser and type the ip/localhost ip in the URL area then you get the output page of default apache web server.
Now if you want to create your own page then you need to disable the default page by editing the file welcome.conf. The full path of that file is /etc/httpd/conf.d/welcome.conf. Edit the welcome.conf file by using vi editor and comment the below lines with # (hash).
[root@faraz html]# vi /etc/httpd/conf.d/welcome.conf #
# Options -Indexes # ErrorDocument 403 /.noindex.html ## # AllowOverride None # Require all granted ##Alias /.noindex.html /usr/share/httpd/noindex/index.html #Alias /noindex/css/bootstrap.min.css /usr/share/httpd/noindex/css/bootstrap.min.css #Alias /noindex/css/open-sans.css /usr/share/httpd/noindex/css/open-sans.css #Alias /images/apache_pb.gif /usr/share/httpd/noindex/images/apache_pb.gif #Alias /images/poweredby.png /usr/share/httpd/noindex/images/poweredby.png
Now to create the web page we need to install php by using yum command.
Syntax yum install php php-sql
[root@faraz html]# yum install php php-mysql Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: centos.mirror.net.in * extras: centos.mirror.net.in * updates: centosc6.centos.org Resolving Dependencies --> Running transaction check
Now go to html directory where we are going to host our site, by default for hosting we use that directory. The full path to change the directory by using cd command is /var/www/html. Create the empty file by using touch command and named it index.php (for direct access with ip save the file name as index).
[root@faraz ~]# cd /var/www/html/ [root@faraz html]# [root@faraz html]# touch index.php [root@faraz html]# ls index.php [root@faraz html]#
Now open file with vi editor for add some basic syntax to perform sample test page as given below;
[root@faraz html]# vi index.php This is my first page for Web Server on php "; echo "www.shahid-academy.com" . "
"; $x = 10; $y = 10; echo $x + $y; ?>
Restart the service of httpd by using systemctl restart httpd.
Open browser to check the output as you can see the below image;
If you save the file with other name then for access the site you need to follow the path as well for example here I am going to change the name of file index.php to mypage.php by using mv command and access it from browser (in the URL area ip/mypage.php)
[root@faraz html]# mv index.php mypage.php [root@faraz html]# ls mypage.php [root@faraz html]#
If you write the IP only the output will be as shown in below image;
In this tutorial/ article we have learnt about web server and hosting. We have discussed about some site running on Linux web server. I hope you have easily deploy basic level of web server. We will discuss more about hosting in upcoming tutorial/ article. Keep learning with us