Tuesday, March 19, 2024

Install LAMP stack on Linux(Ubuntu OS, Zorin OS etc) for local development environment

Step 1:
---------------------
Install apache2 by below command:

sudo apt install apache2

Step 2:
---------------------
Install PHP 7.4:
First, need to enable/add a package for php 7.4 by below command:

sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install php7.4 php7.4-cli php7.4-common php7.4-json php7.4-opcache php7.4-mysql php7.4-mbstring php7.4-curl php7.4-xml

By the below command, you can change PHP version if you have multiple versions of PHP:

sudo update-alternatives --set php /usr/bin/php7.4

Restart apache server:

sudo systemctl restart apache2

Step 3:
---------------------
Install composer by below command:

sudo apt install composer

Step 4:
---------------------
Apache document root folder is: /var/www/html
No write permission to this html folder.
Run below command to change ownership of this html folder:

sudo chown -R $USER:$USER /var/www/html

Step 5:
---------------------
Add user to apache server by below command:

sudo nano /etc/apache2/apache2.conf

Need to change these below two lines with your linux user name:
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

To

User $USER
Group $USER

Save and restart apache service:

sudo service apache2 restart

Step 6:
---------------------
Install Mysql Database by below command:

sudo apt install mysql-server

Now secure Mysql by below command:

sudo mysql_secure_installation

N, Y, Y, Y, Y

Add Mysql root password permission:

sudo mysql
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your password';
FLUSH PRIVILEGES;
exit;

Step 7:
---------------------
Install phpmyadmin
Go to phpmyadmin.net and download zip to /var/www/html folder 
and unzip it and rename to phpmyadmin.
Then access phpmyadmin with this URL: http://localhost/phpmyadmin

You will get phpmyadmin login page.

Optional:
=======
Few important commands to switch PHP version:

sudo update-alternatives --config php
sudo a2dismod php8.1
sudo a2enmod php7.4
sudo service apache2 restart

Sometimes you may face 404 not found in all inner pages of your websites 
then follow below step to solve it:
Open /etc/apache2/apache2.conf by below command:

sudo gedit /etc/apache2/apache2.conf

then edit below line specially AllowOverride none to AllowOverride All:

<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

Then save and restart apache.

.:The End:.

Suomen kieli (Imperfekti)

In Finnish, the imperfekti is the past tense that describes actions that happened in the past, like the English simple past (e.g., "I ...