- CentOS 7 – Install PHP and Postgres
- How To Install php-pgsql on CentOS 7
- What is php-pgsql
- Install php-pgsql on CentOS 7 Using yum
- Install php-pgsql on CentOS 7 Using dnf
- How To Uninstall php-pgsql on CentOS 7
- php-pgsql Package Contents on CentOS 7
- References
- Summary
- Install phpPgAdmin On CentOS 7
- Before you move on, you need to:
- Step 1: Update the system to the latest status
- Step 2: Install Apache Web Server
- Step 3: Configure the firewall
- Step 4: Install PHP 5 and the necessary extensions
- Step 5: Install and configure PostgreSQL
- Step 6: Install and Use phpPgAdmin
- virbo / lempp.md
CentOS 7 – Install PHP and Postgres
First time using CentOS. Thought it will be useful to list down the steps to install PHP and Postgres and get it to work together.
0. Always recommend updating
yum update # update will update every currently installed package
1. Install PHP
yum install php # Validate installation and version by executing php --info
2. Install PostgreSQL
yum install postgresql-server postgresql-contrib
3. Install php-pgsql connector
4. Now start and enable postgres
service postgresql initdb systemctl start postgresql systemctl enable postgresql service postgresql restart
5. Modify the pg_hba.conf file located under /var/lib/pgsql/data/. Find the lines that looks like this
host all all 127.0.0.1/32 ident host all all ::1/128 ident
Then replace “ident” with “md5”, so they look like this:
host all all 127.0.0.1/32 md5 host all all ::1/128 md5
6. Create local user and set user password
adduser automation sudo su passwd automation
7. Login as postgres and connect to database. Create user role (with same password as shell) and new database
su postgres pgsql >CREATE DATABASE masterdb; >CREATE ROLE automation WITH PASSWORD 'UserPassword'; >GRANT ALL PRIVILEGES ON DATABASE masterdb TO automation; >ALTER ROLE automation WITH LOGIN;
The last one was important because I wasn’t able to connect to the database. But not sure if this solved the problem because GRANT ALL PRIVILEGES should have taken care of it. Needs to be researched further.
8. Create a test connection script in PHP to validate database connection
// Configure DB Parameters $host = «localhost»; $dbname = «masterdb»; $dbuser = «automation»; $userpass = «UserPassword»; $con = pg_connect(«host=$host dbname=$dbname user=$dbuser password=$userpass «); if (!$con) < die('Could not connect'); >else
How To Install php-pgsql on CentOS 7
In this tutorial we learn how to install php-pgsql on CentOS 7.
What is php-pgsql
The php-pgsql add PostgreSQL database support to PHP. PostgreSQL is an object-relational database management system that supports almost all SQL constructs. PHP is an HTML-embedded scripting language. If you need back-end support for PostgreSQL, you should install this package in addition to the main php package.
We can use yum or dnf to install php-pgsql on CentOS 7. In this tutorial we discuss both methods but you only need to choose one of method to install php-pgsql.
Install php-pgsql on CentOS 7 Using yum
Update yum database with yum using the following command.
After updating yum database, We can install php-pgsql using yum by running the following command:
sudo yum -y install php-pgsql
Install php-pgsql on CentOS 7 Using dnf
If you don’t have dnf installed you can install dnf first. Update yum database with dnf using the following command.
After updating yum database, We can install php-pgsql using dnf by running the following command:
sudo dnf -y install php-pgsql
How To Uninstall php-pgsql on CentOS 7
To uninstall only the php-pgsql package we can use the following command:
php-pgsql Package Contents on CentOS 7
/etc/php.d/pdo_pgsql.ini /etc/php.d/pgsql.ini /usr/lib64/php/modules/pdo_pgsql.so /usr/lib64/php/modules/pgsql.so
References
Summary
In this tutorial we learn how to install php-pgsql on CentOS 7 using yum and dnf.
Install phpPgAdmin On CentOS 7
phpPgAdmin is a widely used PostgreSQL management tool. You can use it to manage PostgreSQL databases in an intuitive web interface.
In this article, we will cover the necessary steps to install phpPgAdmin on a Vultr CentOS 7 x64 server instance.
Before you move on, you need to:
Step 1: Update the system to the latest status
On CentOS 7, it is always recommended to update the system to the latest status using yum:
sudo yum update sudo reboot
Note: You only need to reboot your instance if kernel updates were applied.
Once the server reboots, log in again using the same sudo user.
Step 2: Install Apache Web Server
Since phpPgAdmin is a web-based tool, a web server is required for it to run.
For the purpose of this tutorial, we will installing Apache. You are however free to pick your Niginx or Lighttpd if you prefer.
sudo yum install httpd sudo systemctl start httpd.service sudo systemctl enable httpd.service
Step 3: Configure the firewall
You need to modify the default firewall configuration before you can access phpPgAdmin from a web browser:
sudo firewall-cmd --zone=public --permanent --add-service=http sudo firewall-cmd --zone=public --permanent --add-port=5432/tcp sudo firewall-cmd --reload
Then you can visit http://[YourServerIP] from your browser to confirm your configuration.
Note: For your information, SELinux is disabled on the Vultr CentOS 7 x64 server instance by default. If you turn it on manually, you need also configure SELinux as below:
sudo setsebool -P httpd_can_network_connect on sudo setsebool -P httpd_can_network_connect_db on
Step 4: Install PHP 5 and the necessary extensions
phpPgAdmin is written in PHP, you need to install PHP 5 and some extensions to serve phpPgAdmin.
sudo yum install php php-pgsql
Step 5: Install and configure PostgreSQL
On the phpPgAdmin official website, find the latest stable version of PostgreSQL for CentOS 7 x64 and its URL. As of writing, the latest stable version of PostgreSQL is 9.5.
5.1) Use the following commands to install PostgreSQL 9.5 on your CentOS 7 server:
sudo yum install http://yum.postgresql.org/9.5/redhat/rhel-7-x86_64/pgdg-centos95-9.5-2.noarch.rpm sudo yum groupinstall "PostgreSQL Database Server 9.5 PGDG"
sudo /usr/pgsql-9.5/bin/postgresql95-setup initdb
5.3) Setup database user authentication method:
sudo vi /var/lib/pgsql/9.5/data/pg_hba.conf
Find the following section:
# IPv4 local connections: host all all 127.0.0.1/32 ident # IPv6 local connections: host all all ::1/128 ident
Modify the authentication method of IPv4 local connections to md5:
# IPv4 local connections: host all all 127.0.0.1/32 md5 # IPv6 local connections: host all all ::1/128 md5
5.4) Setup PostgreSQL listening addresses:
sudo vi /var/lib/pgsql/9.5/data/postgresql.conf
#listen_addresses = 'localhost'
5.5) Start the PostgreSQL service:
sudo systemctl start postgresql-9.5.service sudo systemctl enable postgresql-9.5.service
5.6) Setup database user credentials:
By default, PostgreSQL program will create a database user «postgres». For security purposes, however, you need to create another database user for remote log in.
CREATE USER pgdbuser CREATEDB CREATEUSER ENCRYPTED PASSWORD 'pgdbpass'; CREATE DATABASE mypgdb OWNER pgdbuser; GRANT ALL PRIVILEGES ON DATABASE mypgdb TO pgdbuser; \q
Step 6: Install and Use phpPgAdmin
Install phpPgAdmin with the following command:
sudo yum install phpPgAdmin
Then configure phpPgAdmin as accessible from outside:
sudo vi /etc/httpd/conf.d/phpPgAdmin.conf
virbo / lempp.md
Edit environtment vi /etc/environment add these lines.
LANG=en_US.utf-8 LC_ALL=en_US.utf-8
yum -y update yum -y upgrade
yum install epel-release yum install nginx
Start NGINX and Enable Service
systemctl start nginx systemctl enable nginx
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum --disablerepo="*" --enablerepo="remi-safe" list php82.x86_64
yum -y install yum-utils yum-config-manager --enable remi-php80
yum -y install php php-fpm php-mysqlnd php-pgsql php-gd php-imagick php-json php-opcache php-mcrypt php-curl php-mongodb php-mbstring php-intl php-dom php-zip
Make sure the /var/lib/php directory has the correct ownership :
chown -R root:nginx /var/lib/php
Edit nano /etc/php-fpm.d/www.conf
user = nginx group = nginx listen = /var/run/php-fpm/php-fpm.sock listen.owner = nginx listen.group = nginx listen.mode = 0660
systemctl start php-fpm systemctl enable php-fpm
Create VirtualHost Default NGINX nano /etc/nginx/conf.d/default.conf
server < listen 80; server_name server_domain_or_IP; root /usr/share/nginx/html; index index.php index.html index.htm; location / < try_files $uri $uri/ =404; >error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html < root /usr/share/nginx/html; >location ~ \.php$ < try_files $uri =404; fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; >>
nginx -t systemctl restart nginx
Testing PHP nano /usr/share/nginx/html/info.php
Install Postgres (Latest Version)
rpm -Uvh https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm yum list postgresql* yum -y install postgresql13-server postgresql13-contrib postgresql13
/usr/pgsql-13/bin/postgresql-13-setup initdb
Start and Enable Postgres
systemctl start postgresql-13 systemctl enable postgresql-13
nano /var/lib/pgsql/13/data/pg_hba.conf
host all all 127.0.0.1/32 md5 host all all ::1/128 md5
su postgres psql CREATE DATABASE db_name; CREATE ROLE username WITH PASSWORD 'password' GRANT ALL PRIVILEGES ON DATABASE db_name TO username; ALTER ROLE username WITH LOGIN;
Install MariaDB 10 (Centos 7 default using MariaDB 5)
First download and use the mariadb_repo_setup script to configure the MariaDB repositories for YUM
wget https://downloads.mariadb.com/MariaDB/mariadb_repo_setup chmod +x mariadb_repo_setup ./mariadb_repo_setup
yum install mariadb-server
Configuring and Securing MariaDB Server
systemctl start mariadb systemctl enable mariadb sudo mysql_secure_installation
mysqladmin -u root -p version
indicates the installation has been successful like this
mysqladmin Ver 9.1 Distrib 10.5.8-MariaDB, for Linux on x86_64 Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Server version 10.5.8-MariaDB Protocol version 10 Connection Localhost via UNIX socket UNIX socket /var/lib/mysql/mysql.sock Uptime: 2 hours 50 min 24 sec Threads: 2 Questions: 690 Slow queries: 0 Opens: 100 Open tables: 94 Queries per second avg: 0.067
cd /tmp wget https://files.phpmyadmin.net/phpMyAdmin/5.0.4/phpMyAdmin-5.0.4-all-languages.zip unzip phpMyAdmin-5.0.4-all-languages.zip mv phpMyAdmin-5.0.4-all-languages /usr/share
Update config virtualhost
nano /etc/nginx/conf.d/default.conf
location /phpMyAdmin < root /usr/share/; index index.php index.html index.htm; location ~ ^/phpMyAdmin/(.+\.php)$ < try_files $uri =404; fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; >location ~* ^/phpMyAdmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ < root /usr/share/; >> location /phpmyadmin < rewrite ^/* /phpMyAdmin last; >
yum -y install perl-libwww-perl.noarch perl-LWP-Protocol-https.noarch perl-GDGraph dns-utils
cd /usr/src rm -fv csf.tgz wget https://download.configserver.com/csf.tgz tar -xzf csf.tgz cd csf sh install.sh
systemctl stop firewalld systemctl disable firewalld
Solving problem error nginx nginx open() failed (13: Permission denied)
Check selinux, you must disable selinux for solving this error
if still error, do it step below. Check permission
sudo -u username stat /home/username/public_html sudo -u nginx stat /home/username/public_html
Add username to group nginx
chmod g+x /home && chmod g+x /home/username/public_html
Upgrade NGINX (if version nginx installed lower than current version)
Create nginx repo /etc/yum.repos.d/nginx.repo
[nginx-stable] name=nginx stable repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=1 enabled=1 gpgkey=https://nginx.org/keys/nginx_signing.key module_hotfixes=true [nginx-mainline] name=nginx mainline repo baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/ gpgcheck=1 enabled=0 gpgkey=https://nginx.org/keys/nginx_signing.key module_hotfixes=true
if error after upgrade ( module «/usr/lib64/nginx/modules/ngx_http_image_filter_module.so» version 1016001 instead of 1018000 in /usr/share/nginx/modules/mod-http-image-filter.conf:1 ), do it this step
yum remove nginx-mod* yum install nginx-module-*
- https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-centos-7
- https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-centos-7
- https://linuxize.com/post/install-php-7-on-centos-7/
- https://www.woktron.com/secure/knowledgebase/77/Installation-CSF-Firewall-on-CentOS.html
- https://www.pusathosting.com/kb/linux/csf_error/warning_binary_location_for_host
- https://stackoverflow.com/questions/25774999/nginx-stat-failed-13-permission-denied
- https://stackoverflow.com/questions/19285355/nginx-403-error-directory-index-of-folder-is-forbidden
- https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-on-centos-7
- https://phoenixnap.com/kb/how-to-set-up-nginx-server-blocks-virtual-hosts-centos-7
- https://phppedia.com/en/knowledge-base/51254473/php-with-nginx—403-forbidden
- https://varunver.wordpress.com/2016/06/03/centos-7-install-php-and-postgres/
- https://stackoverflow.com/questions/43550336/nginx-failed-test-version-1010002-instead-of-1012000-in-usr-share-nginx-modules
- http://nginx.org/en/linux_packages.html#RHEL-CentOS
- https://www.prado.lt/5-minute-upgrade-nginx-1-12-to-1-17-on-centos-7-rhel-7
- https://mariadb.com/resources/blog/installing-mariadb-10-on-centos-7-rhel-7/
- https://www.digitalocean.com/community/tutorials/how-to-install-mariadb-on-centos-7
- https://linuxize.com/post/how-to-install-phpmyadmin-with-nginx-on-centos-7/