My Youtube Channel

Please Subscribe

Flag of Nepal

Built in OpenGL

Word Cloud in Python

With masked image

Showing posts with label php. Show all posts
Showing posts with label php. 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

Will "mysqli" extension work for MariaDB database?

Yes, `mysqli` can work with MariaDB in PHP. The `mysqli` extension stands for "MySQL Improved" and is designed to work with both MySQL and MariaDB databases. MariaDB is a fork of MySQL, so they share a lot of similarities and are largely compatible with each other.

When you use the `mysqli` extension in PHP, you can connect to both MySQL and MariaDB databases using the same functions and methods. This is because the `mysqli` extension provides an improved and more feature-rich API for accessing MySQL and MariaDB databases in PHP.

Here's a simple example of connecting to a MariaDB database using `mysqli` in PHP:


<?php

$servername = "localhost";

$username = "your_username";

$password = "your_password";

$dbname = "your_database";


// Create connection

$conn = new mysqli($servername, $username, $password, $dbname);


// Check connection

if ($conn->connect_error) {

    die("Connection failed: " . $conn->connect_error);

}


echo "Connected successfully";


// Close connection

$conn->close();

?>


Remember to replace `your_username`, `your_password`, and `your_database` with your actual database credentials.

So, whether you are working with MySQL or MariaDB, you can use `mysqli` in PHP to interact with the database effectively.

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.