LAMP – Linux Hint https://linuxhint.com Exploring and Master Linux Ecosystem Mon, 01 Feb 2021 00:55:07 +0000 en-US hourly 1 https://wordpress.org/?v=5.6.2 Set up LAMP(Linux, Apache, MySQL, PHP) Stack on Ubuntu 20.04 https://linuxhint.com/install-lamp-stack-ubuntu/ Thu, 28 Jan 2021 15:45:37 +0000 https://linuxhint.com/?p=87968

You might have just started building your dynamic web application in PHP, and you want to set up the LAMP Stack. LAMP term comes from the Linux Operating System, Apache server, MySQL database, and PHP language. Let’s get started with the installation of LAMP Stack on Ubuntu 20.04.

First of all, you should have sudo privileges on your system or log in as a root to perform the following tasks:

Update the System’s Package Repository

To get started with all the installation, it is the best practice to update the APT cache repository first so that all the latest applications can be installed smoothly.

$ sudo apt update


Once the apt-cache is updated, we are ready to move forward with the LAMP Stack installation.

Let’s first install MySQL.

Install MySQL on Ubuntu 20.04

Since MySQL is mostly used as a database with PHP and used to manage and store data to install MySQL on your ubuntu system, type the command given below.

$ sudo apt install mysql-server mysql-client


It will ask you to take additional disk space for the package to install, so press “y” to continue installing MySQL.


Once MySQL is installed, check the version by typing this command.

$ mysql --version


And to check that MySQL’s service is running or not on your ubuntu system, type this command to check the status.

$ sudo systemctl status mysql.service


If it is not active, you can start it by using the start keyword in the above command like this

$ sudo systemctl start mysql.service


To login to the MySQL’s shell, type the following command

$ sudo mysql


It won’t ask you for any password for the first time.

Once you log in to MySQL’s shell, you can set up your password or perform any function related to the database in it.

Now let’s exit through it and install the Apache 2 web server on the Ubuntu system.

mysql> exit

Install Apache Web Server on Ubuntu 20.04

Apache 2 is a web server that handles the servers for hosting web applications. To install Apache 2 on your ubuntu system, run this command.

$ sudo apt install apache2


It may also prompt for taking a grant of additional disk space for the Apache’s installation, so press “y” to continue the installation process.

Once, Apache 2 web server is installed as well; you can check the status by typing the following command.

$ sudo systemctl status apache2


If it is active and running, then you are good to go with the installation of PHP; otherwise, start using the command

$ sudo systemctl start apache2


After starting it, let’s install the PHP now,

Install PHP on Ubuntu 20.04

PHP’s latest stable version can easily be installed on ubuntu from the APT package repository by typing the command given below in the terminal

$ sudo apt install php


Press “y” to continue the process if it prompts for taking additional disk space for installing PHP.

After the successful installation of PHP, you can check the version by typing the command

 $ php --version


PHP version 7.3.4 is installed.

Install PHP Extensions

Now if you want to install some other basic PHP extension as well, which are required for the phpMyAdmin, For example,

  • php-curl
  • php-gd
  • php-mbstring
  • php-mysql
  • php-zip
  • php-json
  • php-xml

You can do so by typing the following command.

$ sudo apt install php-curl php-gd php-mbstring php-mysql php-zip php-json php-xml


Allow it to take additional disk space for the extensions to install by typing “y” and hitting the “Enter” button.


This command will install all the required PHP extensions for running the phpMyAdmin.

So this is how you can install all the required packages on Ubuntu 20.04 and set up the LAMP Stack for building your dynamic web application.

Conclusion

This post contains the step by step guide to install and set up the LAMP stack on Ubuntu 20.04 LTS.

]]>
Configure a LAMP Server on CentOS 8 for PHP Web Development https://linuxhint.com/lamp_server_centos8_php_web/ Mon, 30 Dec 2019 04:13:45 +0000 https://linuxhint.com/?p=52710 In this article, I am going to show you how to configure CentOS 8 as a LAMP (Linux, Apache,  MariaDB/MySQL, PHP) server for PHP web development. So, let’s get started.

Updating CentOS 8 Package Repository Cache:

First, update the CentOS 8 package repository cache with the following command:

$ sudo dnf makecache

Installing and Configuring MySQL/MariaDB:

I am going to show you how to configure the database first.

To install MariaDB database client tools and server, run the following command:

$ sudo dnf install mariadb mariadb-server

To confirm the installation, press Y and then press <Enter>.

MariaDB database server and client programs should be installed.

Now, check the status of the mariadb service as follows:

$ sudo systemctl status mariadb

It may be inactive (not running) and disabled (won’t automatically start on system boot) as shown in the screenshot below.

Start mariadb service with the following command:

$ sudo systemctl start mariadb

mariadb service should be active.

$ sudo systemctl status mariadb

Now, add mariadb service to the system startup as follows:

$ sudo systemctl enable mariadb

Now, you should set up a MariaDB root password. To do that, run the following command:

$ sudo mysql_secure_installation

Press <Enter>.

Press <Enter>.

Now, type in a new root password and press <Enter>.

Type in the root password again and press <Enter>.

Press Y and then press <Enter>.

Press Y and then press <Enter>.

Press Y and then press <Enter>.

Press Y and then press <Enter>.

MariaDB root password should be set.

Now, login to the MariaDB shell as root user as follows:

$ sudo mysql -u root -p

Type in the root password and press <Enter>.

You should be logged in.

Now, create a new MariaDB user as follows:

> GRANT ALL ON *.* TO '<username>'@'localhost' IDENTIFIED BY '<password>'

Make sure to replace <username> and <password> with your own username and password.

Now, run the following SQL statement for the changes to take effect.

> FLUSH PRIVILEGES;

Now, exit out of the MariaDB database as follows:

> exit

Installing and Configuring Apache Web Server and PHP:

Now, run the following command to install Apache web server and PHP:

$ sudo dnf install httpd httpd-tools php php-cli php-json php-gd php-mbstring php-pdo
 php-xml php-mysqlnd

To confirm the installation, press Y and then press <Enter>.

Apache web server and PHP should be installed.

Now, check the status of the httpd server as follows:

$ sudo systemctl status httpd

It may be inactive (not running) and disabled (won’t auto start on system boot) by default.

Start httpd service as follows:

$ sudo systemctl start httpd

The httpd service should be active.

$ sudo systemctl status httpd

Now, add the httpd service to the system startup as follows:

$ sudo systemctl enable httpd

The main configuration file of Apache web server is /etc/httpd/conf/httpd.conf

Custom configuration files should be put in the /etc/httpd/conf.d/ directory.

The default webroot directory is /var/www/html

Now, to test whether Apache web server and PHP is working, create a new PHP script index.php in the default webroot directory /var/www/html as follows:

$ echo '<?php phpinfo(); ?>' | sudo tee /var/www/html/index.php

Now, open a web browser and try to access http://localhost

You should see the phpinfo page as shown in the screenshot below. So, Apache and PHP are working correctly.

Letting Apache Web Server to Write to Web Root:

By default, the Apache web server can only read from the default web root directory /var/www/html

If your application needs to write to the directory, it must be owned by the apache user and group.

To change the user and group of the Apache web root directory /var/www/html to apache, run the following command:

$ sudo chown -Rf apache:apache /var/www/html

On CentOS 8, you also have to configure SELinux to allow write to the webroot directory /var/www/html.

You can configure SELinux for the /var/www/html directory and its contents with the following command:

$ sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html(/.*)?"

For the SELinux changes to take effect, run the following command:

$ sudo restorecon -Rv /var/www/html

Making Web Development Easier:

When you’re developing a website, you would want to make changes to the /var/www/html directory as your login user.

To make this easier, create a symbolic link of the /var/www/html directory in your user’s home directory as follows:

$ ln -s /var/www/html ~/public_html

Also, give everyone read, write and execute permission to the directory /var/www/html as follows:

$ sudo chmod -R 777 /var/www/html

Now, you should be able to access /var/www/html directory as ~/public_html from your user’s home directory and make changes to the files and directories there as required.

When you’re done developing your website, you can secure the web root directory /var/www/html again as follows:

$ sudo chmod -R 660 /var/www/html

So, that’s how you configure a LAMP server on CentOS 8 for PHP web development. Thanks for reading this article.

]]>