centos下编译安装postgresql数据库

系统是centos6.x,现在需要配置nginx+php+postgresql,整个流程自己做了一遍记录下,网上的教程都是东拼西凑,自己完整的搞了一遍。

系统约定:软件包放在/usr/local/src下,安装在/usr/local/下的目录即是软件名,跟我以前编译习惯一致

首先前期安装依赖的项

yum install gcc gcc-c++ make readline-devel flex zlib-devel -y

接着去这选择你要编译安装的postgresql的版本:http://ftp.postgresql.org/pub/source/

然后下面详情跟着操作就可以了。

cd /usr/local/src
tar -zxvf postgresql-9.6.6.tar.gz
groupadd postgres  #添加mysql组    
useradd -g postgres postgres #必须要添加pgsql独立用户,后面操作都需要切换这个账户
passwd postgres
mkdir -p /data/pgsql
chown -R postgres:postgres /data/pgsql
mkdir -p /usr/local/pgsql
cd postgresql-9.6.6
./configure --prefix=/usr/local/pgsql
make && make install

上面没有报错的话,接下来我们位pgsql创建账户和密码

切换到postgres账户

su - postgres
cd /usr/local/pgsql/bin
./initdb -D /data/pgsql #初始化pgsql数据
#退出postgres用户
exit

#到这里,数据库就算安装好了。

不过现在还缺少一个启动脚本,还好postgresql官方已经帮你准备好了,那么在哪呢?就在你的源码目录下,用它就行了。

#复制postgresql的源码包目录下的linux启动脚本到/etc/init.d

cp /usr/local/src/postgresql-9.6.6/contrib/start-scripts/linux /etc/rc.d/init.d/pgsqld
vi /etc/rc.d/init.d/pgsqld
PGDATA="/data/pgsql" #修改pgsql数据存放路径

#赋予执行权限

chmod +x /etc/init.d/pgsqld

#启动数据库

service pgsqld start #注意要先启动,直接restart是启动不了的。

#开机启动

chkconfig pgsqld on

#添加系统环境变量

export PATH=$PATH:/usr/local/pgsql/bin

还有一件事没完成,那就是刚安装好的postgresql数据库还没有密码,咱得给它设一个密码

#连接到数据库,修改管理员密码

/usr/local/psql/bin/psql -U postgres

#执行以下语句,给postgres用户设置密码

ALTER USER postgres WITH PASSWORD '你的密码';

#退出

\q

上面postgresql基本已经配置完,我们解析来配置nginx和php,主要参考这个文章https://sulao.cn/post/111.html

其中php配置改成如下配置:

./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7/etc --with-pgsql=/usr/local/pgsql/bin/pg_config --with-pdo-pgsql=/usr/local/pgsql/bin/pg_config --with-gd --with-iconv --with-zlib --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex  --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt --with-curl --with-jpeg-dir --with-freetype-dir --with-png-dir

或者按照下面教程追加编译两个扩展,一个pq和一个PDO_PGSQL

解包上面两个扩展,进入扩展包解压的文件夹内
/usr/local/php7/bin/phpize
./configure --with-php-config=/usr/local/php7/bin/php-config
make && make install

安装这两个扩展钱需要先添加raphf扩展

追加编译成功会在相应的文件夹内生成.so文件,然后在php.ini文件内extension里面加上即可,然后重启php-fpm和nginx,phpinfo页面浏览看看是否开启扩展 

20170527115302308.png

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://sulao.cn/post/456.html

我要评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。