Reading time: 2 mins
How to Install Linux Server for Php and MySql
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. 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 a Ubuntu 18.04 server.
Let’s assume you already have access to a server. So in order to access the server you will need to ssh into it.
If you are using a PEM KEY (Highly Recommended approach)
ssh -i “path to your key file” ubuntu@IP
sudo apt-get update
The command above tells the system to check if any packages that are available on the system have updates. It doesn’t actually upgrade the packages installed.
sudo apt install apache2
This installs the apache2 web server on your system.
This is the server that takes all the information your browser requests and sends it back to the browser.
It handles communication to other web-servers( proxy ) / Single tenant web-server or Multi Tenant (i.e. whether 2 domains example.com and example2.com point to the same server to show different sites respectively)
sudo service apache2 status
This command checks if your server is running proper.
Next we can move on to installing php
sudo apt -y install software-properties-common sudo add-apt-repository ppa:ondrej/php
You’re adding the php7.4 repository to your system. Now again we will update our package list
sudo apt-get update
Once done you can now setup php7.4
sudo apt -y install php7.4
The command above will check your installation. It should display your php version.
To see all modules. Now you will need modules depending on your requirements
You can install them by running
sudo apt install php7.4-X php7.4-XX
Where X and XX are your modules names you get after running php -m
Few basic ones are:
sudo apt install libapache2-mod-php7.4 php7.4-common php7.4-mbstring php7.4-xmlrpc php7.4-gd php7.4-xml php7.4-mysql php7.4-cli php7.4-zip php7.4-curl
You can install multiple php versions on your system and you can disable or enable them by running a2dismod X or a2ensite X
Let’s break this up for you
A2 dis mod X
Apache disable module module name
Try to figure out the other one using the pattern above.
Remember this pattern, you may need it in the future for other things like a2disconf or a2dissite (will explain it in another post)
Ok now let’s configure your PHP
sudo vim /etc/php/7.4/apache2/php.ini
Find these Variables and set them to your preference
memory_limit = 256
upload_max_filesize = 100M
max_execution_time = 360
date.timezone = Europe/London
Next we need to setup MYSQL
sudo apt install mysql-server mysql-client
Run this command after
This command will help you configure your default mysql user and other settings.
Connect to the database
sudo mysql -u root -p
Enter the password you entered in the previous step
Create your new user now
CREATE USER 'username'@'localhost' IDENTIFIED BY 'yourpassword'; GRANT ALL ON *.* TO 'username'@'localhost' IDENTIFIED BY 'yourpassword'; FLUSH PRIVILEGES; EXIT;
That’s it! You are all set to go to the /var/www/html/ folder using your SFTP/FTP client and set up your new website.
Read more blogs like these on Agaetis.tech