Kamis, 05 November 2020

How To Install LAMP centos 7, PhpMyadmin, PHP 7.3 on CentOS 7

Step 1: Update Package Repository Cache

Before you start building the stack, be sure to update the packages on your CentOS 7 server using the command:

sudo yum update

Step 2: Install the Apache Web Server

As you already have a CentOS operating system running, the first step of assembling the LAMP stack is to install the web server. The simplest way to install Apache is through CentOS’s native package manager, yum.

1. Install Apache on Centos with:

sudo yum install httpd

When prompted, confirm that you are executing the command with sudo privileges.

The output will show the package httpd package was installed as in the image below:

CentOS running output httpd packages

2. Next, start Apache by running the following command:

sudo systemctl start httpd.service

3. Check whether the service is running by going to your server’s public IP address. The browser should display the test CentOS 7 Apache web page:

apache http welcome page

4. Finally, set up Apache to start at boot:

sudo systemctl enable httpd.service

Step 3: Install MySQL (MariaDB) and Create a Database

To organize and store data for your dynamic website, you need MariaDB. This is an open-source fork of the MySQL database management system. It is a backward compatible and binary drop-in replacement for the original MySQL.

1. Install MariaDB with the command:

sudo yum install mariadb-server mariadb

When a y/n prompt appears, confirm with y.

2. Now start MariaDB using the command:

sudo systemctl start mariadb

Step 4: Run MySQL Security Script

MariaDB does not have secure settings by default. Therefore, you need to configure settings, test the database, and remove anonymous users.

1. Begin by typing the command:

sudo mysql_secure_installation

2. You will be prompted to provide your MariaDB root password (this is not the root password for your server). As you do not have a password yet, pressing Enter allows you to continue configuration.

4. Next, it will ask you a series of queries. To ensure your database is protected, answer the questions as follows:

  • Set root password? [y/n] Y
  • New password: Type in a password you would like to use
  • Re-enter new password: Retype the password from the previous field
  • Remove anonymous users? [y/n] Y
  • Disallow root login remotely? [y/n] Y
  • Remove test database and access to it? [y/n] Y
  • Reload privilege tables now? [y/n] Y

5. After answering the questions, the output will display a message that your system is cleaning up, and the installation should now be secure.

mysql successful installation cleaning up

Lastly, enable MariaDB to start up when you boot the system:

sudo systemctl enable mariadb.service

Step 5: Install PHP

As a server-side scripting language, PHP is the part of the LAMP grouping that processes the code for showing dynamic content. Once it is connected with the MySQL database, PHP will be retrieving information and processing it for the Apache webserver to display.

1. Install the MySQL extension along with PHP, again using the yum package installer, with the command:

sudo yum install php php-mysql

Now you should get a Y/n prompt allowing you to confirm the installation, by entering Y.

2. To have your Apache webserver start co-working with PHP, restart the server:

sudo systemctl restart httpd.service 

Step 6: Test PHP Processing

To locate and serve the website, Apache must save the file to the web root. Apache places its default website in this directory: /var/www/html/

By using the nano editor, you can go into this directory and run a test of PHP on the CentOs 7 server.

1. To install the editor, use this command:

sudo yum install nano

2. Use a basic PHP script to make an info.php file, with the command:

sudo nano /var/www/html/info.php

3. This opens a blank text file in which you should copy and paste the following:

<?php

phpinfo ();

?>

4. Hold CTRL+X (to exit) and Y and Enter (to save changes, and close the file).

5. Check whether PHP is working by visiting the following URL:

http://ip_address/info.php

The ip_address should be the public IP address of your server. If PHP is set up correctly you will see this image on the browser:

php running version 5.4

6. If a firewall is enabled you will need to open a route for HTTP traffic. Use the command:

sudo firewall-cmd --permanent --zone=public --add-service=http

Following with the command to open it for HTTPS traffic:

sudo firewall-cmd --permanent --zone=public --add-service=https

Finally, restart the firewall to enable the new settings:

sudo firewall-cmd --reload

Step 7: Install PHP Modules

To optimize PHP’s capabilities, look at the names and descriptions of optional modules with the command:

yum search php-

To get detailed, plain-language information about what each module does, view a longer description with: yum info followed by a space and the module name.

Install an optional package with sudo yum install followed by a space and the module name.

Step 8: Restart Apache

In order for the changes to take effect, restart the Apache service with the command:

sudo systemctl restart apache2


INSTALL PHP 7.3

Step 1: Add PHP 7.3 Remi repository

PHP 7.3 is available for CentOS 7 and Fedora distributions from the Remi repository. Add it to your system by running

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

Step 2: Disable repo for PHP 5.4

By default, the enabled repository is for PHP 5.4. Disable this repo and enable on for PHP 7.3

sudo yum-config-manager --disable remi-php54
sudo yum-config-manager --enable remi-php73

Step 3: Install PHP 7.3 on CentOS 7 / Fedora

Once the repo has been enabled, install php 7.3 on CentOS 7 or Fedora using the command

sudo yum -y install php php-cli php-fpm php-mysqlnd php-zip php-devel php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-json

Check version installed

$ php -v
PHP 7.3.1 (cli) (built: Jan 8 2019 13:55:51) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.1, Copyright (c) 1998-2018 Zend Technologies

I will update this guide once the final release of PHP 7.3 is available for production use.

Step 4: Installing other PHP 7.3 Extensions

Install PHP 7.3 extensions by using the syntax

sudo yum install php-<entension-name>

As an example, to install a mysql module for PHP applications that use MySQL databases, you’ll run:

sudo yum install php-mysql

This will only work if the default repository for PHP packages is 7.3

sudo yum install php-mysqlnd

Confirm:

# rpm -qi php-mysqlnd
Name : php-mysqlnd
Version : 7.3.1
Release : 1.el7.remi
Architecture: x86_64
Install Date: Thu 10 Jan 2019 06:56:47 PM UTC
Group : Development/Languages
Size : 856852
License : PHP
Signature : DSA/SHA1, Tue 08 Jan 2019 06:44:21 PM UTC, Key ID 004e6f4700f97f56
Source RPM : php-7.3.1-1.el7.remi.src.rpm
Build Date : Tue 08 Jan 2019 06:24:34 PM UTC
Build Host : builder.remirepo.net
Relocations : (not relocatable)
Packager : https://blog.remirepo.net/
Vendor : Remi Collet
URL : http://www.php.net/
Bug URL : https://forum.remirepo.net/
Summary : A module for PHP applications that use MySQL databases
Description :
The php-mysqlnd package contains a dynamic shared object that will add
MySQL database support to PHP. MySQL is an object-relational database
management system. PHP is an HTML-embeddable scripting language. If
you need MySQL support for PHP applications, you will need to install
this package and the php package.
This package use the MySQL Native Driver

Enjoy using PHP 7.3 and feel free to report any bugs you encounter to the development team.


Installing phpMyAdmin on CentOS 7

To install PHPMyAdmin on CentOS, enter the command:

sudo yum -y install phpmyadmin

Once the system executes the command, PHPMyAdmin is installed and ready to launch.

Step 4: Configuring and Securing phpMyAdmin

Your new software installation includes a default Apache configuration file. You’ll want to make some changes to that configuration to prevent unauthorized access. Here are two common ways of restricting access to unauthorized users.

Restrict IP Addresses

This method can be used to grant remote access to a single workstation. By default, phpMyAdmin is configured so that the server it’s installed on has access. This change lets you allow or restrict access to specific IP addresses of different or additional computers.

The file is located at /etc/httpd/conf.d/phpMyAdmin.conf. Type the following at your command prompt:

sudo vim /etc/phpMyAdmin/config.inc.php

Inside the config file, you should see four (4) lines that refer to “Require IP” or “Allow IP.”  By default, they should be set to 127.0.0.1, which is the IP address referring to the system you are working on. To allow other systems to access this phpMyAdmin application, add (or change) these numbers to the IP address of the computer you want to grant access to.

Once you’ve made the changes, save the file.

Change Alias

Open phpMyAdmin.conf using a text editor:

sudo vim /etc/phpMyAdmin/config.inc.php

Near the top, you should see two lines:

Alias /phpMyAdmin /usr/share/phpMyAdmin
Alias /phpmyadmin /usr/share/phpMyAdmin

“Alias” is how the internet will see your phpMyAdmin configuration. Since the default configuration is an easy target for bots and hackers, consider changing the alias setting. Just put a ‘#’ sign before the existing entries so the program sees them as comments, rather than instructions. Then add your own line:

Alias /MySecretLogin /usr/share/phpMyAdmin

Now, when you go to your login screen, you’ll have to type https://IP_OR_DOMAIN/MySecretLogin (or whatever you choose) to gain access.

Once you’re finished making changes, save the file.

Step 5: Restart Apache

Regardless of which configuration you use, you’ll need to restart the Apache service to see your changes:

sudo systemctl restart httpd.service

Step 6: Verify phpMyAdmin is Working

To check if phpMyAdmin is working correctly, enter your servers IP and /phpmyadmin in a web browser. For example:

125.0.0.2/phpmyadmin

You should see the PhpMyAdmin login screen.


NOTED :

VIM /etc/httpd/conf.d/phpmyadmin.conf file is:

<Directory "/usr/share/phpmyadmin">
   Order Deny,Allow
#   Deny from all
   Allow from 127.0.0.1
</Directory>
Sumber : 
https://phoenixnap.com/kb/how-to-install-lamp-stack-on-centos
https://stackoverflow.com/questions/31853477/centos-7-phpmyadmin-403-forbidden
https://computingforgeeks.com/how-to-install-php-7-3-on-centos-7-fedora/