Skip to content

Instantly share code, notes, and snippets.

@rajibbinalam
Created November 26, 2023 19:05
Show Gist options
  • Save rajibbinalam/3265bf0e9878daedf2ce36d0b8769fad to your computer and use it in GitHub Desktop.
Save rajibbinalam/3265bf0e9878daedf2ce36d0b8769fad to your computer and use it in GitHub Desktop.
Install LAMP (Linux, Apache, MySQL, PHP) stack On CentOS 7

Step 1 — Installing the Apache Web Server

sudo yum install httpd

sudo systemctl start httpd

to know your server’s public IP

ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'

type in your IP address into your web browser to verify that your server is running.

http://your_server_IP_address

This will show Testing 123.. (it's mean working good)

You can enable Apache to start on boot with:

sudo systemctl enable httpd.service

Step 2 — Installing MySQL (MariaDB)

sudo yum install mariadb-server
# Start
sudo systemctl start mariadb
# Enable
sudo systemctl enable mariadb.service
# Check
sudo systemctl status mariadb

log in to the MariaDB console

sudo mysql

#set user and password
GRANT ALL ON example_database.* TO 'root'@'localhost' IDENTIFIED BY '12345' WITH GRANT OPTION;

FLUSH PRIVILEGES;

exit

To access Database

mysql -u example_user -p

#show Databases
SHOW DATABASES;

Step 3 — Installing PHP

sudo yum install php php-mysql
#restart
sudo systemctl restart httpd.service
#Check
php -v

permit e user to root of cent OS

sudo chown -R sammy.sammy /var/www/html/ #sammy is exmple. user 

We can skip this and can do it manually

#Write this into the '/var/www/html/into.php'
<?php phpinfo(); ?>

#run on your browser
http://your_server_IP_address/info.php

#to Remove info.php
rm /var/www/html/info.php

Install Another PHP Version (7.4)

PHP 7.4 is available in the EPEL (Extra Packages for Enterprise Linux) repository. You need to enable it if it's not already enabled.

sudo yum install epel-release

The Remi repository provides more recent versions of PHP.

sudo yum install https://rpms.remirepo.net/enterprise/remi-release-7.rpm

Install

sudo yum install php74 || sudo yum install php81

#To see which versions of php are installed
rpm -qa | grep php

#restart the `Apache`
sudo systemctl restart httpd

if php version does not change

sudo alternatives --set php /usr/bin/php74

#if cann't access
sudo ln -sf /usr/bin/php74 /usr/bin/php
sudo ln -sf /usr/bin/php74 /usr/bin/php-cgi

Then Restart Apache and Check PHP version

After all of that, if you want to install PHP 8.1 Than just Repeat Install Another PHP Version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment