微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

安装Apache

  1. 安装
    yum -y install httpd
  2. 开启apache服务
    systemctl start httpd.service
  3. 设置apache服务开机启动
    systemctl enable httpd.service
  4. 开启防火墙
    firewall-cmd --permanent --zone=public --add-service=http
    firewall-cmd --permanent --zone=public --add-service=https
    firewall-cmd --reload
  5. 验证apache服务是否安装成功
    打开http://xx.xx.xx.xx/,apache认的页面--有Testing 123...字样

安装PHP

  1. 安装工具与软件
    yum install -y wget tar nano
  2. 下载并解压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
  1. 安装编译工具与依赖
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
  1. 安装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

  1. 创建用户与群组
groupadd www
useradd -g www www
  1. 内连ldap
ln -sv  /usr/lib64/libldaP* /usr/lib/ 
  1. 安装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
  1. 添加搜索路径到配置文件
    nano /etc/ld.so.conf
    文件最后添加
/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64
  1. 更新配置
    ldconfig -v
  2. 配置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
  1. 编译与安装
    make && make install

  2. 将路径加入到系统环境变量中
    nano /etc/profile
    在最后加入PHP路径:
PATH=$PATH:/usr/local/PHP/bin
export PATH

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

  1. 修改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

  1. 安装MariaDB
    yum install mariadb-server -y
  2. 重启MariaDB
    systemctl restart mariadb.service
  3. 设置MariaDB权限与密码
  1. 设置防火墙
    firewall-cmd --permanent --zone=public --add-port=3306/tcp
    firewall-cmd --reload
    至此数据库已经可以连接了(windows客户端可以使用Heidisql来连接数据库)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐