LAMP stack is a group of tools installed on a server to enable hosting dynamic websites and web apps. The acronym stands for: Linux, Apache, MySQL, PHP.
In this tutorial we’ll look at how to install the stack on a server running Ubuntu 17.04.
First, connect to your server with
(if you do not have physical access to the machine):
$ ssh user@SERVER_IP
Check for available updates:
$ sudo apt-get update
If there are updates, install all of them:
$ sudo apt-get upgrade
Of course, we already have the “L” part of LAMP stack, which is a running GNU/Linux system (Ubuntu 17.04).
Install the Apache web server, which is available in the Ubuntu repositories:
$ sudo apt-get install apache2
Start an Apache configuration test:
$ sudo apache2ctl configtest
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using fe80::5054:ff:fe69:a3e0. Set the 'ServerName' directive globally to suppress this message Syntax OK
There are no syntax errors, however the test returns a warning message saying that we didn’t set up a FQDN (fully qualified domain name). This warning message is harmless, but it will show up when checking your Apache configuration for syntax errors.
Edit the Apache main configuration:
$ sudo $EDITOR /etc/apache2/apache2.conf
At the end of this file, add a
directive, pointing to server domain or IP. For the purpose of this tutorial we’ll write:
Save, close the file and check for syntax errors in configuration:
$ sudo apache2ctl configtest
Now, the result will be:
$ sudo systemctl restart apache2
Open a web browser and go to your server URL. If you see the following page, Apache is correctly running:
At this point, you also have a web server up and running. Next step is to install the database management system, MySQL.
MySQL is available in Ubuntu repositories, so use
$ sudo apt-get install mysql-server
During the installation, you will be asked for the root account password
At the end of this process, we’ll change some default configurations, running the following script:
Securing the MySQL server deployment. Enter password for user root: VALIDATE PASSWORD PLUGIN can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD plugin? Press y|Y for Yes, any other key for No: N Using existing password for root. Change the password for root ? ((Press y|Y for Yes, any other key for No) : ... skipping. By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL 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? (Press y|Y for Yes, any other key for No) : 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? (Press y|Y for Yes, any other key for No) : y Success. By default, MySQL 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? (Press y|Y for Yes, any other key for No) : 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? (Press y|Y for Yes, any other key for No) : y Success. All done!
The database system is now set up!
The next part of the LAMP stack is a PHP environment. This is the part that will process the code to display dynamic content. Install PHP using
$ sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql
PHP has a lot of different modules that can be easily installed to enhance its functionality. Look for these additional modules with
$ apt-cache search php- | less
libnet-libidn-perl - Perl bindings for GNU Libidn php-all-dev - package depending on all supported PHP development packages php-cgi - server-side, HTML-embedded scripting language (CGI binary) (default) php-cli - command-line interpreter for the PHP scripting language (default) php-common - Common files for PHP packages php-curl - CURL module for PHP [default] php-dev - Files for PHP module development (default) php-gd - GD module for PHP [default] php-gmp - GMP module for PHP [default] php-ldap - LDAP module for PHP [default] php-mysql - MySQL module for PHP [default] php-odbc - ODBC module for PHP [default] php-pear - PEAR Base System php-pgsql - PostgreSQL module for PHP [default] php-pspell - pspell module for PHP [default] php-recode - recode module for PHP [default] php-snmp - SNMP module for PHP [default] php-sqlite3 - SQLite3 module for PHP [default] php-tidy - tidy module for PHP [default] php-xmlrpc - XMLRPC-EPI module for PHP [default] php7.0-cgi - server-side, HTML-embedded scripting language (CGI binary) php7.0-cli - command-line interpreter for the PHP scripting language php7.0-common - documentation, examples and common module for PHP ...
To test PHP, create a new basic file named
in the Apache web root, which, for Ubuntu, is
$ sudo $EDITOR /var/www/html/info.php
In this file, paste the following code:
<?php phpinfo(); ?>
Save and close this. Next, with a web browser, go to:
. If everything is working well, it should display the following page
Now we have a LAMP stack correctly installed. This is the first basic step for hosting dynamic websites or web apps.
In the next weeks we will learn how to build different “environments” on top of this LAMP stack. Keep your eyes on Unixmen!