Original: http://www.unixmen.com/how-to-install-lamp-stack-on-ubuntu-16-04/
LAMP is a combination of operating system and Open-source software stack. The acronym LAMP came from the first letters ofLinux, Apache HTTP Server, mysql or mar IADB database, and php/perl/python. This tutorial describes how to install LAMP stacks on Ubuntu 16.04, however the steps described below should work on Previo US Ubuntu versions such as Ubuntu 15.10/15.04/14.10/14.04/13.10 etc.
Install LAMP Stack on Ubuntu 16.041. 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:
sudo apt-get install apache2
Enable and start your Apache
[email protected]:~# systemctl enable apache2[email protected]:~# systemctl start apache2[email protected]:~# systemctl status apache2 Apache2.service-lsb:apache2 Web server loaded:loaded (/etc/init.d/apache2; bad; vendor preset:enabled) &NB sp; Active:active (running) since Wed 2016-03-02 09:23:37 PST; 1min 2s ago docs:man:systemd-sysv-generator (8) CGroup:/system.slice/ Apache2.service ├─22328/usr/sbin/apache2-k start ├─22331/usr/sbin/apache2-k start └─22332/usr/sbin/apache2-k Startmar 09:23:36 Ubuntu systemd[1]: Starting Lsb:apache2 Web Server ... Mar 09:23:36 Ubuntu apache2[22304]: * Starting Web server Apache2mar 09:23:36 ubuntu apache2[22304]: AH00558:apache2:Could not reliably determine the server ' s fully qualified domain name, using 127.0.1.1. Set the ' SMar 09:23:37 ubuntu apache2[22304]: *mar 09:23:37 ubuntu systemd[1]: Started lsb:apache2 Web server . Mar 09:24:34 ubuntu systemd[1]: Started lsb:apache2 Web server.
Test Apache:
Open your Web browser and navigate to http://localhost/ or http://server-ip-address/.
2. Install MySQL
MySQL is a relational database management system (RDBMS), runs as a server providing multi-user access to a N Umber of databases, though SQLite probably have 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.
Re-enter the password.
MySQL is installed now.
You can verify the MySQL server status using command:
On Ubuntu 16.04/15.10/15.04:
sudo systemctl status MySQL
On Ubuntu 14.10 and previous versions:
sudo service MySQL status
Sample output:
Mysql.service-mysql Community serverloaded:loaded (/lib/systemd/system/mysql.service; enabled; vendor preset:enable d) active:active (running) since Mon 2015-10-26 14:23:01 IST; 28s agomain pid:3577 (mysqld_safe) CGroup:/system.slice/mysql.service├─3577/bin/sh/usr/bin/mysqld_safe└─3924/usr/ Sbin/mysqld--basedir=/usr--datadir=/var/lib/mysql--... OCT 14:23:00 Server systemd[1]: Starting MySQL Community server ... OCT 14:23:00 Server mysqld_safe[3577]: 151026 14:23:00 mysqld_safe Can ' t .... OCT 14:23:00 Server mysqld_safe[3577]: 151026 14:23:00 mysqld_safe Loggin .... OCT 14:23:01 Server mysqld_safe[3577]: 151026 14:23:01 mysqld_safe starti...loct [14:23:01 server systemd[1]: Started MySQL Community Server.Hint:Some lines were ellipsized, use-l to show on full.
3. Install MariaDB
In case you want to use MariaDB instead of MySQL Community Edition, follow the steps given below.
MariaDB is a drop in replacement for MySQL. It's a robust, scalable and reliable SQL server that comes rich set of enhancements.
First you has to remove existing MySQL packages if any. To completely uninstall MySQL along with its configuration files, enter the following commands one by one:
sudo systemctl stop MySQL
sudo apt-get remove--purge mysql-server mysql-client Mysql-common
sudo rm-rf/var/lib/mysql/
After removing MySQL, run the following command to install MariaDB.
sudo apt-get install Mariadb-server
Alternatively, you can install it using the 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 are not yet updated to Ubuntu 16.04. However, we can use the repository of Ubuntu 15.10 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://download.nus.edu.sg/mirror/mariadb/repo/10.1/ubuntu Vivid main '
Update The Software sources list and install MariaDB using following commands:
sudo apt-get install Mariadb-server
During installation you'll be asked to set MySQL ' root ' user password. Enter the password twice, and complete the installation.
Important Note: In Ubuntu 16.04/15.10/15.04, MariaDB won ' t ask you to set root user password during installation.
Also, you can ' t set password manually using the following command too:
Mysql_secure_installation
It'll throw the following error.
ERROR 1698 (28000): Access denied for user ' root ' @ ' localhost ' Enter current password to root (enter for none):
To fix this error, log in to MySQL prompt without password as root user:
Then, run the following commands one by one in the MySQL prompt:
Update user set plugin= ' where user= ' root ';
That ' s it. Now, set database administrative "root" user password using command. Press Enter and go with the default settings.
Mysql_secure_installation
Sample output:
Note:running all PARTS of this SCRIPT are 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 CurrentPassword for the root user. If you ' ve just Installe D MariaDB, Andyou Haven ' t set the root password yet, the password would be is blank,so you should just press ENTER here. Enter current password to root (enter for none): OK, successfully used password, moving on ... Setting The root password ensures that nobody can log into the Mariadbroot user without the proper authorisation. Set root Password? [y/n] ynew password:re-enter new Password:password updated successfully! Reloading privilege tables. &NBSP, ..... success! By default, a MariaDB installation had an anonymous user, allowing Anyoneto log into MariaDB without had to had a user Account created forthem. This is intended only for testing, and to make the Installationgo a bit smoother. Yo U shoulD remove them before moving into aproduction environment. Remove anonymous users? [y/n] success! Normally, Root should only is allowed to connect from ' localhost ' . thisensures that someone cannot guess at the root Password from the network. Disallow Root login remotely? [y/n] success! By default, the MariaDB comes with a database named ' Test ', anyone canaccess. the is also intended only for testing , and should is removedbefore moving into a production environment. Remove test database and access to it? [y/n] -dropping test database ... ERROR 1008 (HY000) at line 1:can ' t drop database ' test '; Database doesn ' t exist failed! not critical, keep moving... -removing privileges on test database... success! Reloading the privilege tables would ensure that all changes made so farwill take effect immediately. Reload privilege tables now? [y/n] success! Cleaning up ... All done! If You've completed all of the above steps, yOur mariadbinstallation should now is secure. Thanks for using mariadb!
Check if MARIADB is running or not, using the following command:
sudo service MySQL status
Sample output:
Mysql.service-lsb:start and stop the MySQL database server daemonloaded:loaded (/etc/init.d/mysql)Active:active (running) since Mon 2015-10-26 14:26:36 IST; 2min 5s agoDocs:man:systemd-sysv-generator (8) CGroup:/system.slice/mysql.service├─6387/bin/bash/usr/bin/mysqld_safe├─6388 Logger-p Daemon err-t/etc/init.d/mysql-i└─6544/usr/sbin/mysqld--basedir=/usr--datadir=/var/lib/mysql--... OCT 14:26:39 server/etc/mysql/debian-start[6595]: mysql.time_zone_transit ... OCT 14:26:39 server/etc/mysql/debian-start[6595]: mysql.time_zone_transit ... OCT 14:26:39 server/etc/mysql/debian-start[6595]: Mysql.user ... OCT 14:26:39 server/etc/mysql/debian-start[6595]: Phase 2 6: Fixing viewsoct 14:26:39 Server/etc/mysql/debian-star T[6595]: Processing databasesoct 14:26:39 server/etc/mysql/debian-start[6595]: information_schemaoct 26 14:26:39 SERVER/ETC/MYSQL/DEBIAN-START[6595]: mysqloct 14:26:39 server/etc/mysql/debian-start[6595]: Performance_ Schemaoct 14:26:39 server/etc/mysql/debian-start[6653]: Checking for insecure R ... OCT 14:26:39 server/etc/mysql/debian-start[6657]: triggering myisam-recov ... Hint:some lines were ellipsizeD, use-l to show on full.
4. Install PHP (PHP7)
PHP (recursive acronym for PHP:HYPERTEXT Preprocessor) are a widely used Open-source general purpose scripting language that I s especially suited for web development and can is embedded into HTML.
Install PHP with following command:
sudo apt-get update sudo apt-get install php7.0-mysql php7.0-curl php7.0-json php7.0-cgi php7.0 LIBAPACHE2-MOD-PHP7
Test your PHP version
[Email protected]:~# php-vphp 7.0.3-3 (CLI) (NTS) Copyright (c) 1997-2016 the PHP groupzend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies with Zend opcache V7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies[email protecte d]:~#
To test PHP, create a sample "testphp.php" file in Apache document root folder.
sudo vi /var/www/html/testphp.php
Add the following lines:
Restart apache2 Service.
On Ubuntu 15.10/15.04:
sudo systemctl restart Apache2
On Ubuntu 14.10 and lower versions:
sudo service apache2 restart
Navigate to http://server-ip-address/testphp.php. It would display all of the details about PHP such as version, build date and commands etc.
If you want to install all PHP modules at once, enter the command sudo apt-get install php* and restart the Apach E2 Service. To verify the modules, open Web browser and navigate to http://server-ip-address/testphp.php. You'll able to see all installed PHP modules.
5. Manage MySQL Databases (Optional) Install phpMyAdmin
phpMyAdmin is a free Open-source Web interface tool used to manage your MySQL databases. It's available in the official Debian repositories. So install it with command:
sudo apt-get install phpMyAdmin
Select the WEB server that should is automatically configured to run PhpMyAdmin. In my case, it is apache2.
The phpMyAdmin must has a database installed and configured before it can be used. This can is optionally handled by Dbconfig-common.
Select ' Yes ' to configure the database for phpMyAdmin wjth Dbconfig-common.
Enter password of the database ' s administrative user.
Enter MySQL application password for phpMyAdmin:
Re-enter password:
success! PhpMyAdmin installation is installed.
Additional Note: If you followed all steps carefully, phpMyAdmin should work just fine. In case PhpMyAdmin isn't working, please do the following steps.
Open terminal, and type:
sudo nano/etc/apache2/apache2.conf
Add the following line at the end.
Include/etc/phpmyadmin/apache.conf
Save and Exit. Restart Apache Service:
On Ubuntu 16.04/15.10/15.04:
sudo systemctl restart Apache2
On Ubuntu 14.10 and lower versions:
Sudo/etc/init.d/apache2 restart
6. Access phpMyAdmin Web Console
Now, you can access the phpMyAdmin console by navigating to http://server-ip-address/phpmyadmin/ from your browse R.
Enter your MySQL username and password which you had given in previous steps. In my case it "root" and "Ubuntu".
You'll be redirected to PhpMyAdmin main web interface.
From here, you can manage your MySQL databases from PhpMyAdmin Web interface.
That ' s it. Your LAMP Stack is a ready-to-use.
Install LAMP Stack on Ubuntu 16.04