My Youtube Channel

Please Subscribe

Flag of Nepal

Built in OpenGL

Word Cloud in Python

With masked image

Showing posts with label centos. Show all posts
Showing posts with label centos. Show all posts

Thursday, February 1, 2024

Steps to install HTTPD, PHP, MYSQL and PHPMYADMIN in CentOS 8


Steps to install httpd in CentOS 8

  1. sudo yum install dnf
  2. sudo dnf update
  3. sudo dnf install httpd
  4. sudo systemctl start httpd
  5. sudo systemctl enablr httpd
  6. sudo systemctl enable httpd
  7. sudo firewall-cmd --add-service=http --permanent
  8. sudo firewall-cmd --reload
  9. sudo systemctl status httpd
  10. sudo dnf update

Steps to install PHP in CentOS 8

  1. sudo dnf update
  2. sudo dnf install epel-release
  3. sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
  4. sudo dnf module enable php:remi-8.2
  5. sudo dnf module reset php
  6. sudo dnf module enable php:remi-8.2
  7. sudo dnf module list php
  8. sudo dnf install php php-cli php-fpm php-mysqlnd php-pdo php-gd php-xml
  9. php -v
Steps to install MYSQL in CentOS 8

  1. sudo dnf update
  2. sudo dnf install https://dev.mysql.com/get/mysql80-community-release-el8-    3.noarch.rpm
  3. sudo dnf module enable mysql:8.0
  4. sudo dnf update
  5. sudo dnf install mysql-server
  6. sudo systemctl start php-fpm
  7. sudo systemctl enable php-fpm
  8. sudo systemctl restart httpd
  9. sudo systemctl start mysqld
  10. sudo systemctl enable mysqld
Steps to install phpmyadmin in CentOS 8

  1. Sudo dnf install epel-release
  2. sudo dnf update
  3. yum -y update
  4. yum -y install phpmyadmin
  5. dnf --enablerepo=remi install phpMyAdmin
  6. sudo vi /etc/httpd/conf.d/phpMyAdmin.conf
Make sure the phpMyAdmin.conf file looks similar to this:

Alias /phpMyAdmin /usr/share/phpMyAdmin

Alias /phpmyadmin /usr/share/phpMyAdmin

 

<Directory /usr/share/phpMyAdmin/>

   AddDefaultCharset UTF-8

   <IfModule mod_authz_core.c>

      # Apache 2.4

      <RequireAny>

         Require all granted

      </RequireAny>

   </IfModule>

   <IfModule !mod_authz_core.c>

      # Apache 2.2

      Order Deny,Allow

      Deny from All

      Allow from 127.0.0.1

      Allow from ::1

   </IfModule>

</Directory>

 

<Directory /usr/share/phpMyAdmin/setup/>

7. sudo systemctl restart httpd

8. You can verify the phpmyadmin installation by opening URL:

http://your_server_ip/phpMyAdmin

Alternative way to install phpmyadmin on CentOS 8

  1. sudo dnf update
  2. sudo dnf install tar
  3. sudo dnf install wget
  4. wget https://files.phpmyadmin.net/phpMyAdmin/5.1.3/phpMyAdmin-5.1.3-all-languages.tar.gz
  5. tar xzf phpMyAdmin-5.1.3-all-languages.tar.gz
  6. sudo mv phpMyAdmin-5.1.3-all-languages /usr/share/phpMyAdmin
  7. sudo mkdir /etc/phpMyAdmin
  8. sudo cp /usr/share/phpMyAdmin/config.sample.inc.php /etc/phpMyAdmin/config.inc.php
  9. sudo chmod 660 /etc/phpMyAdmin/config.inc.php
  10. sudo chown -R apache:apache /etc/phpMyAdmin
  11. sudo vi /etc/phpMyAdmin/config.inc.php
  12. add to config.inc.php,
                $cfg['blowfish_secret'] = 'a1b2c3d4e5f6g7h8i9j0';

13. sudo vi /etc/httpd/conf.d/phpMyAdmin.conf

Your phpMyAdmin.conf should be similar to given below,

Alias /phpMyAdmin /usr/share/phpMyAdmin

Alias /phpmyadmin /usr/share/phpMyAdmin

 

<Directory /usr/share/phpMyAdmin/>

   AddDefaultCharset UTF-8

   <IfModule mod_authz_core.c>

      # Apache 2.4

      <RequireAny>

         Require all granted

      </RequireAny>

   </IfModule>

   <IfModule !mod_authz_core.c>

      # Apache 2.2

      Order Deny,Allow

      Deny from All

      Allow from 127.0.0.1

      Allow from ::1

   </IfModule>

</Directory>

 

<Directory /usr/share/phpMyAdmin/setup/>

14. sudo systemctl restart httpd

 

Note: "vi" command used above is an editor. I hope you know how to use it.

To insert, press i

To exit without saving, press esc then :q! and then enter

To exit along with saving, press esc then :wq! then enter







Saturday, August 5, 2023

Differences between RPM-based and Debian-based Operating System with examples

 The main difference between RPM-based and Debian-based operating systems lies in the package management systems they use and the package formats they support. These differences influence how software is installed, managed, and updated on each type of system.


**RPM-based OS **:


1. **Package Format**: RPM (RPM Package Manager) is the package format used in RPM-based distributions. RPM packages have the extension `.rpm`. These packages contain the software along with its metadata and instructions for installation.


2. **Package Management System**: RPM-based distributions use package managers like `dnf` (Dandified YUM) or `yum` (Yellowdog Updater Modified) to handle the installation, removal, and management of software packages. These package managers resolve dependencies and download the required RPM packages from software repositories.


3. **Software Repositories**: RPM-based systems typically have centralized software repositories that contain a wide range of software packages. Users can add and enable different repositories to access additional software.


4. **Configuration Files**: RPM-based distributions store system configurations in the `/etc` directory. Configuration files usually have the `.conf` or `.cfg` extension.


**Examples of RPM-based OS**

1. Fedora: A community-driven distribution sponsored by Red Hat, known for its frequent releases and cutting-edge software.

2. CentOS: A community-supported distribution that aims to provide a free and open-source alternative to Red Hat Enterprise Linux (RHEL).

3. Red Hat Enterprise Linux (RHEL): A commercial distribution with long-term support, widely used in enterprise environments.

4. openSUSE: A community-developed distribution that focuses on ease of use and stability, available in two editions: Leap (stable) and Tumbleweed (rolling release).


**Debian-based OS **:


1. **Package Format**: Debian-based distributions use the DEB (Debian Package) format for software packages. DEB packages have the extension `.deb`. Like RPM packages, DEB packages contain software and metadata for installation.


2. **Package Management System**: Debian-based distributions use package managers like `apt` (Advanced Package Tool) or `dpkg` (Debian Package) to handle software installation and management. `apt` is the more user-friendly front-end for `dpkg`, which handles the low-level package operations.


3. **Software Repositories**: Debian-based systems also rely on centralized software repositories, which are typically signed and maintained by the distribution maintainers. Users can add and enable additional repositories as needed.


4. **Configuration Files**: Debian-based distributions store system configurations in the `/etc` directory, similar to RPM-based systems. Configuration files usually have the `.conf` or `.cfg` extension, just like RPM-based distributions.


Both RPM-based and Debian-based operating systems are widely used and have extensive software ecosystems. The choice between the two largely depends on personal preference, specific use case, and familiarity with the distribution's package management system and tools.


**Examples of Debian-based OS:**

1. Debian: One of the oldest and most well-established community-driven distributions, known for its stability and adherence to free software principles.

2. Ubuntu: Based on Debian, Ubuntu is one of the most popular desktop and server distributions, offering a user-friendly experience and long-term support.

3. Linux Mint: A user-friendly distribution built on top of Ubuntu, providing additional features, codecs, and a more polished desktop environment.

4. elementary OS: A visually appealing and beginner-friendly distribution designed for users transitioning from macOS or Windows.


Difference between dnf, yum and apt in linux based operating system

 `dnf`, `yum`, and `apt` are package managers used in different Linux distributions. Each one has its specific features and is associated with different distributions.


1. **dnf (Dandified YUM)**:

   - Used primarily in RPM-based distributions like Fedora, CentOS 8, RHEL 8, and other derivatives.

   - Provides a more modern and improved version of `yum`.

   - Faster and more efficient due to the use of libsolv library for dependency resolution.

   - Has a different command syntax compared to `yum`.

   - Introduced in Fedora 18 and became the default package manager in CentOS 8 and newer.


2. **yum (Yellowdog Updater Modified)**:

   - Used in RPM-based distributions like CentOS 7, RHEL 7, and older versions of Fedora.

   - An older package manager that served as the predecessor to `dnf`.

   - Slower and less efficient compared to `dnf`, especially in large repositories with complex dependencies.

   - Has a different set of commands and options compared to `dnf`.

   - Still available in CentOS 8 but not installed by default.


3. **apt (Advanced Package Tool)**:

   - Used primarily in Debian-based distributions like Debian, Ubuntu, and their derivatives (e.g., Linux Mint, elementary OS).

   - Uses the `.deb` package format instead of RPM.

   - Has a different set of commands and options compared to `dnf` and `yum`.

   - Uses `dpkg` as the underlying low-level package manager.

   - Generally regarded as easy to use and user-friendly.


While all three package managers serve the same purpose of installing, removing, and managing software packages on a Linux system, the main differences lie in the distribution they are associated with, the package formats they handle (RPM for `dnf` and `yum`, and `.deb` for `apt`), and the specific commands and options they offer. The choice of package manager depends on the Linux distribution being used. For instance, if you are using Fedora, CentOS 8, or RHEL 8, `dnf` would be the default and recommended package manager, while for Debian-based systems, `apt` is the standard choice.

Difference between 'dnf' and 'yum' in Centos

`dnf` (Dandified YUM) has become the default package manager in CentOS 8 and newer versions. Both `dnf` and `yum` are package managers used in CentOS and other RPM-based Linux distributions, but there are some differences between the two:


1. **Performance**: `dnf` is generally faster and more efficient than `yum`. It uses the libsolv library for dependency resolution, which is more powerful and faster than the `yum`-based resolver.


2. **Command syntax**: While both `dnf` and `yum` have similar command structures, some commands and options may differ slightly between the two. For example, `dnf` uses "group" instead of "groupinstall" and "module" instead of "module install".


3. **Dependencies and plugins**: `dnf` uses a plugin model that's different from `yum`. Some plugins may be available for one but not the other, or they might have different implementations.


4. **Transaction history**: `dnf` keeps its transaction history in SQLite format, while `yum` uses the simpler "yum history" command.


5. **Default behavior**: In CentOS 8 and later, `dnf` is the default package manager, and `yum` is still available but not installed by default. In earlier versions of CentOS, `yum` was the default.


6. **User experience**: `dnf` provides better feedback during the command execution and generally has more user-friendly output.


Keep in mind that since `dnf` has been adopted as the default package manager, it is recommended to use `dnf` in CentOS 8 and newer versions for compatibility and better performance. If you are using an older CentOS version that still uses `yum`, consider upgrading to a newer release to take advantage of `dnf`.

Various search operation options on Centos

Search for files or directories:

In CentOS 7, you can use various commands and tools to search for files or folders. Here are some common methods:


1. Using the `find` command:

The `find` command is a powerful tool to search for files and directories based on various criteria.

To search for a file named `filename.txt` starting from the root directory (/), open a terminal and run:


find / -name "filename.txt"

Replace `"filename.txt"` with the name of the file you're looking for.


To search for a directory named `dirname`, use the same command:

find / -type d -name "dirname"


2. Using the `locate` command:

The `locate` command utilizes a pre-built database of files for faster searching.

First, make sure the `mlocate` package is installed:

sudo yum install mlocate


Then, update the database:

sudo updatedb


Finally, search for a file or directory:

locate filename.txt

locate dirname

Note that `locate` provides faster results but might not show the most up-to-date information as it depends on the last database update.


3. Using `grep` command (for specific text within files):

If you are looking for files containing specific text, you can use the `grep` command. For example, to search for the word "example" within all files in the current directory and its subdirectories:

grep -r "example" .

The `.` represents the current directory. You can replace it with a specific directory path.


4. Using `whereis` command (for system binaries and manuals):

The `whereis` command is helpful for finding the binary and source files of a command or application.

For example, to find the location of the `ls` command:

whereis ls

These methods should help you search for files and folders efficiently on CentOS 7. Choose the appropriate method based on your requirements.


Search by filename extension:

To search for files by their extension in CentOS 7, you can use the `find` command along with the `-name` option and a wildcard to specify the file extension. Here's how you can do it:

Let's say you want to search for files with the extension `.txt` in the `/home/user/documents` directory:

find /home/user/documents -type f -name "*.txt"


Explanation:

- `find`: The command to search for files and directories.

- `/home/user/documents`: The starting directory for the search. Replace this with the directory where you want to begin the search. If you don't know the directory name or path just use '/' instead of full path like 

find / -type f -name "*.txt"

- `-type f`: Specifies that we are only interested in files (not directories).

- `-name "*.txt"`: The `-name` option allows us to specify a pattern to match filenames. Here, we use the wildcard `*` to match any characters before the `.txt` extension. This way, it will find all files with the `.txt` extension.


You can adjust the file extension and the directory path as needed to search for different file types in different locations. If you want to search for different file extensions, simply change `*.txt` to the desired extension (e.g., `*.pdf`, `*.jpg`, etc.).

Uninstall MariaDB completely along with its dependencies from the Centos

 To uninstall MariaDB on CentOS 8, you can use the `yum` package manager. Follow these steps to uninstall MariaDB:


1. **Stop the MariaDB service**:

   Before uninstalling, it's better to stop the MariaDB service to avoid any issues. Open a terminal and run the following command:

   sudo systemctl stop mariadb


2. **Remove the MariaDB packages**:

   Once the service is stopped, you can proceed to remove the MariaDB packages using `yum`:

   sudo yum remove mariadb-server mariadb-client


3. **Remove data and configuration files (optional)**:

   By default, the package manager may not remove the MariaDB data and configuration files. If you want to remove them as well, run the following commands:

   sudo rm -rf /var/lib/mysql

   sudo rm -rf /etc/my.cnf


   Please be cautious while running the `rm` command, as it permanently deletes the files and directories.


4. **Clean up dependencies (optional)**:

   You can also clean up any unused dependencies to free up disk space:

   sudo yum autoremove


That's it! MariaDB should now be uninstalled from your CentOS 8 system. Before performing these steps, make sure to back up any important databases to prevent data loss.

Install MariaDB on Centos

 To install MariaDB on CentOS 8, follow these steps:


1. Update the system packages:

   Before installing any software, it's a good idea to update your system to ensure you have the latest packages. Open a terminal or SSH into your CentOS 8 server and run the following commands:

   sudo dnf clean all

   sudo dnf update


2. Install MariaDB server:

CentOS 8 uses the DNF package manager, so you can easily install MariaDB by running the following command:

   sudo dnf install mariadb-server


3. Start and enable the MariaDB service:

   After the installation is complete, start the MariaDB service and enable it to start on boot using the following commands:

   sudo systemctl start mariadb

   sudo systemctl enable mariadb


4. Secure the MariaDB installation:

   By default, MariaDB is not configured with a root password, and it is recommended to set a root password for security. You can run the following command to secure your installation:

   sudo mysql_secure_installation

   This command will prompt you to set the root password, remove anonymous users, disallow root login remotely, and remove the test database. You can choose 'Y' or 'N' based on your preferences and requirements.


5. Verify the installation:

   To check if MariaDB is running and to verify its version, you can use the following command:

   sudo systemctl status mariadb

   mysql --version


That's it! MariaDB is now installed and running on your CentOS 8 system. You can interact with the database using the `mysql` command-line client or other tools like phpMyAdmin if you have a web server installed.

Solved: MariaDB failed to start with error message "job for mairadb.service failed because the control process exited with error code"

Here are some steps you can follow to resolve the issue:


1. **Check for Running Processes**: As the logs indicate, another process is already using port 3306. You can verify this by running the following command:

   sudo netstat -tulnp | grep 3306


 The command will show you the process ID (PID) of the process using port 3306. Make a note of the PID.

for example,

[root@Pinrecovery ~]# sudo netstat -tulnp | grep 3306

tcp6       0      0 :::3306                 :::*                    LISTEN      110920/mysqld


Here, the process id is: 110920


2. **Stop the Conflicting Process**: Once you identify the PID of the process using port 3306, you can stop it using the `kill` command. Replace `<PID>` with the actual PID you obtained in the previous step:

   sudo kill <PID>


3. **Start MariaDB**: After stopping the conflicting process, try starting the MariaDB service again:

   sudo systemctl start mariadb


4. **Check SELinux**: If you're still having issues with starting MariaDB, ensure that SELinux is not causing any problems. Temporarily disable SELinux to see if it resolves the issue:

   sudo setenforce 0

   However, keep in mind that disabling SELinux is not recommended for security reasons. If SELinux is causing the issue, you should investigate and configure SELinux policies appropriately.


5. **Verify Configuration**: Double-check your MariaDB configuration files (`/etc/my.cnf` or `/etc/mysql/my.cnf`) for any incorrect settings. Ensure that there are no duplicate configurations or conflicts with other services.


6. **Check Hardware/Software Issues**: If the problem persists, investigate for any potential hardware or software issues on your system that might be affecting MariaDB's ability to start.


After attempting the above steps, try starting the MariaDB service again. If the issue persists, review the error messages carefully to understand the root cause, and if needed, seek further assistance from the MariaDB community or forums.

Install oci8 on centos 8

 Install oci8 on centos 8

 

Now that you have the necessary tools and libraries installed, you can proceed with the next steps to install the OCI8 extension for PHP on CentOS 8:

 

1. Install the Oracle Instant Client:

   - Download the Oracle Instant Client RPM packages for your architecture from the Oracle website (https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html). You'll need  oracle-instantclient-basic ,  oracle-instantclient-devel and oracle-instantclient-sqlplus packages.

   - Transfer the downloaded RPM packages to your CentOS 8 system if you downloaded them on a different machine.

Note: for centos, it is better to download “.rpm” file rather than “.zip”

2. Install the Oracle Instant Client RPM packages:

Go to the directory where you downloaded the oracle instant-client files and install those files:

Let’s take example for version oracle instant-client 11.2,

sudo dnf install oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm  

sudo dnf install oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64

sudo dnf install oracle-instantclient11.2-sqlplus-11.2.0.4.0-1.x86_64

To verify whether the Oracle Instant Client "devel" package is installed on your CentOS system, you can use the package management tool rpm or dnf. Here's how you can check for the presence of the Oracle Instant Client devel package:

Using ‘rpm’:

rpm -qa | grep oracle-instantclient-devel

Using ‘dnf’:

dnf list installed | grep oracle-instantclient-devel

 

3. Verify the ORACLE_HOME environment variable:

echo $ORACLE_HOME

Ensure that the ORACLE_HOME environment variable is set correctly and points to the location where you installed the Oracle Instant Client. If it's not set correctly, you can set it as follows:

export ORACLE_HOME=/path/to/instant/client

During the installation process, you may be prompted to provide the path to the Oracle Instant Client library. If prompted, enter the correct path:

Enter the path: instantclient,/usr/lib/oracle/19.20/client64/lib

 

 

 

4. Set the environment variables required for OCI8 and PHP:

 

echo 'export ORACLE_HOME=/usr/lib/oracle/19.12/client64' | sudo tee -a /etc/profile.d/oracle.sh

echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/oracle/19.12/client64/lib' | sudo tee -a /etc/profile.d/oracle.sh

sudo ldconfig

Once you are done with above steps, the environment is set for oci8 installation, follow the bellows steps now,

5. Stop Apache and uninstall older version of OCI8 if any (stopping Apache is very important):

 service httpd stop

 pecl uninstall oci8

 

6. Install php-pear and php devel:

 sudo yum install php-pear php-devel

 pear download pecl/oci8

7. The next commands depend on the version of oci8 downloaded above.

$ tar xvzf oci8-2.2.0.tgz

$ cd oci8-2.2.0/

$ phpize

$ export PHP_DTRACE=yes

 

 

8. Make sure of the instantclient path below... mine was version 11.2 so it was located in this folder... Also make note some tutorials ask for the ORACLE_HOME folder which theoretically is /usr/lib/oracle/11.2/client64 but if its instantclient then put the lib folder underneath it (worked for me at least:)

$ ./configure --with-oci8=instantclient,/usr/lib/oracle/12.2/client64/lib/

$ make

$ make install

 

9. NOW an .so file built in: /usr/lib64/php/modules/oci8.so

10. check whether oci8 has been successfully installed or not:

php -m | grep oci8

11. sudo service httpd restart

The steps may not be needed in most of the cases. If indeed, it is required in your case go through these steps as well (though it is suggested to first try running before implementing the below steps):

# THIS STEP NOT NEEDED if SELinux disabled on your server/box, but if SELinux is enabled run: setsebool -P httpd_execmem 1

# NOW add:   extension=oci8.so    at the bottom of your php.ini file (probably in /etc/php.ini)

# Add extension_dir=/usr/lib64/php/modules/

Install Apache, PHP on Centos 8

 

Apache installation on centos 8

To install Apache on CentOS 8, you can use the `dnf` package manager, which is the replacement for `yum` in CentOS 8. Here's a step-by-step guide to installing Apache:

 

1. Open a terminal on your CentOS 8 system.

 

2. Update the package list to ensure you have the latest information about available packages:

sudo dnf update

 

3. Install Apache using the `dnf` package manager:

sudo dnf install httpd

 

4. After the installation is complete, start the Apache service:

sudo systemctl start httpd

 

5. Enable Apache to start on boot:

sudo systemctl enable httpd

 

6. Check the status of Apache to ensure it's running without any issues:

sudo systemctl status httpd

 

7. Adjust the firewall settings to allow incoming HTTP traffic:

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

sudo firewall-cmd --reload

 

Now, Apache should be installed and running on your CentOS 8 system. You can verify its functionality by opening a web browser and accessing your server's IP address or domain name. You should see the default Apache welcome page if everything is set up correctly.

 

PHP installation on centos 8

 

To install PHP on CentOS 8, you can use the `dnf` package manager. Additionally, you may want to install some commonly used PHP extensions to ensure the proper functioning of PHP-based applications. Here's a step-by-step guide to installing PHP:

 

1. Open a terminal on your CentOS 8 system.

 

2. Update the package list to ensure you have the latest information about available packages:

sudo dnf update

 

3. Install PHP and some commonly used extensions:

sudo dnf install php php-cli php-fpm php-mysqlnd php-pdo php-gd php-xml php-mbstring

 

The packages above include the basic PHP package (`php`), command-line interface (`php-cli`), PHP-FPM (FastCGI Process Manager) for serving PHP through a web server, MySQL support (`php-mysqlnd`), PDO (PHP Data Objects) for database connectivity (`php-pdo`), GD library for image manipulation (`php-gd`), XML support (`php-xml`), and multibyte string support (`php-mbstring`).

 

4. After the installation is complete, start and enable the PHP-FPM service:

sudo systemctl start php-fpm

sudo systemctl enable php-fpm

 

5. Check the status of PHP-FPM to ensure it's running without any issues:

sudo systemctl status php-fpm

 

6. Restart Apache: After making any changes to the Apache or PHP-FPM configuration, restart Apache to apply the changes:

sudo systemctl restart httpd

 

 

Now, PHP is installed and ready to be used on your CentOS 8 system. You can test your PHP installation by creating a PHP file with the following content:

 

<?php

   phpinfo();

?>

 

Save the file as `info.php` in your web server's document root directory (typically `/var/www/html/`):

 

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

 

Then, open a web browser and navigate to `http://your_server_ip/info.php` or `http://your_domain/info.php`. You should see a PHP information page displaying PHP version, configuration settings, and more. Remember to remove this `info.php` file after testing for security reasons.