newfarhui 2019-12-24
使用新的CentOS8系统架设PHP服务器,因现在主流数据库mysql已闭源了,所以现在改为使用MariaDB.而php7以后不支持mysqli链接,只有pdo方式,为了安装pdo扩展,所以重新编译安装了PHP,折腾很久才完成,收获还是不错的,了解了很多方面的知识.
yum -y install httpd
systemctl start httpd.service
systemctl enable httpd.service
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload
安装工具与软件yum install -y wget tar nano
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
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
ln -sv /usr/lib64/libldap* /usr/lib/
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
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
PATH=$PATH:/usr/local/php/bin export PATH
保存后,在任意地方尝试运行php -version
成功。
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
yum install mariadb-server -y
systemctl restart mariadb.service
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 ‘%‘identified by ‘123456‘;
create user ‘用户名‘@‘%‘ ip地址 by ‘密码‘
firewall-cmd --permanent --zone=public --add-port=3306/tcp
firewall-cmd --reload