Install a LAMP stack manually on Lightsail instance with this handy guide by our experts.
At Bobcares, we offer solutions for every query, big and small, as a part of our Server Management Service.
Let’s take a look at how our Support Team is ready to help customers install a LAMP stack manually on Lightsail instance.
How to install a LAMP stack manually on Lightsail instance
This in-depth guide, by our skilled Support Engineers, is your answer to installing a LAMP manually on your Lightsail instance.
Moreover, this handy guide covers major Linux distributions under the OS Only option in Amazon Lightsail:
- Ubuntu 20.04
- Ubuntu 18.04
- Debian 10 and 9
- CentOS 8 and 7
How to install Apache
- Ubuntu 20.04 and 18.04, Debian 9 and 10
Here, we run the commands below to install the Apache webserver:sudo apt update -y sudo apt install apache2 -y
- CentOS 7 and CentOS 8
We have to run these commands to install the Apache webserver:sudo yum update -y sudo yum install httpd wget -y sudo systemctl enable httpd sudo systemctl start httpd
How to install PHP
- Ubuntu 20.04 and Ubuntu 18.04
Run these commands to install PHP:sudo apt-get install software-properties-common sudo add-apt-repository ppa:ondrej/php sudo apt-get update -y sudo apt install php8.0 php8.0-{fpm,mysql,curl,gd,mbstring,mysql,xml,mcrypt,zip,ldap} libapache2-mod-php8.0 -y
- Debian 10 and Debian 9
Here we execute the following commands to install PHP:sudo apt install -y gnupg2 ca-certificates apt-transport-https software-properties-common wget -qO - https://packages.sury.org/php/apt.gpg | sudo apt-key add - echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/sury-php.list sudo apt update sudo apt install php8.0 php8.0-{fpm,mysql,curl,gd,mbstring,mysql,xml,mcrypt,zip,ldap} libapache2-mod-php8.0 -y
- CentOS 7
Run these commands to install PHP:sudo yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm sudo yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm sudo yum install -y yum-utils sudo yum-config-manager --enable remi-php80 sudo yum install php php-{fpm,mysql,curl,gd,mbstring,mysql,xml,mcrypt,zip,ldap} -y
- CentOS 8
Here we execute the following commands to install PHP:sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm sudo dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm sudo dnf module enable php:remi-8.0 -y sudo yum install php php-{fpm,mysql,curl,gd,mbstring,mysql,xml,mcrypt,zip,ldap} -y
How to enable the PHP-FPM module
- Ubuntu 20.04 and 18.04, Debian 10 and 9
Here we execute the following commands to install PHP-FPM:sudo a2enmod proxy_fcgi setenvif sudo a2enconf php8.0-fpm sudo a2dismod php8.0 sudo systemctl enable php8.0-fpm sudo service apache2 restart;sudo service php8.0-fpm restart
- CentOS 7
- First, update the Apache configuration to utilize mpm_event_module rather than mpm_prefork_module:
[centos@ip ~]# sudo vi /etc/httpd/conf.modules.d/00-mpm.conf # LoadModule mpm_prefork_module modules/mod_mpm_prefork.so LoadModule mpm_event_module modules/mod_mpm_event.so
- Then, backup the present PHP configuration file in Apache. Next, create a new configuration file with the following content:
sudo mv /etc/httpd/conf.d/php.conf /etc/httpd/conf.d/php.conf_bak sudo vi /etc/httpd/conf.d/php.conf
<Files “.user.ini”>
Require all denied
Order allow,deny
Deny from all
Satisfy AllSetHandler “proxy:fcgi://127.0.0.1:9000”
AddType text/html .php
DirectoryIndex index.php - Next, restart PHP-FPM and Apache for the changes to come into effect:
sudo systemctl restart php-fpm sudo systemctl restart httpd
- First, update the Apache configuration to utilize mpm_event_module rather than mpm_prefork_module:
- CentOS 8
- First, we will update the PHP=FPM configuration file in order for the service to listen to the port rather than the socket:
sudo sed 's#listen = /run/php-fpm/www.sock#listen = 127.0.0.1:9000#g' -i /etc/php-fpm.d/www.conf
- Next, create a new PHP configuration file after taking a backup of the file in Apache:
sudo mv /etc/httpd/conf.d/php.conf /etc/httpd/conf.d/php.conf_bak sudo vi /etc/httpd/conf.d/php.conf <Files ".user.ini"> Require all denied Order allow,deny Deny from all Satisfy All SetHandler "proxy:fcgi://127.0.0.1:9000" AddType text/html .php DirectoryIndex index.php
- Next, we will run the command seen below to permit the Apache to make outbound connections:
sudo /usr/sbin/setsebool -P httpd_can_network_connect 1
- Finally, restart PHP=FPM and Apache to allow the changes to take effect:
sudo systemctl restart php-fpm sudo systemctl restart httpd
- First, we will update the PHP=FPM configuration file in order for the service to listen to the port rather than the socket:
How to install MariaDB
We can opt to install MariaDB version 10.5 with the help of the MariaDB repository directly:
-
- First, we have to execute the following command and add the MariaDB yum repository:
curl -LsS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash -s -- --mariadb-server-version="mariadb-10.5"
- Then we have to install the MariaDB package:
For Ubuntu 20.04, Ubuntu 18.04, Debian 10, and Debian 9:
sudo apt install mariadb-server -y
For CentOS 8 and CentOS 7:
sudo yum install MariaDB-server MariaDB-client -y sudo systemctl start mariadb.service sudo systemctl enable mariadb.service
- Next, we execute the command below and complete the MariaDB secure installation, and set the root password:
sudo mysql_secure_installation
- After that, we have to set a password for the root account
- First, we have to execute the following command and add the MariaDB yum repository:
How to add permissions for your website’s folders to the default user
- Ubuntu 20.04 and 18.04
- First, we execute this command:
sudo usermod -a -G www-data ubuntu
- Then, we have to log out and log back in. This enables us to pick up the new group. After that, we have to verify the membership by running “group”:
sudo chown -R ubuntu:www-data /var/www sudo chmod 2775 /var/www find /var/www -type d -exec sudo chmod 2775 {} \; find /var/www -type f -exec sudo chmod 0664 {} \;
- First, we execute this command:
- Debian 10 and 9
- First, we execute this command:
sudo usermod -a -G www-data admin
- Then, we have to log out and log back in. This enables us to pick up the new group. After that, we have to verify the membership by running “group”:
sudo chown -R admin:www-data /var/www sudo chmod 2775 /var/www find /var/www -type d -exec sudo chmod 2775 {} \; find /var/www -type f -exec sudo chmod 0664 {} \;
- First, we execute this command:
- CentOS 8 and 7
- First, we execute this command:
sudo usermod -a -G www-data ubuntu
- Then, we have to log out and log back in. This enables us to pick up the new group. After that, we have to verify the membership by running “group”:
sudo chown -R ubuntu:www-data /var/www sudo chmod 2775 /var/www find /var/www -type d -exec sudo chmod 2775 {} \; find /var/www -type f -exec sudo chmod 0664 {} \;
- First, we execute this command:
[Looking for a solution to another query? We are just a click away.]
Conclusion
In brief, our skilled Support Engineers at Bobcares demonstrated how to install a LAMP stack manually on Lightsail instance.
PREVENT YOUR SERVER FROM CRASHING!
Never again lose customers to poor server speed! Let us help you.
Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.
0 Comments