Home > Backend Development > PHP7 > Detailed explanation of how to install PHP7+Nginx+MySQL under CentOS

Detailed explanation of how to install PHP7+Nginx+MySQL under CentOS

藏色散人
Release: 2023-02-17 13:54:01
forward
3463 people have browsed it

Detailed explanation of how to install PHP7+Nginx+MySQL under CentOS

This article takes centos6 as an example. The sudo command is omitted in the command part.

Install PHP

Download

http://cn2.php.net/distributions/php-5.6.22.tar.bz2
http://cn2.php.net/distributions/php-7.0.7.tar.bz2
Copy after login

Update yum source

Here, replace the Centos yum source with the domestic Alibaba Cloud source . If the yum installation is normal, you can skip this step.

Alibaba Cloud Linux installation image source address:

http://mirrors.aliyun.com/
Copy after login

1. Back up your original image file to avoid recovery after errors:

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
Copy after login

2 , Download the new CentOS-Base.repo to /etc/yum.repos.d/

## CentOS 5
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo
## CentOS 6
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
## CentOS 7
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
Copy after login

3. Generate cache

yum clean all
yum makecache
Copy after login

Install dependencies

yum install -y gcc gcc-c++ make cmake bison autoconf wget lrzsz
yum install -y libtool libtool-ltdl-devel 
yum install -y freetype-devel libjpeg.x86_64 libjpeg-devel libpng-devel gd-devel
yum install -y python-devel  patch  sudo 
yum install -y openssl* openssl openssl-devel ncurses-devel
yum install -y bzip* bzip2 unzip zlib-devel
yum install -y libevent*
yum install -y libxml* libxml2-devel
yum install -y libcurl* curl-devel 
yum install -y readline-devel
Copy after login

Need to compile libmcrypt, mhash, mcrypt library

tar zxvf /libmcrypt-2.5.8.tar.gz \
&& cd /libmcrypt-2.5.8 && ./configure && make && make install && cd - / && rm -rf /libmcrypt* \
&& tar zxvf /mhash-0.9.9.9.tar.gz && cd mhash-0.9.9.9 && ./configure && make && make install && cd - / && rm -rf /mhash* \
&& tar zxvf /mcrypt-2.6.8.tar.gz && cd mcrypt-2.6.8 && LD_LIBRARY_PATH=/usr/local/lib ./configure && make && make install && cd - / && rm -rf /mcrypt*
Copy after login

Start installation

Use ./configure --help to view the options supported by compilation. If you write an unsupported option, such as --with-mysql=mysqlnd, which is not supported in php7, you will be prompted:

configure: WARNING: unrecognized options: --with-mysql
Copy after login
wget http://cn2.php.net/distributions/php-7.0.7.tar.bz2
tar jxvf php-7.0.7.tar.bz2 
cd php-7.0.7
$ ./configure --prefix=/usr/local/php --with-config-file-scan-dir=/usr/local/php/etc/ --enable-inline-optimization --enable-opcache --enable-session --enable-fpm --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pdo-sqlite --with-sqlite3 --with-gettext --enable-mbregex --enable-mbstring --enable-xml --with-iconv --with-mcrypt --with-mhash --with-openssl --enable-bcmath --enable-soap --with-xmlrpc --with-libxml-dir --enable-pcntl --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-sockets --with-curl --with-curlwrappers --with-zlib --enable-zip --with-bz2 --with-gd --enable-gd-native-ttf --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-readline
 
$ make
$ make install
Copy after login

Optional:

--with-fpm-user=www --with-fpm-group=www
Copy after login

This is enabled Lots of extensions. If I forget to turn it on now, can I still add it later? The answer is yes. In the future, you only need to enter the ext directory of the source code. For example, if you forget pdo_mysql, enter ext/pdo_mysql, use the phpize tool, and generate pdo_mysql.so just like installing a normal extension.

About: --enable-safe-mode

If it is turned on, php can execute system functions. It is recommended to turn it off (you can search for php functions affected by this function)

#如果只需要配置某一个目录可以执行则 设置为on并指定 safe_mode_exec_dir=string目录来执行系统函数。
#本特性已自 PHP 5.3.0 起废弃并将自 PHP 5.4.0 起移除。
safe_mode = off
Copy after login

There is no need to add this configuration when compiling php7.

Compilation consumes more memory and CPU. Wait about half an hour for the compilation to be completed:

Build complete.
Don't forget to run 'make test'.
Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20151012/
Installing PHP CLI binary:        /usr/local/php/bin/
Installing PHP CLI man page:      /usr/local/php/php/man/man1/
Installing PHP FPM binary:        /usr/local/php/sbin/
Installing PHP FPM config:        /usr/local/php/etc/
Installing PHP FPM man page:      /usr/local/php/php/man/man8/
Installing PHP FPM status page:   /usr/local/php/php/php/fpm/
Installing phpdbg binary:         /usr/local/php/bin/
Installing phpdbg man page:       /usr/local/php/php/man/man1/
Installing PHP CGI binary:        /usr/local/php/bin/
Installing PHP CGI man page:      /usr/local/php/php/man/man1/
Installing build environment:     /usr/local/php/lib/php/build/
Installing header files:           /usr/local/php/include/php/
Installing helper programs:       /usr/local/php/bin/
  program: phpize
  program: php-config
Installing man pages:             /usr/local/php/php/man/man1/
  page: phpize.1
  page: php-config.1
Installing PEAR environment:      /usr/local/php/lib/php/
[PEAR] Archive_Tar    - installed: 1.4.0
[PEAR] Console_Getopt - installed: 1.4.1
[PEAR] Structures_Graph- installed: 1.1.1
[PEAR] XML_Util       - installed: 1.3.0
[PEAR] PEAR           - installed: 1.10.1
Wrote PEAR system config file at: /usr/local/php/etc/pear.conf
You may want to add: /usr/local/php/lib/php to your php.ini include_path
/php-7.0.7/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin
ln -s -f phar.phar /usr/local/php/bin/phar
Installing PDO headers:           /usr/local/php/include/php/ext/pdo/
[root@e8ed9b00e80c php-7.0.7]# /usr/local/php/bin/php -m
[PHP Modules]
bcmath
bz2
Core
ctype
curl
date
dom
fileinfo
filter
gd
gettext
hash
iconv
json
libxml
mbstring
mcrypt
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
readline
Reflection
session
shmop
SimpleXML
soap
sockets
SPL
sqlite3
standard
sysvmsg
sysvsem
sysvshm
tokenizer
xml
xmlreader
xmlrpc
xmlwriter
zip
zlib
[Zend Modules]
Copy after login

Configuration file

You need to copy php.ini and php-fpm.conf from the installation package to the installation directory:

$ cp php-7.0.7/php.ini* /usr/local/php/etc/
$ cd /usr/local/php/etc/
$ cp php.ini-production php.ini
$ cp php-fpm.conf.default  php-fpm.conf
$ cp php-fpm.d/www.conf.default php-fpm.d/www.conf
$ ls
pear.conf  php-fpm.conf.default  php.ini-development  php.ini-production
Copy after login

Configuration php.ini

# 不显示错误,默认
display_errors = Off
# 在关闭display_errors后开启PHP错误日志(路径在php-fpm.conf中配置),默认
log_errors = On
# 字符集,默认
default_charset = "UTF-8"
# 文件上传大小,默认值太小,建议修改10M
upload_max_filesize = 2M
# Maximum size of POST data that PHP will accept.  表单最大值,默认是8M,如果表单含有多图上传,大小可能不够。超过该大小后台收不到 表单数据
post_max_size = 8M  
# 设置PHP的扩展库路径,,默认被注释了。
extension_dir = "/usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/"
# 如果不设置extension_dir,也可以直接写绝对位置:
# extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20151012/redis.so
# 设置PHP的时区
date.timezone = PRC
# 开启opcache,默认是0
[opcache]
; Determines if Zend OPCache is enabled
opcache.enable=1
Copy after login

Configure php-fpm.conf

; 去掉里分号,方便以后重启。建议修改
; Default Value: none
; 下面的值最终目录是/usr/local/php/var/run/php-fpm.pid
; 开启后可以平滑重启php-fpm
pid = run/php-fpm.pid
; 设置错误日志的路径,可以默认值
; Note: the default prefix is /usr/local/php/var
; Default Value: log/php-fpm.log, 即/usr/local/php/var/log/php-fpm.log
error_log = /var/log/php-fpm/error.log
; Log等级,可以默认值
; Possible Values: alert, error, warning, notice, debug
; Default Value: notice
log_level = notice
; 后台运行,默认yes,可以默认值
; Default Value: yes
;daemonize = yes
; 引入www.conf文件中的配置,可以默认值
include=/usr/local/php/etc/php-fpm.d/*.conf
Copy after login

Configure www.conf (in the php-fpm.d directory)

www.conf This is php- Extended configuration file of fpm process service:

; 设置用户和用户组,默认都是nobody。可以默认值
user = nginx
group = nginx
; 设置PHP监听
; 下面是默认值,不建议使用。可以默认值
; listen = 127.0.0.1:9000
; 根据nginx.conf中的配置fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
listen = /var/run/php-fpm/php-fpm.sock
######开启慢日志。可以默认值
slowlog = /var/log/php-fpm/$pool-slow.log
request_slowlog_timeout = 10s
Copy after login

After saving the configuration file, the method to check whether the configuration is correct is:

/usr/local/php/sbin/php-fpm -t
Copy after login

If words such as test is successful appear, it means there is no problem with the configuration. In addition, this command can also let us know where the configuration file of php-fpm is.

Establish a soft connection:

ln -sf /usr/local/php/sbin/php-fpm /usr/bin/
ln -sf /usr/local/php/bin/php /usr/bin/
ln -sf /usr/local/php/bin/phpize /usr/bin/
ln -sf /usr/local/php/bin/php-config /usr/bin/
ln -sf /usr/local/php/bin/php-cig /usr/bin/
Copy after login

Or add the bin directory generated by php compilation to the environment variable of the current Linux system:

echo -e '\nexport PATH=/usr/local/php/bin:/usr/local/php/sbin:$PATH\n' >> /etc/profile && source /etc/profile
Copy after login

Start php-fpm

/usr/local/php/sbin/php-fpm
Copy after login

If it prompts that there is no www user (www.conf is filled with www instead of nobody), add:

useradd www
chown -R www:www /www
Copy after login

Check whether it is started:

ps aux |grep php-fpm # 另外该命令也可以让我们知道fpm的配置文件在哪。
netstat -ant |grep 9000
Copy after login

Check the number of php-fpm processes:

ps aux | grep -c php-fpm
Copy after login

php-fpm operation summary:

/usr/local/php/sbin/php-fpm         # php-fpm启动
kill -INT `cat /usr/local/php/var/run/php-fpm.pid`      # php-fpm关闭
kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid`         #php-fpm平滑重启
Copy after login

Restart method two:

killall php-fpm
/usr/local/php/sbin/php-fpm &
Copy after login

If it cannot start smoothly, then terminate the process id:

ps aux | grep php-fpm
kill -9  1210  #1210指php-fpm进程id
Copy after login

Installation Nginx

nginx news
http://nginx.org/
http://nginx.org/download/nginx-1.11.1.tar.gz
Copy after login

Dependencies:

# 为了支持rewrite功能,我们需要安装pcre
yum install pcre-devel
# 需要ssl的支持,如果不需要ssl支持,请跳过这一步
# yum install openssl*
# gzip 类库安装,按需安装
# yum install zlib zlib-devel
Copy after login

Configure compilation parameters

$ tar -zxvf nginx-1.11.1.tar.gz
$ cd nginx-1.11.1
$ ./configure \
    --prefix=/usr/local/nginx \
    --with-http_stub_status_module  \
    --with-http_ssl_module \
    --with-http_realip_module \
    --with-http_sub_module \
    --with-http_gzip_static_module \
    --with-pcre
Copy after login

Configure ok:

Configuration summary
  + using system PCRE library
  + using system OpenSSL library
  + md5: using OpenSSL library
  + sha1: using OpenSSL library
  + using system zlib library
  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx modules path: "/usr/local/nginx/modules"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"
Copy after login

Compile and install nginx

make
make install
Copy after login

Set soft connections :

ln -sf /usr/local/nginx/sbin/nginx /usr/sbin
Copy after login

Detect nginx:

nginx -t
Copy after login

Display:

nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
Copy after login

Successfully. Let’s reconfigure nginx.conf:

#user  nobody;
worker_processes  1;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#pid        logs/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    
    # 解决虚拟主机名字过长 http://www.jb51.net/article/26412.htm
    server_names_hash_bucket_size 128; 
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';
    #access_log  logs/access.log  main;
    sendfile        on;
    #tcp_nopush     on;
    #keepalive_timeout  0;
    keepalive_timeout  65;
    #gzip  on;
    
    autoindex on;# 显示目录
    autoindex_exact_size on;# 显示文件大小
    autoindex_localtime on;# 显示文件时间
    
    include vhosts/*.conf;
}
Copy after login

Configure localhost:

vhosts/localhost.conf
Copy after login
server {
    listen       80;
    server_name  localhost;
    #charset utf-8;
    #access_log  logs/host.access.log  main;
    location / {
        root   /www/www/;
        index  index.php index.html index.htm;
    }
    #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
    #
    location ~ \.php$ {
        root           /www/www/;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}
Copy after login

Start nginx:

/usr/local/nginx/sbin/nginx
# 或者
nginx
Copy after login

Restart:

/usr/local/nginx/sbin/nginx -s reload
# 或者
nginx -s reload
Copy after login

Stop:

/usr/local/nginx/sbin/nginx -s stop
# 或者
nginx -s stop
Copy after login

If you are prompted that port 80 is occupied, you can use ps aunx | grep 80 to check. Usually it is occupied by apache. You can use:

chkconfig --list
chkconfig nginx on
service apache off
Copy after login

to disable apache from starting and shut down the apache service.

Install extension

Install swoole

Swoole: PHP’s asynchronous, parallel, high-performance network communication engine

http://www.swoole.com/

wget https://github.com/swoole/swoole-src/archive/swoole-1.8.5-stable.zip
unzip swoole-1.8.5-stable.zip
cd swoole-1.8.5-stable
phpize
./configure
make && make install
Copy after login

Install redis

Server side:

http://download.redis.io/releases/redis-3.2.0.tar.gz

$ wget http://download.redis.io/releases/redis-3.2.0.tar.gz
$ tar xzf redis-3.2.0.tar.gz
$ cd redis-3.2.0
$ make
Copy after login

By default, it will be in the src directory of the current directory after compilation. You can copy the executable file to other places:

mkdir /usr/local/redis
cd src
cp  redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-sentinel redis-server redis-trib.rb /usr/local/redis
Copy after login

Copy the configuration file

$ cd redis-3.2.0
$ cp redis.conf /usr/local/redis/
Copy after login

or specify the location during installation:

make PREFIX=/usr/local/redis install
Copy after login

Add the directory where the Redis command is located to the system parameters In PATH:

Modify the profile file:

vi /etc/profile
Copy after login

Append in the last line:

export PATH="$PATH:/usr/local/redis/bin"
Copy after login

Then apply this file immediately:

. /etc/profile
Copy after login

This way you can call it directly The command of redis-cli is

Client:

2.0 installation

wget https://github.com/nicolasff/phpredis/archive/2.2.4.tar.gz
tar -zxvf 2.2.4
cd phpredis-2.2.4/
phpize
./configure 
make && make install
Copy after login

3.0 installation

phpredis/phpredis: A PHP extension for Redis
https://github.com/phpredis/phpredis
Copy after login

You need to install igbinary first:

PECL::Package::igbinary

http://pecl.php.net/package/igbinary

wget http://pecl.php.net/get/igbinary-1.2.1.tgz
tar zxvf igbinary-1.2.1.tgz
cd igbinary-1.2.1
phpize
./configure 
make && make install
Copy after login
wget https://github.com/phpredis/phpredis/archive/3.0.0-rc1.zip
unzip 3.0.0-rc1
cd phpredis-3.0.0-rc1/
phpize
./configure [--enable-redis-igbinary]
make && make install
Copy after login

Install memcache

pecl install memcache
Copy after login

There are compatibility issues with the installation of php7. I found an available one from github:

git clone https://github.com/websupport-sk/pecl-memcache memcache
cd memcache
phpize
./confihure
make
make install
Copy after login

Install memcached:

pecl install memcached
Copy after login

You need to first Installation:

yum install libmemcached-dev
Copy after login

Use yum/apt-get to install php

If you just want to quickly set up a development environment, you can use yum to install:

yum install php-cli php-devel php-common php-pear  php-gd php-fpm php-mbstring php-mcrypt php-mysql php-sqlite3 php-pdo php-memcache
Copy after login

Use yum search php to query Which PHP-related extensions can be installed.

If it is ubuntu:

sudo apt-get install php7.0-cli php7.0-dev php-pear php7.0-common  php7.0-pdo php7.0-curl php7.0-gd php-redis php-xdebug php-memcache php7.0-fpm  composer
Copy after login

You need to download the 15.9 MB archive.

After decompression, it will consume 57.7 MB of additional space.

Do you want to continue? [Y/n]

php-pear contains pecl, php-dev contains phpize, and pecl depends on phpize.

It should be noted that for php installed using yum, its configuration file is located at:

/etc/php.ini
/etc/php-fpm.conf
/etc/php-fpm.d/www.conf
/etc/php.d/mysqli.ini
/etc/php.d/pdo.ini
Copy after login

ubuntu is different from centos, and php.ini will be stored separately in /etc/php7/cli/php .ini and /etc/php7/fpm/php.ini. This needs attention.

Extensions that cannot be installed by yum can be installed using pecl. Since pecl needs to be compiled, you need to install the compiler first:

yum install -y gcc gcc-c++ make cmake bison autoconf
Copy after login

然后:

pecl install swoole
pecl install redis
Copy after login

pecl安装扩展完成后会提示添加so文件到php.ini。示例:

Build process completed successfully
Installing '/usr/lib64/php/modules/swoole.so'
install ok: channel://pecl.php.net/swoole-1.9.11
configuration option "php_ini" is not set to php.ini location
You should add "extension=swoole.so" to php.ini
Copy after login

添加示例:

[swoole]
extension = /usr/lib64/php/modules/swoole.so
Copy after login

使用php -m可以查看安装的扩展。

信号管理

不重载配置启动新/旧工作进程

kill -HUP 旧/新版主进程号
Copy after login

从容关闭旧/新进程

kill -QUIT 旧/新主进程号
Copy after login

如果此时报错,提示还有进程没有结束就用下面命令先关闭旧/新工作进程,再关闭主进程号:

kill -TERM 旧/新工作进程号
Copy after login

升级、添加或删除模块时,我们需要停掉服务器

kill -USR2 旧版程序的主进程号或进程文件名
Copy after login

MySQL

如果存在旧版本,需要先卸载旧版本。

使用下面的命令检查是否安装有MySQL Server

rpm -qa | grep mysql
Copy after login

有的话通过下面的命令来卸载掉

rpm -e mysql   //普通删除模式
rpm -e --nodeps mysql    // 强力删除模式,如果使用上面命令删除时,提示有依赖的其它文件,则用该命令可以对其进行强力删除
Copy after login

安装

安装编译代码需要的包

yum -y install make gcc-c++ cmake bison-devel  ncurses-devel
Copy after login

下载MySQL 5.6.14:

wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.14.tar.gz
tar xvf mysql-5.6.14.tar.gz
cd mysql-5.6.14
Copy after login

编译安装

cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci\
-DMYSQL_USER=mysql
make && make install
Copy after login

编译的参数可以参考

http://dev.mysql.com/doc/refman/5.5/en/source-configuration-options.html

整个过程需要30分钟左右……漫长的等待

配置MySQL

设置权限

使用下面的命令查看是否有mysql用户及用户组

cat /etc/passwd 查看用户列表
cat /etc/group  查看用户组列表
Copy after login

如果没有就创建

groupadd mysql
useradd -g mysql mysql
Copy after login

修改/usr/local/mysql权限

chown -R mysql:mysql /usr/local/mysql
Copy after login

修改/usr/local/mysql权限

初始化配置

进入安装路径

cd /usr/local/mysql
Copy after login

进入安装路径,执行初始化配置脚本,创建系统自带的数据库和表

scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
Copy after login

注:在启动MySQL服务时,会按照一定次序搜索my.cnf,先在/etc目录下找,找不到则会搜索"$basedir/my.cnf",在本例中就是 /usr/local/mysql/my.cnf,这是新版MySQL的配置文件的默认位置!

注意:在CentOS 6.4版操作系统的最小安装完成后,在/etc目录下会存在一个my.cnf,需要将此文件更名为其他的名字,如:/etc/my.cnf.bak,否则,该文件会干扰源码安装的MySQL的正确配置,造成无法启动。

在使用"yum update"更新系统后,需要检查下/etc目录下是否会多出一个my.cnf,如果多出,将它重命名成别的。否则,MySQL将使用这个配置文件启动,可能造成无法正常启动等问题。

启动MySQL

添加服务,拷贝服务脚本到init.d目录,并设置开机启动

cp support-files/mysql.server /etc/init.d/mysql
chkconfig mysql on
service mysql start  --启动MySQL
Copy after login

配置用户

MySQL启动成功后,root默认没有密码,我们需要设置root密码。

设置之前,我们需要先设置PATH,要不不能直接调用mysql

修改/etc/profile文件,在文件末尾添加

PATH=/usr/local/mysql/bin:$PATH
export PATH
Copy after login

关闭文件,运行下面的命令,让配置立即生效

source /etc/profile
Copy after login

现在,我们可以在终端内直接输入mysql进入,mysql的环境了

执行下面的命令修改root密码

mysql -uroot  
mysql> SET PASSWORD = PASSWORD('123456');
Copy after login

若要设置root用户可以远程访问,执行

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'172.16.%' IDENTIFIED BY 'password' WITH GRANT OPTION;
Copy after login

红色的password为远程访问时,root用户的密码,可以和本地不同。

配置防火墙

防火墙的3306端口默认没有开启,若要远程访问,需要开启这个端口

打开/etc/sysconfig/iptables

在“-A INPUT –m state --state NEW –m tcp –p –dport 22 –j ACCEPT”,下添加:

-A INPUT -m state --state NEW -m tcp -p -dport 3306 -j ACCEPT
Copy after login

然后保存,并关闭该文件,在终端内运行下面的命令,刷新防火墙配置:

service iptables restart
Copy after login

OK,一切配置完毕,你可以访问你的MySQL了~

注意:

CentOS 7中默认使用Firewalld做防火墙,所以修改iptables后,在重启系统后,根本不管用。

Firewalld中添加端口方法如下:

firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
Copy after login

常见问题

1、编译PHP提示easy.h should be in /include/curl/

如果是centos:

yum install curl curl-devel
Copy after login

如果是ubuntu:

apt-get install libcurl4-gnutls-dev
Copy after login

如果还是没有解决,直接编译curl:

wget http://curl.haxx.se/download/curl-7.37.0.tar.gz
tar zxvf curl-7.37.0.tar.gz
cd curl-7.37.0.
./configure --prefix=/usr/local --enable-shared 
make
make install
Copy after login

The above is the detailed content of Detailed explanation of how to install PHP7+Nginx+MySQL under CentOS. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template