Writing a LAMP install.sh, but why?. Nobody wants to manually configure a server. Not every time you need one. What if you need to scale to 1,000 installs overnight, 10,000? Scaling a LAMP install. Writing an install.sh, what does that actually provide? With an install.sh most if not all of the install process is automatic. Sure we can use the above image to install one LAMP server, however, I like to know how the server is being configured so I can replicate it to 1,000 or 100,000. This is the outcome of exactly that.
So, what is a LAMP? Put simply, they are an organization of components that make up a server. The letters LAMP stands for Linux, Apache, MySQL, and PHP. All together, they provide a proven platform of software for delivering high-performance web sites and applications. Each component of the LAMP contributes essential capabilities to the stack:
Linux: The operating system. We are going to use Ubuntu 20.04 LTS
Linux represents an entire industry of software. Linux is mostly a free and open source operating system (OS) that has been around since the mid-1990s. Today, it has quite an extensive worldwide user base that extends across every industry. Linux is popular in part, not only because it is free of licensing fees, because it offers more flexibility and configuration options than some other operating systems.
Apache: The web server. We are going to use Apache2
The Apache web server processes requests and serves up web assets via HTTP so that the application is accessible to anyone in the public domain over a simple web URL. Developed and maintained by an open community, Apache is a mature, feature-rich server that runs a large share of the websites currently on the internet.
MySQL: The database. We are going to use MySQL 8.0
MySQL is a relational database management system for storing a wide range of application data. With MySQL, you can store all your information in a format that is easily queried with the SQL language. Recently MySQL was acquired by Oracle and in doing so the original MySQL programmers wrote MariaDB. Which is a MySQL drop in replacement should you need it.
PHP: The programming language. We are going to use PHP7.4
The PHP open source scripting language works with Apache to help you create dynamic web pages. You cannot use HTML to perform dynamic processes such as pulling data out of a database. To provide this type of functionality, you simply drop PHP code into the parts of a page that you want to be dynamic.
The LAMP stack is a layered architecture, with Linux at the lowest level. The next layer is Apache and MySQL, followed by PHP. While PHP is nominally at the top layer, in this stack the PHP component resides inside the Apache web server.
That brings us to just how to do it? That is why I am writing this. Recently I had the need to for a fairly robust web server that is capable of running web apps well. So I did what everybody does now and I found what others have done and what I found was a plethora of old knowledge without a decent amount of more recent installs it makes it difficult to get a fully working setup. So I started from scratch.
Getting this right took a while, you get to easily fast forward through the tough parts and see a much more simplified version of what I went through. If you are not using this in a script ran as root then you will need to append each line with sudo or use the command sudo -i to stay in sudo as you complete the steps below.
First we update the server.
apt-get update
Upgrade.
apt upgrade -y
Install Apache web server and Apache utilities.
apt-get install -y apache2-utils apache2
Restart the Apache web server.
service apache2 restart
Install MySQL server.
apt-get install -y mysql-server
Now everything else:
apt-get install -y php7.4 libapache2-mod-php7.4 libapache2-mod-fcgid software-properties-common zip unzip php7.4-fpm php php-mysql
Wait there is more:
apt-get install -y phpmyadmin
Verify web services are working by using curl to see.
curl localhost
The next three lines automatically set the apache2.conf without intervention from you. Part of setting up phpmyadmin and configuration of Apache web server.
echo >> /etc/apache2/apache2.conf echo '#phpmyadmin include' >> /etc/apache2/apache2.conf echo 'Include /etc/phpmyadmin/apache.conf' >> /etc/apache2/apache2.conf
Lastly, we finish with setting up PHP MCrypt and MBString, doing an update, and restarting the Apache2 web server to solidify and reloading settings.
MCrypt while not absolutely needed it is functionally helpful and why I added it. MCrypt is a file encryption method. It allows users to encrypt files or data streams without using cryptographers.
Mbstring is used to convert strings to different encodings. Also not absolutely needed but very helpful.
phpenmod mcrypt phpenmod mbstring apt-get update service apache2 restart
Now browse to your http://localhost/index.html http://localhost/phpmyadmin and you are done.
If you liked this checkout some of my others:
Containing Your Game Servers – Building Minecraft Servers Using Docker.