Friday, October 31, 2014

Install LAMP Server (Apache, MySQL or MariaDB, PHP) On Ubuntu 14.10/14.04/13.10

Install LAMP Server (Apache, MySQL or MariaDB, PHP) On Ubuntu 14.10/14.04/13.10

 

LAMP is a combination of operating system and open-source software stack. The acronym LAMP comes from the first letters of Linux, Apache HTTP Server, MySQL or MariaDB database, and PHP/Perl/Python.
In this tutorial, we will see how to setup LAMP server on Ubuntu 14.10 system.

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.
To install Apache, enter the following command from your terminal:
sudo apt-get install apache2

Test Apache:

Open your web browser and navigate to http://localhost/ or http://server-ip-address/.
Apache2 Ubuntu Default Page: It works - Mozilla Firefox_004

Install MySQL

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
sudo apt-get install mysql-server mysql-client
During installation, you’ll be asked to setup the MySQL root user password. Enter the password and click Ok.
sk@server: ~_002
Re-enter the password.
sk@server: ~_003
Now, MySQL server has been installed.
You can verify the MySQL server status using command:
sudo service mysql status
Sample output:
mysql start/running, process 11690
Note: If you want to use MariaDB instead of MySQL, then follow these steps.

Install MariaDB

MariaDB is a drop in replacement for MySQL. It is a robust, scalable and reliable SQL server that comes rich set of enhancements.
First you have to remove existing MySQL packages if any. To completely uninstall MySQL along with its configuration files, enter the following command:
sudo apt-get purge mysql*
Run the following command to remove unwanted packages.
sudo apt-get autoremove
After removing MySQL, run the following command to install MariaDB.
sudo apt-get install mariadb-server mariadb-client
Alternatively, you can install it from MariaDB repository if you want to try most recent version of MariaDB. Run the following commands to add PPA. As of writing this, MariaDB PPA is not yet updated to Ubuntu 14.10. However, we can use the repository of Ubuntu 14.04 instead.
sudo apt-get install software-properties-common
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
sudo add-apt-repository 'deb http://sgp1.mirrors.digitalocean.com/mariadb/repo/5.5/ubuntu trusty main'
Update the software sources list and install MariaDB using following commands:
sudo apt-get update 
sudo apt-get install mariadb-server mariadb-client
During installation you will be asked to set mysql ‘root’ user password.
sk@server: ~_004
Re-enter password:
sk@server: ~_005
Check if mariadb is running or not, using the following command:
sudo service mysql status
Sample output:
 * /usr/bin/mysqladmin  Ver 9.0 Distrib 5.5.40-MariaDB, for debian-linux-gnu on x86_64
Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others.

Server version        5.5.40-MariaDB-1~trusty-log
Protocol version    10
Connection        Localhost via UNIX socket
UNIX socket        /var/run/mysqld/mysqld.sock
Uptime:            15 sec

Threads: 1  Questions: 571  Slow queries: 0  Opens: 332  Flush tables: 4  Open tables: 22  Queries per second avg: 38.066

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.
Install PHP with following command:
sudo apt-get install php5 php5-mysql libapache2-mod-php5
To test PHP, create a sample “testphp.php” file in Apache document root folder.
sudo nano /var/www/html/testphp.php
Add the following lines.
<?php
phpinfo();
?>
Restart apache2 service:
sudo service apache2 restart
Navigate to http://server-ip-address/testphp.php. It will display all the details about php such as version, build date and commands etc.
phpinfo() - Mozilla Firefox_001
If you want to install all php modules, enter the command sudo apt-get install php* and restart the apache2 service. To verify the modules, open web browser and navigate to http://server-ip-address/testphp.php. You will able to see all installed php modules.

Manage MySQL Databases (Optional)

Install phpMyAdmin

phpMyAdmin is a free open-source web interface tool used to manage your MySQL databases. It is available in the Official Debian repositories. So install it with command:
sudo apt-get install phpmyadmin
Select the Web server you use. In my case, it is apache2.
sk@server: ~_007
Select ‘Yes’ to configure database for phpmyadmin wjth dbconfig-common.
sk@server: ~_008
Enter password of the database’s administrative user.
sk@server: ~_009
Enter MySQL application password phpmyadmin.
sk@server: ~_010
Re-enter the password.
sk@server: ~_011
Success, phpMyAdmin installation has been completed now.

Access phpMyAdmin Web Console

Now, you can access the phpmyadmin console by navigating to http://server-ip-address/phpmyadmin/ from your browser.
Enter your MySQL username and password which you have given in previous steps. In my case its “root” and “ubuntu”.
phpMyAdmin - Mozilla Firefox_002
You will be redirected to PhpMyAdmin main web interface.
192.168.1.100 - localhost | phpMyAdmin 4.2.6deb1 - Mozilla Firefox_003
Now, you can manage your MySQL databases from phpMyAdmin web interface.
That’s it. Your LAMP server is up and running now.

 

No comments: