According to the desktop operating system usage data, Linux can be found on 2% of personal computers worldwide. This is not nearly as much as Windows and macOS share among desktop users, but arguing the reasons for that should be a topic of another article. Ubuntu (with all of its flavors) is one of the most popular Linux distributions.
Having in mind that Linux is the native environment for the commonly used web service stack (Apache, MySQL, PHP), goal of this article is to introduce a script that makes it easier to setup, as well as to manage, the mentioned web stack on Ubuntu.
The LAMP setup and management script can enable Ubuntu users to use the power of the underlying operating system more easily, making a setup of their working environment and adding a new project as simple as “running a wizard”.
With an intend to make available a tool for ever growing number of web developers out there that use Ubuntu, I have written and provided the script. Following lines will reveal the details about the web service stack and features of the script.
LAMP is a well-known acronym for the bundle of services that can “convert” any Linux into Apache (httpd), MySQL and PHP – web server. Ubuntu 20.04 LTS comes with Apache (httpd) 2.4.41, MySQL Server 8.021 and PHP 7.4.9 available for installation from its default repository.
Installation of those services is not complicated but numerous steps are required for configuration so that a web server could be accessible in a user’s personal environment for development.
Developers often need to use different PHP versions per project, or to test (debug) an existing application on another PHP version. Environment with multiple PHP versions adds to complexity of the setup or, at least, makes it more time consuming.
I have planned and designed the script with a clear goal to:
- shorten the time required for web server setup and configuration;
- reduce the number of steps in process;
- reduce overall complexity;
- enable users without in-depth Linux knowledge to setup their development environment, manage it and add (or remove) projects.
The LAMP setup and management script provides four operations:
- 1. LAMP setup for development environment;
- The operation removes any previously installed Apache, MySQL and PHP, websites, databases and configuration before it starts the installation. Upon successful installation phpMyAdmin access is provided in the output;
- 2. Additional PHP versions installation;
- The operation provides an option to install available PHP versions. Upon successful installation added PHP version will be available for use on Virtual Hosts;
- 3. Adding or removing Virtual Hosts (websites);
- The operation enables user to add or remove website (project) by providing FQDN. Successful execution will generate (or remove) the required configuration with the corresponding output;
- 4. Changing Virtual Host’s PHP version;
- The operation enables user to change Virtual Host’s PHP version to one of the previously installed version.
- 5. Restarting web services.
- The operation enables user to restart web services (Apache, PHP, MySQL).
- This guide may lead to data loss.
- The script may be used for setting up local development environment only.
- Do not use the script to setup a production environment as it does not have a proper security measures implemented for that purpose.
- The script has been written for Ubuntu 20.04 LTS only.
- Please, follow the instructions and warnings while executing the script.
[Download] LAMP setup and management script
Execute the script from Terminal using bash:
The script has been tested in Ubuntu 20.04 Focal Fossa.