CentOS8部署PHP,CentOS8 安装部署Apache+Php+MariaDB(pdo扩展)

使用新的CentOS8系统架设PHP服务器,因现在主流数据库mysql已闭源了,所以现在改为使用MariaDB.而php7以后不支持mysqli链接,只有pdo方式,为了安装pdo扩展,所以重新编译安装了PHP,折腾很久才完成,收获还是不错的,了解了很多方面的知识.

安装Apache

安装

yum -y install httpd

开启apache服务

systemctl start httpd.service

设置apache服务开机启动

systemctl enable httpd.service

开启防火墙

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

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

firewall-cmd --reload

验证apache服务是否安装成功

打开http://xx.xx.xx.xx/,apache默认的页面--有Testing 123...字样

安装PHP

安装工具与软件

yum install -y wget tar nano

下载并解压PHP源码

cd /home

wget https://www.php.net/distributions/php-7.3.13.tar.gz

tar -xzf php-7.3.13.tar.gz php-7.3.13

安装编译工具与依赖

yum install -y gcc make gcc-c++ libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel curl-devel postgresql-devel libpng libjpeg-devel libjpeg libpng-devel freetype freetype-devel libicu-devel libzip cmake

安装libsodium

wget https://download.libsodium.org/libsodium/releases/libsodium-1.0.18-stable.tar.gz

tar -zxf libsodium-1.0.18-stable.tar.gz libsodium-stable

cd libsodium-stable

./configure --prefix=/usr

make && make check

php-devel

创建用户与群组

groupadd www

useradd -g www www

内连ldap

ln -sv /usr/lib64/libldap* /usr/lib/

安装libzip

wget https://libzip.org/download/libzip-1.5.2.tar.gz

tar -zxf libzip-1.5.2.tar.gz

cd libzip-1.5.2

mkdir build

cd build

cmake ..

make -j4

make install

添加搜索路径到配置文件

nano /etc/ld.so.conf

在文件最后添加

/usr/local/lib64

/usr/local/lib

/usr/lib

/usr/lib64

更新配置

ldconfig -v

配置php源码

cd /home/php-7.3.13

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-config-file-scan-dir=/usr/local/php/etc/php.d --enable-fpm --with-fpm-user=www --with-fpm-group=www --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-mysqlnd-compression-support --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl=/usr/local/curl --enable-mbregex --enable-mbstring --enable-intl --enable-ftp --with-gd --enable-gd-jis-conv --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --disable-fileinfo --enable-opcache --enable-maintainer-zts --with-ldap=shared --without-gdbm --with-apxs2=/usr/bin/apxs

编译与安装

make && make install

将路径加入到系统环境变量中

nano /etc/profile

在最后加入PHP路径:

PATH=$PATH:/usr/local/php/bin

export PATH

保存后,在任意地方尝试运行php -version成功。

修改Apache配置

nano /etc/httpd/conf/httpd.conf

#在LoadModule后面添加:(未添加.php文件会变成下载)

LoadModule php7_module modules/libphp7.so

#在DirectoryIndex后面添加index.php:(让网站默认显示页面)

DirectoryIndex index.html index.php

#在AddType application/x-gzip .gz .tgz后面添加:

AddType application/x-httpd-php .php //.php前面有一个空格

然后重启Apache服务

systemctl restart httpd.service

安装MariaDB

安装MariaDB

yum install mariadb-server -y

重启MariaDB

systemctl restart mariadb.service

设置MariaDB权限与密码等

登陆MariaDB:无密码mysql -uroot有密码用mysql -uroot -p123456

显示数据库show databases;

选择数据库use mysql;

查询用户SELECT host,user,password from user;

设置密码set password for ‘root‘@‘localhost‘ =password(‘123456‘);

远程连接设置grant all privileges on *.* to root@‘%‘identified by ‘123456‘;

如果是不是root则先新建用户create user ‘用户名‘@‘%‘ ip地址 by ‘密码‘

设置防火墙

firewall-cmd --permanent --zone=public --add-port=3306/tcp

firewall-cmd --reload

至此数据库已经可以连接了(windows客户端可以使用HeidiSQL来连接数据库)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值