Maison > développement back-end > PHP7 > le corps du texte

Explication détaillée de la façon d'installer PHP7+Nginx+MySQL sous CentOS

藏色散人
Libérer: 2023-02-17 13:54:01
avant
3406 Les gens l'ont consulté

Explication détaillée de la façon d'installer PHP7+Nginx+MySQL sous CentOS

Cet article utilise centos6 comme exemple. La commande sudo est omise dans la partie commande.

Installer PHP

Télécharger

http://cn2.php.net/distributions/php-5.6.22.tar.bz2
http://cn2.php.net/distributions/php-7.0.7.tar.bz2
Copier après la connexion

Mettre à jour la source yum

Ici, remplacez la source Centos yum par la source nationale Alibaba Cloud . Si l'installation de Yum est normale, vous pouvez ignorer cette étape.

Adresse source de l'image d'installation d'Alibaba Cloud Linux :

http://mirrors.aliyun.com/
Copier après la connexion

1 Sauvegardez votre fichier image d'origine pour éviter la récupération après des erreurs :

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
Copier après la connexion

2 , téléchargez le nouveau CentOS-Base.repo dans /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
Copier après la connexion

3. Générez le cache

yum clean all
yum makecache
Copier après la connexion

Installez les dépendances

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
Copier après la connexion

besoin de compiler libmcrypt, mhash, bibliothèque mcrypt

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*
Copier après la connexion

Démarrer l'installation

Utilisez ./configure --help pour afficher les options prises en charge par la compilation. Si vous écrivez une option non prise en charge, par exemple, --with-mysql=mysqlnd n'est pas pris en charge dans php7, le système affichera :

configure: WARNING: unrecognized options: --with-mysql
Copier après la connexion
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
Copier après la connexion

Facultatif :

--with-fpm-user=www --with-fpm-group=www
Copier après la connexion

De nombreuses extensions sont activées ici. Si j'oublie de l'activer maintenant, puis-je toujours l'ajouter plus tard ? La réponse est oui. À l'avenir, il vous suffira d'entrer le répertoire ext du code source. Par exemple, si vous oubliez pdo_mysql, entrez ext/pdo_mysql, utilisez l'outil phpize et générez pdo_mysql.so comme si vous installiez une extension normale.

À propos de : --enable-safe-mode

S'il est activé, php peut exécuter des fonctions système. Il est recommandé de le désactiver (vous pouvez rechercher les fonctions php affectées par cette fonction).

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

Il n'est pas nécessaire d'ajouter cette configuration lors de la compilation de php7.

La compilation consomme plus de mémoire et de CPU. Attendez environ une demi-heure que la compilation soit terminée :

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]
Copier après la connexion

Fichier de configuration

Vous devez copier php.ini et php-fpm.conf du package d'installation vers le répertoire d'installation :

$ 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
Copier après la connexion

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
Copier après la connexion

Configurer 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
Copier après la connexion

Configurer www.conf (dans le répertoire php-fpm.d)

www.conf Il s'agit de php - Fichier de configuration étendu du service de processus fpm :

; 设置用户和用户组,默认都是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
Copier après la connexion

Après avoir enregistré le fichier de configuration, la méthode pour vérifier si la configuration est correcte est :

/usr/local/php/sbin/php-fpm -t
Copier après la connexion

Si des mots tels que le test est réussi apparaît, cela signifie qu'il n'y a aucun problème avec la configuration. De plus, cette commande peut également nous indiquer où se trouve le fichier de configuration de php-fpm.

Établissez une connexion logicielle :

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/
Copier après la connexion

Ou ajoutez le répertoire bin généré par la compilation php à la variable d'environnement du système Linux actuel :

echo -e '\nexport PATH=/usr/local/php/bin:/usr/local/php/sbin:$PATH\n' >> /etc/profile && source /etc/profile
Copier après la connexion

Démarrez php-fpm

/usr/local/php/sbin/php-fpm
Copier après la connexion

S'il indique qu'il n'y a pas d'utilisateur www (www.conf est rempli avec www au lieu de personne), ajoutez :

useradd www
chown -R www:www /www
Copier après la connexion

Vérifiez s'il est démarré :

ps aux |grep php-fpm # 另外该命令也可以让我们知道fpm的配置文件在哪。
netstat -ant |grep 9000
Copier après la connexion

Vérifiez le nombre de processus php-fpm :

ps aux | grep -c php-fpm
Copier après la connexion

résumé de l'opération php-fpm :

/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平滑重启
Copier après la connexion

Redémarrez la deuxième méthode :

killall php-fpm
/usr/local/php/sbin/php-fpm &
Copier après la connexion

S'il ne peut pas démarrer correctement, terminez l'identifiant du processus :

ps aux | grep php-fpm
kill -9  1210  #1210指php-fpm进程id
Copier après la connexion

Installation Nginx

nginx news
http://nginx.org/
http://nginx.org/download/nginx-1.11.1.tar.gz
Copier après la connexion

Dépendance :

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

Configurer les paramètres de compilation

$ 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
Copier après la connexion

Configurer 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"
Copier après la connexion

Compiler et installer nginx

make
make install
Copier après la connexion

Définir une connexion logicielle :

ln -sf /usr/local/nginx/sbin/nginx /usr/sbin
Copier après la connexion

La détection de nginx :

nginx -t
Copier après la connexion

affiche :

nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
Copier après la connexion

avec succès. On 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;
}
Copier après la connexion

Configurer localhost :

vhosts/localhost.conf
Copier après la connexion
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;
    }
}
Copier après la connexion

Démarrer nginx :

/usr/local/nginx/sbin/nginx
# 或者
nginx
Copier après la connexion

Redémarrer :

/usr/local/nginx/sbin/nginx -s reload
# 或者
nginx -s reload
Copier après la connexion

Arrêter :

/usr/local/nginx/sbin/nginx -s stop
# 或者
nginx -s stop
Copier après la connexion

S'il indique que le port 80 est occupé, vous pouvez utiliser ps aunx | grep 80 pour vérifier. Habituellement, il est occupé par Apache. Vous pouvez utiliser :

chkconfig --list
chkconfig nginx on
service apache off
Copier après la connexion

pour désactiver le démarrage d'Apache et arrêter le service Apache.

Installer l'extension

Installer swoole

Swoole : le moteur de communication réseau asynchrone, parallèle et hautes performances de PHP

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
Copier après la connexion

Installer redis

Côté serveur :

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
Copier après la connexion

Par défaut, il sera dans le répertoire src du répertoire courant après compilation. Vous pouvez copier le fichier exécutable à d'autres endroits :

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
Copier après la connexion

Copiez le fichier de configuration

$ cd redis-3.2.0
$ cp redis.conf /usr/local/redis/
Copier après la connexion

ou précisez l'emplacement lors de l'installation :

make PREFIX=/usr/local/redis install
Copier après la connexion

Ajoutez le répertoire où se trouve la commande Redis situé dans les paramètres système Dans PATH :

Modifier le fichier de profil :

vi /etc/profile
Copier après la connexion

Ajouter en dernière ligne :

export PATH="$PATH:/usr/local/redis/bin"
Copier après la connexion

puis appliquer immédiatement ce fichier :

. /etc/profile
Copier après la connexion

De cette façon, vous pouvez l'appeler directement La commande de redis-cli est

Client :

Installation 2.0

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
Copier après la connexion

Installation 3.0

phpredis/phpredis: A PHP extension for Redis
https://github.com/phpredis/phpredis
Copier après la connexion

Vous devez d'abord installer igbinary :

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
Copier après la connexion
rrree

Installer memcache

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
Copier après la connexion

Il y a des problèmes de compatibilité avec l'installation de php7. J'en ai trouvé un disponible sur github :

pecl install memcache
Copier après la connexion

Installer. memcached :

git clone https://github.com/websupport-sk/pecl-memcache memcache
cd memcache
phpize
./confihure
make
make install
Copier après la connexion

Vous devez d'abord installer :

pecl install memcached
Copier après la connexion

Utilisez yum/apt-get pour installer php

Si vous souhaitez simplement mettre en place rapidement un développement environnement, vous pouvez utiliser yum pour installer :

yum install libmemcached-dev
Copier après la connexion

Utilisez yum search php pour demander quelles extensions liées à PHP peuvent être installées.

Si Ubuntu :

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
Copier après la connexion

Besoin de télécharger une archive de 15,9 Mo.

Utilise 57,7 Mo d'espace supplémentaire après décompression.

Voulez-vous continuer ? [O/n]

php-pear contient pecl, php-dev contient phpize et pecl dépend de phpize.

Il est à noter que pour php installé avec yum, son fichier de configuration se trouve à l'adresse :

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
Copier après la connexion

Ubuntu est différent de centos, et php.ini sera stocké séparément dans /etc/php7 /cli/php.ini et /etc/php7/fpm/php.ini. Cela nécessite une attention particulière.

Les extensions qui ne peuvent pas être installées par yum peuvent être installées en utilisant pecl. Puisque pecl doit être compilé, vous devez d'abord installer le compilateur :

yum install -y gcc gcc-c++ make cmake bison autoconf
Copier après la connexion

然后:

pecl install swoole
pecl install redis
Copier après la connexion

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
Copier après la connexion

添加示例:

[swoole]
extension = /usr/lib64/php/modules/swoole.so
Copier après la connexion

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

信号管理

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

kill -HUP 旧/新版主进程号
Copier après la connexion

从容关闭旧/新进程

kill -QUIT 旧/新主进程号
Copier après la connexion

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

kill -TERM 旧/新工作进程号
Copier après la connexion

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

kill -USR2 旧版程序的主进程号或进程文件名
Copier après la connexion

MySQL

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

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

rpm -qa | grep mysql
Copier après la connexion

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

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

安装

安装编译代码需要的包

yum -y install make gcc-c++ cmake bison-devel  ncurses-devel
Copier après la connexion

下载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
Copier après la connexion

编译安装

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
Copier après la connexion

编译的参数可以参考

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

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

配置MySQL

设置权限

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

cat /etc/passwd 查看用户列表
cat /etc/group  查看用户组列表
Copier après la connexion

如果没有就创建

groupadd mysql
useradd -g mysql mysql
Copier après la connexion

修改/usr/local/mysql权限

chown -R mysql:mysql /usr/local/mysql
Copier après la connexion

修改/usr/local/mysql权限

初始化配置

进入安装路径

cd /usr/local/mysql
Copier après la connexion

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

scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
Copier après la connexion

注:在启动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
Copier après la connexion

配置用户

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

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

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

PATH=/usr/local/mysql/bin:$PATH
export PATH
Copier après la connexion

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

source /etc/profile
Copier après la connexion

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

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

mysql -uroot  
mysql> SET PASSWORD = PASSWORD('123456');
Copier après la connexion

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

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'172.16.%' IDENTIFIED BY 'password' WITH GRANT OPTION;
Copier après la connexion

红色的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
Copier après la connexion

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

service iptables restart
Copier après la connexion

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

注意:

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

Firewalld中添加端口方法如下:

firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
Copier après la connexion

常见问题

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

如果是centos:

yum install curl curl-devel
Copier après la connexion

如果是ubuntu:

apt-get install libcurl4-gnutls-dev
Copier après la connexion

如果还是没有解决,直接编译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
Copier après la connexion

Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!

Étiquettes associées:
source:cnblogs.com
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!