道者编程

php7和 mysql5.7.17安装

centos安装:

一:mysql采用rpm安装

(1):rpm在线安装

1:添加安装源

# 安装源,会在 /etc/yum.repos.d/ 下生成 mysql-community.repo 文件
rpm -ivh https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm 
# 查看 yum 源中是否有 mysql 安装包
yum repolist all | grep mysql
 2:安装

# 安装管理工具
yum install -y yum-utils 

# 禁用 mysql 8.0

yum-config-manager --disable mysql80-community
# 启用 mysql 5.7
yum-config-manager --enable mysql57-community
    
# 安装mysql
yum install -y mysql-community-server
 3:命令和管理

# 开启服务
systemctl start mysqld.service
    
# 开机自启动
systemctl enable mysqld.service
    
# 检查MySQL服务器的状态
systemctl status mysqld.service
    
# 查看端口
netstat -ln | grep 3306
    
# 从日志文件中获取 root 账户初始密码
grep "password" /var/log/mysqld.log
 4:初始化、修改密码

mysql_secure_installation
 

(2):rpm本地安装,在https://dev.mysql.com/downloads/repo/yum/下载下来

1:先检查服务器是否有mysql存在

#rpm -qa | grep mariadb #mysql也查一下
mariadb-libs-5.5.52-1.el7.x86_64 
 卸载掉:

rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64
如果etc下有my.cnf,也删掉,/var/lib/mysql 都删掉

2:把mysql解压在一个目录下,


解压后有12个包我们只要安装其中四个即可,注意安装顺序。*rpm 安装很可能安装不完,依次执行命令:

rpm -ivh mysql-community-common-5.7.17-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.17-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.17-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.17-1.el7.x86_64.rpm
 

报错提示:


解决方法:

yum install -y perl-Module-Install.noarch perl-JSON.noarch
 

3:又报错:


解决方法:加--force --nodeps强制安装,这种情况是服务器存在mysql残留文件,第2步的四个rpm 加上 --force --nodeps 强制安装。比如:

rpm -ivh --force --nodeps mysql-community-common-5.7.17-1.el7.x86_64.rpm


4:初始化,用root登录:

mysqld --initialize --user=mysql

报错:


命令查找:

yum search libnuma
 


如上图,输入命令

yum -y install numactl
 问题解决

5:查看日志: cat /var/log/mysqld.log,文件最后为mysql密码,保存下来

6:启动mysql:

systemctl start mysqld 或者 /etc/init.d/mysql start

7:输入mysql -uroot -p 进入mysql控制台。

8:修改mysql密码:

alter user 'root'@'localhost' identified by '123'

 这样就把root密码修改为123


二:PHP安装编译同以前没什么区别:

1:编译安装

安装依赖:RedHat/Centos平台:

$ yum install -y epel-release
$ yum -y install libmcrypt-devel libxm12 libxml2-devel BZip2-devel bzip2-devel curl curl-devel libjpeg libpng freetype libjpeg-devel libpng-devel freetype-devel

 Debian/Ubuntu平台:

$ apt-get install -y libmcrypt-dev libxml2 libxml2-dev libbz2-dev libcurl4-gnutls-dev libwebp-dev libjpeg-dev libpng-dev libxpm-dev libfreetype6-dev libvpx-dev

编译:

# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-libxml-dir --with-mcrypt --with-gd --with-jpeg-dir --with-png-dir --with-bz2 --with-freetype-dir --with-iconv-dir --with-zlib-dir --enable-bcmath --enable-soap --enable-zip --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --enable-ipv6 --with-zlib --with-curl --with-pdo-mysql --with-openssl --enable-fpm --with-mysqli
# make
# make install 
 注意:如果mysql是源安装,那么--with-mysql=/usr/local/mysql 指定安装路径 如果是rpm安装 则--with-mysql即可,--with-mysqli=/usr/local/mysql/bin/mysql_config,但是PHP7已经没有了mysql扩展支持,所以这里要用:--with-pdo-mysql --with-mysqli;如果是php7.2:以上编译参数要去掉 --enable-gd-native-ttf 和--with-mcrypt,php7.2不支持这两个选项,phh7.1开始,官方就开始建议用openssl_*系列函数代替Mcrypt_*系列的函数

# cp php.ini-development /usr/local/php/etc/php.ini
# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
# cp -R ./sapi/fpm/php-fpm /etc/init.d/php-fpm
# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
 

sapi在php编译目录, php7中www.conf配置文件,配置phpfpm的端口号等信息,如果你修改默认的9000端口号需在这里改,再改nginx配置


查看一下my.cnf,找到socket=/var/lib/mysql/mysql.sock,然后在phpini里配置:

mysqli.default_socket =/var/lib/mysql/mysql.sock
pdo_mysql.default_socket=/var/lib/mysql/mysql.sock

开启Opcache加速:

zend_extension=opcache.so 
opcache.enable=1
opcache.enable_cli=1"

 opcache.so,如果在配置文件中没有则加进去,其他选项都有,去掉分号即可,这两个参数在7.2中默认是1,只是没开启,在7.0中默认是0;其他配置项参考手册。


启动:

/etc/init.d/php-fpm


设置nginx和php的环境变量:打开文件/etc/profile

export PHP_HOME=/usr/local/php/bin
export NGINX_HOME=/usr/local/nginx/sbin
export PATH=$PATH:$PHP_HOME:$NGINX_HOME

设置好后运行命令生效:

source /etc/profile

nginx的配置以及和PHP的配置参考另外一篇  php5.5 nginx mysql linux安装

2:yum安装

推荐使用Remi安装,Remi 软件源主要提供最新版的 PHP 软件包和其他一些 PHP 扩展工具包,它是针对 Fedora 和 RHEL体系,非常方便。

安装 EPEL 源及源管理工具:

yum install epel-release yum-utils
安装 REMI 源:

yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
 安装php以及扩展

yum install -y php73-php-fpm php73-php-cli php73-php-bcmath php73-php-gd php73-php-json php73-php-mbstring php73-php-mcrypt php73-php-mysqlnd php73-php-opcache php73-php-pdo php73-php-pecl-crypto php73-php-pecl-mcrypt php73-php-pecl-geoip php73-php-pecl-swoole php73-php-recode php73-php-snmp php73-php-soap php73-php-xmll

 如果扩展不够,还要安装其他扩展

yum search php73 

配置文件位置:/etc/opt/remi/php73

设置php:

将php73链接到系统环境变量中,就可以使用 php -v

ln -s /opt/remi/php73/root/usr/bin/php /usr/bin/php

处理个漏洞,将 cgi.fix_pathinfo 设置为 0
sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/' /etc/opt/remi/php73/php.ini

 一些命令

php73 -v #查看版本
systemctl enable php73-php-fpm #开启开机自启
systemctl restart php73-php-fpm #重启
systemctl start php73-php-fpm #启动
systemctl stop php73-php-fpm #关闭
systemctl status php73-php-fpm #检查状态

ubuntu安装过程:

apt-get update
编译参数:
一:nginx1.14.2:
#安装依赖:gcc、g++依赖库
sudo apt-get install build-essential libtool
#支持重写,安装 pcre依赖库(http://www.pcre.org/)
sudo apt-get install libpcre3 libpcre3-dev
#安装 zlib依赖库(http://www.zlib.net)
sudo apt-get install zlib1g-dev zlib1g libssl-dev
#安装ssl依赖库
sudo apt-get install openssl openssl-devel

tar xvzf 
sudo ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
sudo make
sudo make install

二:mysql5.7.26
apt-get -y install libaio1 numactl libncurses5 #安装依赖
tar -xvf

#预配置执行
sudo dpkg-preconfigure mysql-community-server_*.deb 

如果有警告运行:sudo apt-get -f install

#依次执行
sudo dpkg -i mysql-common_*.deb
sudo dpkg -i mysql-community-client_*.deb
sudo dpkg -i mysql-client_*.deb
sudo dpkg -i mysql-community-server_*.deb

#启动
sudo service mysql start
#停止
sudo service mysql stop
#服务状态
sudo service mysql status

三:php7.2:

apt-get install -y libmcrypt-dev libxml2 libxml2-dev libbz2-dev libcurl4-gnutls-dev libwebp-dev libjpeg-dev libpng-dev libxpm-dev libfreetype6-dev libvpx-dev libcurl4-doc libidn11-dev libkrb5-dev libldap2-dev librtmp-dev libssh2-1-dev

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-bz2 --with-freetype-dir --with-iconv-dir --with-zlib-dir --enable-bcmath --enable-soap --enable-zip --enable-ftp --enable-mbstring --enable-exif --enable-ipv6 --with-zlib --with-curl --with-pdo-mysql --with-openssl --enable-fpm --with-mysqli

make && make install

# cp php.ini-development /usr/local/php/etc/php.ini
# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
# cp -R ./sapi/fpm/php-fpm /etc/init.d/php-fpm
# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf



最新评论:
我要评论:

看不清楚