LAMP Stack Installation 18.04
A "LAMP" stack is a group of open source software that is typically installed together to enable a server to host dynamic websites and web apps. This term is actually an acronym which represents the Linux operating system, with the Apache web server with PHP and MySQL database. The site data is stored in a MySQL database, and dynamic content is processed by PHP.
In this guide, we will install a LAMP stack on an Ubuntu 18.04 server.
Apache Web Server Install
The Apache web server is among the most popular web servers in the world. It's well-documented and has been in wide use for much of the history of the web, which makes it a great default choice for hosting a website.
Install Apache using Ubuntu's package manager
sudo apt update sudo apt install apache2
We will install the curl utility (if its not already there) as its handy to to determine external IP addresses for apps etc.
sudo apt install curl
MySQL Server Install
Install MySQL server,
sudo apt install mysql-server
Now we can configure the MySQL defaults
Answer the questions, (I would remove default access / test databases etc, only allow ROOT local access for example)
PHP is the component of your setup that will process code to display dynamic content. It can run scripts, connect to your MySQL databases to get information, and hand the processed content over to your web server to display.
Once again, leverage the apt system to install PHP. In addition, include some helper packages this time so that PHP code can run under the Apache server and talk to your MySQL database:
sudo apt install php libapache2-mod-php php-mysql
In most cases, you will want to modify the way that Apache serves files when a directory is requested. Currently, if a user requests a directory from the server, Apache will first look for a file called index.html. We want to tell the web server to prefer PHP files over others, so make Apache look for an index.php file first.
To do this, type this command to open the dir.conf file in a text editor with root privileges:
sudo nano /etc/apache2/mods-enabled/dir.conf
Modify the order of the default files to serve up.
/etc/apache2/mods-enabled/dir.conf <IfModule mod_dir.c> DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm </IfModule>
Restart Apache web server
sudo systemctl restart apache2
Check the status of the startup
sudo systemctl status apache2
To enhance the functionality of PHP, you have the option to install some additional modules. To see the available options for PHP modules and libraries, pipe the results of apt search into less, a pager which lets you scroll through the output of other commands:
apt search php- | less
Use the arrow keys to scroll up and down, and press Q to quit. The results are all optional components that you can install. It will give you a short description for each:
bandwidthd-pgsql/bionic 2.0.1+cvs20090917-10ubuntu1 amd64 Tracks usage of TCP/IP and builds html files with graphs bluefish/bionic 2.2.10-1 amd64 advanced Gtk+ text editor for web and software development cacti/bionic 1.1.38+ds1-1 all web interface for graphing of monitoring systems ganglia-webfrontend/bionic 3.6.1-3 all cluster monitoring toolkit - web front-end golang-github-unknwon-cae-dev/bionic 0.0~git20160715.0.c6aac99-4 all PHP-like Compression and Archive Extensions in Go haserl/bionic 0.9.35-2 amd64 CGI scripting program for embedded environments kdevelop-php-docs/bionic 5.2.1-1ubuntu2 all transitional package for kdevelop-php kdevelop-php-docs-l10n/bionic 5.2.1-1ubuntu2 all transitional package for kdevelop-php-l10n
To learn more about what each module does, you could search the internet for more information about them. Alternatively, look at the long description of the package by typing:
apt show package_name
There will be a lot of output, with one field called Description which will have a longer explanation of the functionality that the module provides. For example, to find out what the php-cli module does, you could type this:
apt show php-cli
If you want to install more than one module, you can do that by listing each one, separated by a space, following the apt install command, like this:
sudo apt install package1 package2 ...