一. 源码安装php7.2

  1. 选择需要的php版本

    • 从 php官网: http://cn2.php.net/downloads.php 选择需要的php版本,选择.tar.gz 的下载包,点击进入,选择中国的本地语言包,复制这个下载地址

    最后得到的下载的地址就是: 
    http://cn2.php.net/get/php-7.2.0.tar.gz/from/this/mirror 
    (参照这个方法就可以随时获取最新版本的PHP了) 
    2.下载php源码

    • 选择一个位置存放文件 
      cd /usr/src/
    • 下载刚刚选好的php压缩包 
      wget http://cn2.php.net/get/php-7.2.0.tar.gz/from/this/mirror 
      但是我们下载下来看到并不是我们要的php-7.2.0.tar.gz 类似的压缩文件,而是一个mirror的文件,很简单,我们给文件重命名就可以了 
      mv mirror php-7.2.0.tar.gz 
      1. 安装php所需要的依赖
    yum install gcc
yum install libxml2
yum install libxml2-devel
yum install openssl openssl-devel
yum -y install curl-devel
yum install libjpeg.x86_64 libpng.x86_64 freetype.x86_64 libjpeg-devel.x86_64 libpng-devel.x86_64 freetype-devel.x86_64 -y
yum install bzip2-devel.x86_64 -y
yum install libXpm-devel
yum install gmp-devel
yum install -y icu libicu libicu-devel
yum install php-mcrypt libmcrypt libmcrypt-devel
yum install postgresql-devel
yum install libxslt-devel
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

4.解压编译 
tar -xzxvf php-7.2.0.tar.gz 
cd php-7.2.0 
设置编译需要加载的模块 
./configure --prefix=/usr/local/php --with-pdo-pgsql --with-zlib-dir --with-freetype-dir --enable-mbstring --with-libxml-dir=/usr --enable-soap --enable-calendar --with-curl --with-mcrypt --with-gd --with-pgsql --disable-rpath --enable-inline-optimization --with-bz2 --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --enable-exif --enable-bcmath --with-mhash --enable-zip --with-pcre-regex --with-pdo-mysql --with-mysqli --with-jpeg-dir=/usr --with-png-dir=/usr --enable-gd-native-ttf --with-openssl --with-fpm-user=www-data --with-fpm-group=www-data --with-libdir=/lib/x86_64-linux-gnu/--enable-ftp --with-gettext --with-xmlrpc --with-xsl --enable-opcache --enable-fpm --with-iconv --with-xpm-dir=/usr

编译: 
make clean && make && make install 
5. 复制配置文件 
cp php.ini-development /usr/local/php/lib/php.ini 
6. 设置全局的php命令 
vim /etc/profile 
在文件最后添加:

PATH=$PATH:/usr/local/php/bin
export PATH
  • 1
  • 2

然后执行 命令 source /etc/profile 
此时php就是全局命令了,可以通过php -v 查看php版本信息或者php -m 看看刚刚编译加载的模块了

  1. 配置PHP-fpm
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf

cp /usr/src/php-7.2.0/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

chmod +x /etc/init.d/php-fpm
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

新建www-data 用户组:

groupadd www-data
useradd -g www-data www-data
  • 1
  • 2

启动php-fpm 
/etc/init.d/php-fpm start 
(可选)配置php-fpm自启动,如果存在这个文件,这步省略 
创建php-fpm启动脚本

vim /etc/init.d/php-fpm
  • 1

插入如下内容:

#!/bin/sh
# chkconfig: 2345 15 95 # description: PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation \ # with some additional features useful for sites of any size, especially busier sites.
# DateTime: 2016-09-20 # Source function library.
. /etc/rc.d/init.d/functions # Source networking configuration.
. /etc/sysconfig/network # Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0 phpfpm="/usr/local/php/sbin/php-fpm"
prog=$(basename ${phpfpm}) lockfile=/var/lock/subsys/phpfpm start() {
[ -x ${phpfpm} ] || exit 5
echo -n $"Starting $prog: "
daemon ${phpfpm}
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
} stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
} restart() {
configtest || return $?
stop
start
} reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc ${phpfpm} -HUP
RETVAL=$?
echo
} force_reload() {
restart
} configtest() {
${phpfpm} -t
} rh_status() {
status $prog
} rh_status_q() {
rh_status >/dev/null 2>&1
} case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
status)
rh_status
;;
*)
echo $"Usage: $0 {start|stop|status|restart|reload|configtest}"
exit 2
esac
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94

添加到开机启动项 
chkconfig --add php-fpm

此时也可以使用service来启动php-fpm了

service php-fpm start
service php-fpm stop
  • 1
  • 2

二、yum安装nginx 
1. 执行yum安装命令 
yum install nginx 
关于yum安装nginx的一些位置说明: 
https://www.cnblogs.com/odbo/p/5295690.html 
2. 修改配置文件已支持php 
cd /etc/nginx/ 
删掉原本的nginx.conf,复制一份nginx.conf.default的默认配置

rm -rf nginx.conf
cp nginx.conf.default nginx.conf
vim nginx.conf
  • 1
  • 2
  • 3

server里面的配置: 
在location / 的中index增加index.php ,增加URL重写读取; 
解开location ~ .php$的注释,修改fastcgi的路径,最终server部分配置内容为:

server {
listen 80;
server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / {
root html;
# 修改1:这里新增了index.php
index index.html index.htm index.php;
# 修改2:这里新增url重写(path)
try_files $uri $uri/ /index.php$is_args$args;
} #error_page 404 /404.html; # redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html { root html;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#修改3:解开php支持的注释
location ~ \.php$ {
root html;
#默认就使用php-fpm
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#修改4:修改fastcig的路径
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
} # deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53

保存配置文件。 
3.启动nginx 
service nginx start 
4.(可选)设置nginx开机自启动 
创建nginx启动命令脚本 
vi /etc/init.d/nginx 
插入以下内容:

#! /bin/bash
# chkconfig: - 85 15
PATH=/usr/local/nginx
DESC="nginx daemon"
NAME=nginx
DAEMON=$PATH/sbin/$NAME
CONFIGFILE=$PATH/conf/$NAME.conf
PIDFILE=$PATH/logs/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
set -e
[ -x "$DAEMON" ] || exit 0
do_start() {
$DAEMON -c $CONFIGFILE || echo -n "nginx already running"
}
do_stop() {
$DAEMON -s stop || echo -n "nginx not running"
}
do_reload() {
$DAEMON -s reload || echo -n "nginx can't reload"
}
case "$1" in
start)
echo -n "Starting $DESC: $NAME"
do_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
do_stop
echo "."
;;
reload|graceful)
echo -n "Reloading $DESC configuration..."
do_reload
echo "."
;;
restart)
echo -n "Restarting $DESC: $NAME"
do_stop
do_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2
exit 3
;;
esac
exit 0
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48

设置执行权限 
chmod a+x /etc/init.d/nginx 
注册成服务 
chkconfig --add nginx 
设置开机启动 
chkconfig nginx on 
重启查看nginx服务是否自动启动(!!! 请确保重启不会影响现有业务,如不确定请不要执行,后果自负)

shutdown -h 0 -r
netstat -apn|grep nginx
  • 1
  • 2

配置nginx成服务还有一个好处就是可以直接通过systemctl或者service直接启动或停止nginx了,例如 systemctl stop nginx 或者 service nginx stop就可以停止nginx了

三、编写测试文件 
vim /usr/share/nginx/html/phpinfo.php 
比如编辑一个phpinfo

<?php
phpinfo();
  • 1
  • 2

最后就可以访问刚刚这个文件了 

四、yum安装mysql5.7 
以下内容转载自:https://www.cnblogs.com/wishwzp/p/7113403.html

第一步:获取mysql YUM源 
进入mysql官网获取RPM包下载地址 
https://dev.mysql.com/downloads/repo/yum/

右击 复制链接地址 https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm 
得到这个 这个就是Yum仓库的rpm包 其实就是一个下载地址

第二步:下载和安装mysql源

先下载 mysql源安装包

wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

安装mysql源

yum -y localinstall mysql57-community-release-el7-11.noarch.rpm

第三步:在线安装Mysql

yum -y install mysql-community-server

第四步:启动Mysql服务

systemctl start mysqld

(service mysqld start 也行)

第五步:设置开机启动

systemctl enable mysqld 
systemctl daemon-reload

第六步:修改root本地登录密码

mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个临时的默认密码。

[root@localhost ~]# vi /var/log/mysqld.log

这里的临时密码 eMV.R#mWe3ha

[root@localhost ~]# mysql -u root -p

Enter password:

输入临时密码 进入mysql命令行;

mysql> ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘ZhipengWang2012@’;

Query OK, 0 rows affected (0.00 sec)

修改密码为 ZhipengWang2012@ (备注 mysql5.7默认密码策略要求密码必须是大小写字母数字特殊字母的组合,至少8位)

第七步:设置允许远程登录

Mysql默认不允许远程登录,我们需要设置下,并且防火墙开放3306端口;

mysql> GRANT ALL PRIVILEGES ON . TO ‘root’@’%’ IDENTIFIED BY ‘ZhipengWang2012@’ WITH GRANT OPTION;

Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> exit;

Bye

这里其实最好新建一个用户: 
GRANT ALL PRIVILEGES ON *.* TO 'adduser'@'%' IDENTIFIED BY 'zyytest12!' WITH GRANT OPTION;

开放3306端口 
firewall-cmd --zone=public --add-port=3306/tcp --permanent 
重启防火墙 
firewall-cmd --reload 
第八步:配置默认编码为utf8

修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置,如下所示:

[mysqld] 
character_set_server=utf8 
init_connect=’SET NAMES utf8’ 
vi /etc/my.cnf

编辑保存完 重启mysql服务; 
systemctl restart mysqld

end

版权声明:本文为博主原创文章,未经博主允许不得转载。 http://blog.csdn.net/qq_32080545/article/details/78894792

centos7.2+php7.2+nginx1.12.0+mysql5.7配置的更多相关文章

  1. CentOS-7.3.1611编译安装 Nginx-1.12.1+mysql-5.7.19+PHP-7.1.8+zabbix-3.4.1

    CentOS-7.3.1611编译安装 Nginx-1.12.1+mysql-5.7.19+PHP-7.1.8+zabbix-3.4.1 下载软件 1.下载nginx http://nginx.org ...

  2. 手动编译部署LNMP环境(CentOS7.5+Nginx-1.18.0+MySQL-5.7.30+PHP-7.4.14)

    在平时运维工作中,经常需要用到LNMP应用框架.LNMP环境是指在Linux系统下,由Nginx + MySQL + PHP组成的网站服务器架构. 可参考前面的文章: 如何在CentOS 7上搭建LA ...

  3. CentOS7.0安装Nginx-1.12.0

    一.安装准备 首先由于nginx的一些模块依赖一些lib库,所以在安装nginx之前,必须先安装这些lib库,这些依赖库主要有g++.gcc.openssl-devel.pcre-devel和zlib ...

  4. centos7编译安装LNMP(nginx-1.16.0,mysql8.0.16,php-7.3.6)常见问题报错及解决方法

    LNMP的安装与配置 nginx-1.16.0安装及配置: 第一步:前往官网下载nignx源码包 下载完毕后上传至服务器(先安装lrzsz) yum -y install lrzsz 安装完毕后执行: ...

  5. CentOS 7.0编译安装Nginx1.6.0+MySQL5.6.19+PHP5.5.14

    准备篇: CentOS 7.0系统安装配置图解教程 http://www.osyunwei.com/archives/7829.html 一.配置防火墙,开启80端口.3306端口 CentOS 7. ...

  6. CentOS 6.2编译安装Nginx1.2.0+MySQL5.5.25+PHP5.3.13

    CentOS 6.2编译安装Nginx1.2.0+MySQL5.5.25+PHP5.3.132013-10-24 15:31:12标签:服务器 防火墙 file 配置文件 written 一.配置好I ...

  7. CentOS 7.0编译安装Nginx1.6.0+MySQL5.6.19+PHP5.5.14方法分享

    一.配置防火墙,开启80端口.3306端口 CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙. 1.关闭firewall: systemctl stop fi ...

  8. Nginx1.6.0+MySQL5.6.19+PHP5.5.14(centos)

    一.配置防火墙,开启80端口.3306端口 CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙. 1.关闭firewall: systemctl stop fi ...

  9. CentOS 6.2编译安装Nginx1.2.0+MySQL5.5.25+PHP5.3.13+博客系统WordPress3.3.2

    说明: 操作系统:CentOS 6.2 32位 系统安装教程:CentOS 6.2安装(超级详细图解教程): http://www.osyunwei.com/archives/1537.html 准备 ...

随机推荐

  1. (转)飘逸的python - 增强的格式化字符串format函数

    原文:https://blog.csdn.net/handsomekang/article/details/9183303 Python字符串格式化--format()方法-----https://b ...

  2. python strip()函数的用法

    函数原型 声明:s为字符串,rm为要删除的字符序列 s.strip(rm)         删除s字符串中开头.结尾处,位于 rm删除序列的字符 s.lstrip(rm)        删除s字符串中 ...

  3. 部分替换mysql表中某列的字段

    UPDATE `table_name` SET `field_name` = replace (`field_name`,'from_str','to_str') WHERE `field_name` ...

  4. 《Android应用性能优化》2——内存、CPU、性能测评

    4.高效使用内存 4.1 说说内存 Android设备的性能主要取决于以下三因素: CPU如何操纵特定的数据类型: 数据和指令需占用多少存储空间: 数据在内存中的布局 4.2 数据类型 int和lon ...

  5. 用sinopia搭建内部npm服务

    sinopia搭建 这里默认你已经有node环境了,执行下面命令,全局安装 sinopia npm install -g sinopia 安装好后,执行下面命令启动 sinopia sinopia 你 ...

  6. C#的TextBox获取行高

    当TextBox使用多行之后,如果想获取每行的高度,似乎有点问题, TextBox.Height获取的是控件的高度, 而我们常做的是根据行的数量来决定是否要显示滚动条 如下: //不能直接获取每行的高 ...

  7. solidity如何拼接字符串?

    当你开始学习使用solidity开发以太坊智能合约之后,很快你会碰到一个问题: 一.在solidity中该如何拼接字符串? 可能你已经试过了,下面的代码试图把两个字符串使用相加的运算符连接起来,但是这 ...

  8. DirectorySearcher.Filter 属性(转)

    获取或设置一个值,该值的轻型目录访问协议 (LDAP) 格式筛选器字符串. 更多信息见:http://www.cnblogs.com/zhongweiv/archive/2013/01/05/ad_s ...

  9. Golang cron 定时任务使用

    1.cron 表达式的基本格式 用过 linux 的应该对 cron 有所了解.linux 中可以通过 crontab -e 来配置定时任务.不过,linux 中的 cron 只能精确到分钟.而我们这 ...

  10. stream was not readable.

    StreamWriter使用时的报错情况: stream was not readable. 错误原因: 没有指定StreamWriter的写入文件 正确代码示例1: byte[] businessD ...