Install LAMP stack on Debian

LAMP stack is used for hosting Websites and Apps. LAMP stack is a set of packages such as Linux, Apache, MySQL, and PHP. In this tutorial, you are going to learn How to install LAMP stack on Debian.

Prerequisites

Before you start to install LAMP stack on Debian 9. You must have the non-root user account on your server/desktop with sudo privileges.

1. Install Apache

Update the apt package manager index by running following command

sudo apt update

Now install Apache web server by typing following command

sudo apt install apache2

Confirm the installation of Apache by using the following command

sudo systemctl status apache2

If you have UFW firewall enabled then you should open port 80 for HTTP and 443 for HTTPS to Apache Web Server. Enter the following commands to enable ports.

sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw reload

Now you can verify your Apache installation by visiting http://YOUR_DOMAIN_NAME/ or http://localhost/

2. Install MariaDB

Update apt package manager index by typing following command

sudo apt update

Now you can install MariaDB by running following command

sudo apt install mariadb-server mariadb-client

Check the status and confirm installation by typing following command

sudo systemctl status apache2

To secure MariaDB run following command.

sudo mysql_secure_installation

Once you execute above command you will be asked to enter current password (Press ENTER for none) then you will be asked following questions, enter y for following questions:

  • Set root password? : y
  • Remove anonymous users? : y
  • Disallow root login remotely? : y
  • Remove test database and access to it? : y
  • Reload privilege tables now? : y

3. Install PHP

To install PHP you should first update package manager index. Update apt package manager index by typing

sudo apt update

Install PHP and some of its common extensions by typing

sudo apt install php php-common php-mysql php-gd php-cli

After installing PHP you can confirm installtion by creating info.php file. Run following command to create info.php file.

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php

Now visit http://YOUR_DOMAIN_NAME/info.php or http://localhost/info.php in your browser to confirm installation.

Conclusion

You have successfully learned how to install LAMP stack on Debian 9. If you have any queries regarding this please don’t forget to comment below.

Install LAMP stack on CentOS

LAMP stack stands for the set of packages such as Linux, Apache, MySQL, and PHP. LAMP stack is widely used for hosting Websites and Apps. In this tutorial, you are going to learn How to install LAMP stack on CentOS.

Prerequisites

Before you start to install LAMP stack on CentOS 7. You must have the non-root user account on your server with sudo privileges.

1. Install Apache

In CentOS and RHEL Apache service is known as httpd. As Apache repository is available if CentOS core repositories, installation is pretty easy.

To install Apache on CentOS enter following command

sudo yum install httpd

Once You install Apache start and enable service by typing following in terminal.

sudo systemctl start httpd
sudo systemctl enable httpd

Confirm the status of Apache service by running following command

sudo systemctl status httpd

Enter CTRL+c to exit.

2. Install MariaDB

Now you are going to install MariaDB on your server. To install type following:

sudo yum install mariadb-server

After installing MariaDB you should start and enable MariaDB service by running the following command.

sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service

Check the status of MariaDB service by typing

sudo systemctl status mariadb.service

The Installer generates the temporary password for MariaDb and saves it inside a file to check the password inside file enter following command

grep "A temporary password" /var/log/mysqld.log  | tail -n1

[Some text hidden] A temporary password is generated for [email protected]: Eif;=GPCD88#

To secure MariaDB run following command.

sudo mysql_secure_installation

Once you execute above command you will be asked to enter current password (Press ENTER for none) then you will be asked following questions, enter y for following questions:

  • Set root password? : y
  • Remove anonymous users? : y
  • Disallow root login remotely? : y
  • Remove test database and access to it? : y
  • Reload privilege tables now? : y

Enter CTRL+c to exit

3. Install PHP

CentOS does not ship with PHP 7.2 in its core repositories. Here we are going to use the Remi repository to install PHP 7.2.

Enter the following command to add Remi repository on CentOS

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

Now you should enable remi-php72 repository, to do so type:

sudo yum install yum-utils
sudo yum-config-manager --enable remi-php72

Install PHP and some of its required extensions by typing

sudo yum install php php-common php-gd php-curl php-mysql

Now restart Apache by using the following command

sudo systemctl restart httpd

Test PHP

Now you should create info.php file to test php to do so type following.

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php

Now visit http://YOUR_DOMAIN_NAME_OR_IP_ADDRESS/info.php or http://localhost/info.php in your browser.

Conclusion

You have successfully learned to install LAMP stack on CentOS 7. If you have any queries regarding this please don’t forget to comment below.

Install LAMP stack on Ubuntu

LAMP stack is a set of packages such as Linux, Apache, MySQL, and PHP. LAMP stack is used for hosting Websites and Apps. In this tutorial, you are going to learn How to install LAMP stack on Ubuntu.

Prerequisites

Before you start to install LAMP stack on Ubuntu 18.04. You must have the non-root user account on your server/desktop with sudo privileges.

1. Install Apache

First, you will need to update the package manager index by typing

sudo apt update

Now install Apache by running following command

sudo apt install apache2

Confirm the installation of Apache by using the following command

sudo systemctl status apache2

If you have UFW firewall enabled then you should open port 80 for HTTP and 443 for HTTPS to Apache Web Server. Enter the following commands to enable ports.

sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw reload

Now you can verify your Apache installation by visiting http://YOUR_DOMAIN_NAME/ or http://localhost/

2. Install MariaDB

Update apt package manager index by typing following command

sudo apt update

Now you can install MariaDB by running following command

sudo apt install mariadb-server mariadb-client

Check the status and confirm installation by typing following command

sudo systemctl status apache2

To secure MariaDB run following command.

sudo mysql_secure_installation

Once you execute above command you will be asked to enter current password (Press ENTER for none) then you will be asked following questions, enter y for following questions:

  • Set root password? : y
  • Remove anonymous users? : y
  • Disallow root login remotely? : y
  • Remove test database and access to it? : y
  • Reload privilege tables now? : y

3. Install PHP

To install PHP you should first update package manager index then you will install PHP.

Update apt package manager index by typing

sudo apt update

Install PHP and some of its common extensions by typing

sudo apt install php php-common php-mysql php-gd php-cli

After installing PHP you can confirm installtion by creating info.php file. Run following command to create info.php file.

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php

Now visit http://YOUR_DOMAIN_NAME/info.php or http://localhost/info.php in your browser to confirm installtion.

Conclusion

You have successfully learned how to install LAMP stack on Ubuntu 18.04. If you have any queries regarding this please don’t forget to comment below.

Install PHP 7.2 on CentOS 7

PHP is the server-side scripting language used for web development. PHP has different versions 5.6, 7.0, 7.1 and 7.2 etc. Currently, PHP 7.2 is the latest version of PHP. CentOS 7 official repository supports PHP 5.4 which will no longer receive any updates. To get the latest security updates and features you need to migrate to PHP 7.2. In this tutorial you will learn how to install PHP 7.2 on CentOS.

Prerequisites

Before you start installing PHP 7.2 on CentOS 7. You must have the non-root user account on your server with sudo privileges.

1. Installing PHP on CentOS

As PHP 7.2 is not available in CentOS global repository. You will need to add it manually.

Start software update by typing following command.

yum update
To Enable PHP 7.2 in CentsOS repository enter following text in terminal.
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
If you have not installed ==yum-utils== enter following command.
yum install yum-utils

Now enable Remi Repositories for PHP 7.2 entering following command.

yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
    yum-config-manager --enable remi-php72

Install PHP 7.2 by typing the following text.

yum install php72

Confirm installation of PHP 7.2.

php72 -v

Output should be:

# php72 -v
    PHP 7.2.10 (cli) (built: Oct 22 2018 02:02:51) ( NTS )
    Copyright (c) 1997-2018 The PHP Group
    Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.10, Copyright (c) 1999-2018, by Zend Technologies

Create a symbolic link to ==user/bin/php==

ln -s /usr/bin/php72 /usr/bin/php

Now check the version by typing.

php -v

4. Install PHP Extensions

You will need to install some basic PHP extensions to run WordPress, Ghost etc. frameworks on the server. To install any of the PHP extensions on the server following is the basic format

yum install php72-php-[name_of_the_extension]

You can install curl extension for PHP by running following command.

yum install php72-php-curl

Following are some basic PHP extensions needs to be installed on your server.

yum install php72 php72-php-fpm php72-php-mysqlnd php72-php-opcache php72-php-xml php72-php-xmlrpc php72-php-gd php72-php-mbstring php72-php-json

To install more extensions you can use the given format.

5. Testing PHP processing

To test PHP is configured on your server properly or not you should create a file test.php inside directory var/www/html/ with following code.

<?php
    phpinfo();

If you see the following output at https:// YOUR DOMAIN NAME /test.php or https:// IP ADDRESS /test.php then you have installed PHP successfully.

Conclusion

You have successfully learned how to install PHP 7.2 on CentOS 7 with some of its basic extensions and tested. If you have any of the queries regarding this then don’t forget to comment below.

Install PHP 7.2 on Debian 9

PHP has different versions 5.6, 7.0, 7.1 and 7.2. Currently, PHP 7.2 is the latest version of it. PHP 7.2 offers much better performance and faster request processing and some security updates. Debian 9 ships with PHP 7.0 which will no longer receive security updates so you should migrate from PHP 7.0 to PHP 7.2. In this tutorial you will learn install PHP 7.2 on Debian 9.

Prerequisites

Before you start to install PHP on Debian 9. You must have the non-root user account on your server with sudo privileges

1. Installing PHP on Debian

To install PHP 7.2 on Debian 9, First, you will need to install some missing packages so you can add new repository over HTTPS. Then you will add GPG keys after you will install PHP.

Update the package manager index by typing following in the terminal

sudo apt update

Now add missing package so you can add new repository over HTTPS.

sudo apt install ca-certificates apt-transport-https

Import signing key and enable PPA for PHP 7.2 by using the following command.

curl -fsSL https://packages.sury.org/php/apt.gpg | sudo apt-key add -
sudo add-apt-repository "deb https://packages.sury.org/php/ $(lsb_release -cs) main"

Now update the package manager index again and install PHP 7.2 in Ubuntu.

sudo apt update
sudo apt install php7.2

Confirm the installation and check the version of PHP by typing:

php -v

2. Setup PHP for Nginx

Nginx by default does not support native PHP processing. You will need to install “fastCGI process manager”. Run following command to install php-fpm on your server.

sudo apt install php-fpm

You can check the status where it is correctly installed or not by the following command

systemctl status php7.2-fpm

After installing the php-fpm package you will need to restart Nginx server. To restart Nginx server run following command

sudo systemctl restart nginx

you can check PHP version by running following command

php -v

3. Installing PHP With Apache

If you are running Apache at backend then you need to install PHP and Apache PHP module on the server. To install PHP 7.2 and apache module type following command and press enter.

sudo apt install php libapache2-mod-php

After installing PHP and apache-php module you will need to restart Apache server by typing following command.

sudo systemctl restart apache2

4. Install PHP Extensions

You will need to install some basic PHP extensions to run WordPress, Laravel like frameworks on the server. To install any of the PHP extensions on the server following is the basic format

sudo apt install php-[name_of_the_extension]

You can install curl extension for PHP by running following command.

sudo apt install php-curl

Following are some basic PHP extensions needs to be installed on your server.

sudo apt install php7.2-curl php7.2-mysql php7.2-common php7.2-cli php7.2-gd php7.2-opcache php7.2-mcrypt

To install more extensions you can use the above format.

5. Testing PHP processing

To test PHP is configured on your server properly or not you should create a file test.php inside directory /var/www/html/ with following code.

/var/www/html/test.php
<?php
    phpinfo();

If you see the following output at https://YOUR_DOMAIN_NAME/test.php then you have installed PHP successfully.

Conclusion

You have installed PHP 7.2 on Debian 9 successfully with some of its basic extensions and tested successfully. If you have any of the queries regarding this then don’t forget to comment below.