Centos7.6 PHP 7.2.9 MariaDB Apache

发布于 2019-04-07  574 次阅读


环境
系统: CentOS 7
IP: 10.0.0.84

#查看系统版本

[root@bt18 ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)

#关闭selinux

[root@bt18 ~]# setenforce 0
[root@bt18 ~]# sed -i "s/enforcing/disabled/g" /etc/selinux/config

安装MariaDB

[root@bt18 ~]yum -y install mariadb mariadb-server mariadb-libs mariadb-devel

#马上启动MariaDB

[root@bt18 ~]systemctl start mariadb

#设置开机启动MariaDB

[root@bt18 ~]systemctl enable mariadb

#查看MariaDB运行状态

[root@bt18 ~]# systemctl status mariadb
● mariadb.service - MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
Active: active (running) since Sun 2019-03-10 23:28:54 CST; 15s ago
Main PID: 61685 (mysqld_safe)
CGroup: /system.slice/mariadb.service

#MariaDB安全配置

[root@bt18 ~]# mysql_secure_installation
Enter current password for root (enter for none):<–初次运行直接回车

设置密码

Set root password? [Y/n] <– 是否设置root用户密码,输入y并回车或直接回车
New password: 【password】 <– 设置root用户的密码
Re-enter new password: 【password】 <– 再输入一次你设置的密码

其他配置

Remove anonymous users? [Y/n] <– 是否删除匿名用户,回车
Disallow root login remotely? [Y/n] <–是否禁止root远程登录,回车,
Remove test database and access to it? [Y/n] <– 是否删除test数据库,回车
Reload privilege tables now? [Y/n] <– 是否重新加载权限表,回车

初始化MariaDB完成

安装apache

[root@bt18 ~]# yum -y install httpd httpd-devel

#马上启动Apache

[root@bt18 ~]# systemctl start httpd

#设置开机启动Apache

[root@bt18 ~]# systemctl enable httpd

#查看Apache运行状态

[root@bt18 ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: active (running) since Sun 2019-03-10 23:32:51 CST; 13s ago
Docs: man:httpd(8)
man:apachectl(8)
Main PID: 62047 (httpd)
Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec"

安装PHP7.2.9
#安装依赖

[root@bt18 ~]#yum -y install gcc libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libjpeg freetype libjpeg-devel libpng-devel freetype-devel libzip-devel bzip2-devel libXpm-devel gmp-devel icu libicu libicu-devel php-mcrypt libmcrypt libmcrypt-devel postgresql-devel libxslt-devel libjpeg-deve

#添加用户

groupadd www
useradd -g www www

下载PHP7.2.9 # http://mirrors.sohu.com/php/

[root@bt18 ~]#cd /usr/local/src

#wget 下载

[root@bt18 src]#wget http://mirrors.sohu.com/php/php-7.2.9.tar.gz

#解压

[root@bt18 src]#tar -zxvf php-7.2.9.tar.gz

#编译

[root@bt18 src]#cd php-7.2.9/
[root@bt18 php-7.2.9]#./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --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 --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-intl --with-mcrypt --with-libmbfl --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --disable-fileinfo --enable-opcache --with-pear --enable-maintainer-zts --with-ldap=shared --without-gdbm --with-apxs2=/usr/bin/apxs

报错:

configure: error: Cannot find ldap libraries in /usr/lib.

解决:

cp -frp /usr/lib64/libldap* /usr/lib/

#安装

make && make install

配置php-fpm

[root@bt18 src]#cp /usr/local/src/php-7.2.9/php.ini-production /usr/local/php/lib/php.ini
[root@bt18 src]#cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[root@bt18 src]#ln -s /usr/local/php/sbin/php-fpm /usr/local/bin
[root@bt18 src]#cd /usr/local/php/etc/php-fpm.d/
[root@bt18 src]#vim www.conf
[www]
listen = 127.0.0.1:9000   
listen.mode = 0666      
user = www
group = www 
pm = dynamic
pm.max_children = 128
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 10000
rlimit_files = 1024
slowlog = log/$pool.log.slow

#加入 systemtl 服务

[root@bt18 ~]# cp /usr/local/src/php-7.3.1/sapi/fpm/php-fpm.service /usr/lib/systemd/system/

#马上启动php-fpm

[root@bt18 ~]# systemctl start php-fpm

#设置开机启动php-fpm

[root@bt18 ~]# systemctl enable php-fpm

#查看php-fpm运行状态

[root@bt18 ~]# systemctl status php-fpm.service
● php-fpm.service - The PHP FastCGI Process Manager
   Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2019-03-11 00:10:08 CST; 2min 23s ago
 Main PID: 112317 (php-fpm)

#设置防火墙

firewall-cmd --permanent --zone=public --add-service=http 
firewall-cmd --permanent --zone=public --add-service=https 
firewall-cmd --permanent --zone=public --add-port=3306/tcp 
firewall-cmd --permanent --zone=public --add-port=80/tcp 
firewall-cmd --reload

#配置Apache

[root@bt18 ~]# vi /etc/httpd/conf/httpd.conf

约152行

AllowOverride None 

改为

AllowOverride All

约164行

DirectoryIndex index.html

改为

DirectoryIndex index.html index.php index.htm

添加
约286

AddType application/x-httpd-php .php

最尾添加

ServerTokens Prod
KeepAlive On

#重启 Apache

[root@bt18 ~]# systemctl restart httpd 

访问测试

[root@bt18 ~]# cd /var/www/html
[root@bt18 ~]# touch 1.php
[root@bt18 ~]# vi i.php

<?php
phpinfo();
?>

http://10.0.0.84/1.php


一沙一世界,一花一天堂。君掌盛无边,刹那成永恒。