使用新的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
/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64
./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:无密码
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来连接数据库)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。