Google+ Badge

Tuesday, December 23, 2014

How To Install Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu 14.04

About LAMP
LAMP stack is a group of open source software used to get web servers up and running. The acronym stands for Linux, Apache, MySQL, and PHP. The user to have root privileges on your VPS.

Step 1 - Install Apache :
Apache is an open-source multi-platform web server. It provides a full range of web server features including CGI, SSL and Virtual domains.

     root@digidom:~# sudo apt-get update
     root@digidom:~# sudo apt-get install apache2

How to Find your Server’s IP address :

     root@digidom:~# ifconfig eth0 | grep inet | awk '{ print $2 }'

That’s it. To check if Apache is installed, go to your browser and enter your server’s IP address (Eg. http://Your-Server-IP Address).

Step 2 - Install MySQL :

MySQL is a powerful database management system used for organizing and retrieving data. MySQL is a relational database management system (RDBMS) that runs as a server providing multi-user access to a number of databases, though SQLite probably has more total embedded deployments.

    root@digidom:~# sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql

During the installation, MySQL will ask you to set a root password. If you miss this step while the program is installing, it is very easy to set the password later from within the MySQL shell.

Re-enter the password.

To check the mysql  Directory locations :

     root@digidom:~# whereis mysql 
          mysql:/usr/bin/mysql  /etc/mysql  /usr/lib/mysql  /usr/share/mysql     /usr/share/man/man1/mysql.1.gz

To create Database directory structure :

Once you have installed MySQL, we should activate it with this command "mysql_install_db"

To run security script that will remove default setting :

Afterwards, we want to run a simple security script that will remove some dangerous defaults and lock down access to our database system a little bit. Start the interactive script by running  "mysql_secure_installation".


Restart mysql service and Check the mysql status :

Step 3 - Install PHP :

PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely used open-source general purpose scripting language that is especially suited for web development and can be embedded into HTML.

     root@digidom:~# apt-get install php5 libapache2-mod-php5 php5-mcrypt

     root@digidom:~# php -v
     PHP 5.5.9-1ubuntu4.5 (cli) (built: Oct 29 2014 11:59:10)
     Copyright (c) 1997-2014 The PHP Group
     Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies with Zend      OPcache v7.0.3,       Copyright (c) 1999-2014, by Zend Technologies

Modify apache server file and Add index.php to begin :

If a user requests a directory from the server, Apache will first look for a file called index.html. We want to tell our web server to prefer PHP files, so we'll make Apache look for an index.php file first.

     root@digidom:~# vi /etc/apache2/mods-enabled/dir.conf
          <IfModule mod_dir.c>
                 DirectoryIndex index.php index.html index.cgi index.xhtml index.htm

Check the PHP Modules :

PHP also has a variety of useful libraries and modules that you can add onto your virtual server. You can see the libraries that are available.

root@digidom:~# apt-cache search php5-
php5-cgi - server-side, HTML-embedded scripting language (CGI binary)
php5-cli - command-line interpreter for the php5 scripting language
php5-common - Common files for packages built from the php5 source
php5-curl - CURL module for php5
php5-dbg - Debug symbols for PHP5
php5-dev - Files for PHP5 module development
php5-gd - GD module for php5
php5-gmp - GMP module for php5
php5-json - JSON module for php5
php5-ldap - LDAP module for php5
php5-mysql - MySQL module for php5
php5-odbc - ODBC module for php5
php5-pgsql - PostgreSQL module for php5
php5-pspell - pspell module for php5
php5-readline - Readline module for php5
php5-recode - recode module for php5
php5-snmp - SNMP module for php5
php5-sqlite - SQLite module for php5
php5-tidy - tidy module for php5
php5-xmlrpc - XML-RPC module for php5
php5-xsl - XSL module for php5
ibphp5-embed - HTML-embedded scripting language (Embedded SAPI library)
php5-adodb - Extension optimising the ADOdb database abstraction library
php5-apcu - APC User Cache for PHP 5
php5-enchant - Enchant module for php5
php5-exactimage - fast image manipulation library (PHP bindings)
php5-fpm - server-side, HTML-embedded scripting language (FPM-CGI binary)
php5-gdcm - Grassroots DICOM PHP5 bindings
php5-gearman - PHP wrapper to libgearman
php5-geoip - GeoIP module for php5
php5-gnupg - wrapper around the gpgme library
php5-imagick - ImageMagick module for php5
php5-imap - IMAP module for php5
php5-interbase - interbase/firebird module for php5
php5-intl - internationalisation module for php5
php5-lasso - Library for Liberty Alliance and SAML protocols - PHP 5 bindings
php5-librdf - PHP5 language bindings for the Redland RDF library
php5-mapscript - php5-cgi module for MapServer
php5-mcrypt - MCrypt module for php5
php5-memcache - memcache extension module for PHP5
php5-memcached - memcached extension module for PHP5, uses libmemcached
php5-midgard2 - midgard2 Content Repository - PHP5 language bindings and module
php5-ming - Ming module for php5
php5-mongo - MongoDB database driver
php5-msgpack - PHP extension for interfacing with MessagePack
php5-mysqlnd - MySQL module for php5 (Native Driver)
php5-mysqlnd-ms - MySQL replication and load balancing module for PHP
php5-oauth - OAuth 1.0 consumer and provider extension
php5-pinba - Pinba module for PHP 5
php5-ps - ps module for PHP 5
php5-radius - PECL radius module for PHP 5
php5-redis - PHP extension for interfacing with Redis
php5-remctl - PECL module for Kerberos-authenticated command execution
php5-rrd - PHP bindings to rrd tool system
php5-sasl - Cyrus SASL Extension
php5-stomp - Streaming Text Oriented Messaging Protocol (STOMP)client module for PHP 
php5-svn - PHP Bindings for the Subversion Revision control system
php5-sybase - Sybase / MS SQL Server module for php5
php5-tokyo-tyrant - PHP interface to Tokyo Cabinet's network interface, Tokyo Tyrant
php5-vtkgdcm - Grassroots DICOM VTK PHP bindings
php5-xcache - Fast, stable PHP opcode cacher
php5-xdebug - Xdebug Module for PHP 5
php5-xhprof - Hierarchical Profiler for PHP5

Once you decide to install the module, type :

     root@digidom:~#  sudo apt-get install "name of the module"

Step 4 - Check LAMP Server :

Although LAMP is installed, we can still take a look and see the components online by creating a quick php info page.

To test PHP, create a sample “phpinfo.php” file in Apache Document Root folder.

Then Save and Exit. 

Restart apache and mysql :

      root@digidom:/var/www/html# /etc/init.d/apache2 restart
      * Restarting web server apache2                         [ OK ]

      root@digidom:/var/lib/mysql# /etc/init.d/mysql  restart
      * Stopping MySQL database server mysqld           [ OK ]
      * Starting MySQL database server mysqld            [ OK ]
      * Checking for tables which need an upgrade, are corrupt or were not closed cleanly.

Navigate to http://server-ip-address/phpinfo.php. It will display all the details about apache, mysql and php such as version, build date and commands etc.

You can check php and mysql connectivity by using this script :

Testing MySQL connection with PHP script.Create the file /var/www/html/phpmysql.php then add the following line on below. Replace the password with your mysql root password.

To see script running successfully.

That's it............