CentOS 7下编译安装Nginx+MySQL+PHP(3)

查看授权的用户表

[root@localhost mysql]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Server version: 5.7.18 Source distribution Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user; +--------------------------------+ | query | +--------------------------------+ | User: 'ceshi'@'%'; | | User: 'mysql.sys'@'localhost'; | | User: 'root'@'localhost'; | +--------------------------------+ 3 rows in set (0.00 sec)

在别的机器连接172.16.0.20的ceshi数据库

[root@localhost ~]# mysql -h172.16.0.20 -uceshi -p'ceshi2017' mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 11 Server version: 5.7.18 Source distribution Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | ceshi | +--------------------+ 2 rows in set (0.00 sec) PHP 7 安装

PHP 7 在15年年底推出,PHP官方说的比 PHP 5 快2倍,就为这个,这个鲜必须尝。不过有个很值得注意的地方是,虽然 PHP 7 增加了不少新特性,但也很多地方是向后不兼容的,例如 mysql 扩展,在 PHP 7 中已经被删除。 现在最新版本是7.1.4。

进入software目录

[root@localhost mysql]# cd /software/

接着解压php源码包

[root@localhost software]# tar zxvf php-7.1.4.tar.gz

再进入解压后的文件夹

[root@localhost software]# cd php-7.1.4/

这里将只安装一些常用的扩展,大家可以根据自己的实际需要进行增减,可以通过以下命令查看PHP安装是具体有有些扩展和选项:

[root@localhost php-7.1.4]# ./configure --help

有接近300个选项。
安装之前要先安装那些准备装的扩展要用到的软件模块

[root@localhost php-7.1.4]# yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel curl curl-devel openssl openssl-devel

接下来 configure PHP 7

[root@localhost php-7.1.4]# ./configure --prefix=/usr/local/php --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-mysqli --with-zlib --with-curl --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-openssl --enable-mbstring --enable-xml --enable-session --enable-ftp --enable-pdo -enable-tokenizer --enable-zip

上面已经提到,PHP 7 已经删除了 MySQL 扩展,所以 -with-mysql 不再是一个有效的选项。这里用 MySQLi 或 PDO 代替。
其中 --prefix 是安装目录,上面提到在同一个服务器安装多个 PHP 版本,这个 --prefix 设定是很有必要的。至于其他扩展大家按实际增减。
如果 configure 成功的话,将会看到以下类似字样:

+--------------------------------------------------------------------+ | License: | | This software is subject to the PHP License, available in this | | distribution in the file LICENSE. By continuing this installation | | process, you are bound by the terms of this license agreement. | | If you do not agree with the terms of this license, you must abort | | the installation process at this point. | +--------------------------------------------------------------------+ Thank you for using PHP.

编译和安装

[root@localhost php-7.1.4]# make && make install

好,PHP 7 已经安装完成,下面进行配置
先是 PHP 的配置文档

[root@localhost php-7.1.4]# cp php.ini-development /usr/local/php/lib/php.ini

php.ini 路径应该放在 PREFIX/lib 文件夹,除非在安装的时候通过这个选项修改
--with-config-file-path=PATH
如果安装 PHP 时没有指明 --prefix ,那么就 php.ini 路径就是 /usr/local/lib/php.ini 。刚才安装时有指明 --prefix ,所以是 /usr/local/php/lib/php.ini
然后根据实际自己需要修改 php.ini。
查找 mysqli.default_socket,修改成 mysqli.default_socket = /usr/local/mysql/mysql.sock:

[root@localhost php-7.1.4]# grep mysqli.default_socket /usr/local/php/lib/php.ini mysqli.default_socket = [root@localhost php-7.1.4]# sed -i 's#mysqli.default_socket =#mysqli.default_socket = /usr/local/mysql/mysql.sock#' /usr/local/php/lib/php.ini [root@localhost php-7.1.4]# grep mysqli.default_socket /usr/local/php/lib/php.ini mysqli.default_socket = /usr/local/mysql/mysql.sock

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/191db1c59a1e46fec03178ee061889db.html