当前位置:Gxlcms > 数据库问题 > centOS7 安装nginx+php+mysql

centOS7 安装nginx+php+mysql

时间:2021-07-01 10:21:17 帮助过:12人阅读

PHP-FPM是一个PHP FastCGI管理器,是只用于PHP的,可以在 http://php-fpm.org/download下载得到.

PHP-FPM其实是PHP源代码的一个补丁,旨在将FastCGI进程管理整合进PHP包中。必须将它patch到你的PHP源代码中,在编译安装PHP后才可以使用。

新版PHP已经集成php-fpm了,不再是第三方的包了,推荐使用。PHP-FPM提供了更好的PHP进程管理方式,可以有效控制内存和进程、可以平滑重载PHP配置,比spawn-fcgi具有更多优点,所以被PHP官方收录了。在./configure的时候带 –enable-fpm参数即可开启PHP-FPM,其它参数都是配置php的,具体选项含义可以查看这里。

安装前准备
centos下执行

1 yum -y install gcc gcc-c++ glibc
yum -y install libmcrypt-devel mhash-devel libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel
技术分享图片
 1 cd /usr/local/src
 2 wget http://php.net/get/php-5.6.27.tar.gz/from/a/mirror
 3 tar -zvxf mirror
 4 cd php-5.6.27
 5 
 6 ./configure --prefix=/usr/local/php  --enable-fpm --with-mcrypt  7 --enable-mbstring --enable-pdo --with-curl --disable-debug  --disable-rpath  8 --enable-inline-optimization --with-bz2  --with-zlib --enable-sockets  9 --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex 10 --with-mhash --enable-zip --with-pcre-regex --with-mysql --with-mysqli 11 --with-gd --with-jpeg-dir --with-freetype-dir --enable-calendar
技术分享图片

以上就完成了php-fpm的安装

下面是对php-fpm运行用户进行设置

1、为php提供配置文件

1 cp php.ini-production /usr/local/php/lib/php.ini

2、为php-fpm提供配置文件

 

1 cd /usr/local/php
2 cp etc/php-fpm.conf.default etc/php-fpm.conf
3 vim etc/php-fpm.conf

修改
user = www-data
group = www-data

如果www-data用户不存在,那么先添加www-data用户

1 groupadd www-data
2 useradd -g www-data www-data
修改 pm.max_children = 150 pm.start_servers = 8 pm.min_spare_servers = 5 pm.max_spare_servers = 10 pid = /usr/local/php/var/run/php-fpm.pid 

3、启动php-fpm

执行

1 /usr/local/php/sbin/php-fpm
使用如下命令来验正(如果此命令输出有中几个php-fpm进程就说明启动成功了):
1 ps aux | grep php-fpm

3、nginx和php-fpm整合

编辑/usr/local/nginx/nginx.conf

1 vim /usr/local/nginx/nginx.conf

修改如下:

红框中“#”号去掉

技术分享图片

红框中“#”号去掉

技术分享图片

添加红框中内容

技术分享图片

改成如下

技术分享图片

重新载入nginx的配置文件:

1 /usr/loca/nginx/sbin/nginx -s reload

4、测试php文件

 在/usr/local/nginx/html下创建index.php文件,输入如下内容

1 <?php
2     phpinfo();
3 ?>

5、浏览器访问

访问http://你的服务器ip/index.php,皆可以见到php信息了。

技术分享图片


安装Mysql5.7(解压缩版)

#### 1、下载安装包 
http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.16-linux-glibc2.5-x86_64.tar
推荐下载通用安装方法的TAR包

2.检查库文件是否存在,如有删除。

[root@localhost Desktop]$ rpm -qa | grep mysql
mysql-libs-5.1.52-1.el6_0.1.x86_64
[root@localhost ~]$ rpm -e mysql-libs-5.1.52.x86_64 --nodeps
[root@localhost ~]$

3.检查mysql组和用户是否存在,如无创建。

[root@localhost ~]$ cat /etc/group | grep mysql
mysql:x:490:
[root@localhost ~]$ cat /etc/passwd | grep mysql
mysql:x:496:490::/home/mysql:/bin/bash

以上为默认存在的情况,如无,执行添加命令:

[root@localhost ~]$groupadd mysql
[root@localhost ~]$useradd -r -g mysql mysql
//useradd -r参数表示mysql用户是系统用户,不可用于登录系统。

4.解压TAR包,更改所属的组和用户

[root@localhost ~]$ cd /usr/local/
[root@localhost local]$ tar xvf mysql-5.7.12-linux-glibc2.5-x86_64.tar
[root@localhost local]$ ls -l
total 1306432
-rwxr--r--. 1 root root  668866560 Jun  1 15:07 mysql-5.7.12-linux-glibc2.5-x86_64.tar
-rw-r--r--. 1 7161 wheel 638960236 Mar 28 12:54 mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz
-rw-r--r--. 1 7161 wheel  29903372 Mar 28 12:48 mysql-test-5.7.12-linux-glibc2.5-x86_64.tar.gz
[root@localhost local]$ tar xvfz mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz
[root@localhost local]$ mv mysql-5.7.12-linux-glibc2.5-x86_64 mysql
[root@localhost local]$ ls -l
total 1306436
drwxr-xr-x. 2 root root       4096 Dec  4  2009 bin
drwxr-xr-x. 2 root root       4096 Dec  4  2009 etc
drwxr-xr-x. 2 root root       4096 Dec  4  2009 games
drwxr-xr-x. 2 root root       4096 Dec  4  2009 include
drwxr-xr-x. 2 root root       4096 Dec  4  2009 lib
drwxr-xr-x. 3 root root       4096 Dec  2 14:36 lib64
drwxr-xr-x. 2 root root       4096 Dec  4  2009 libexec
drwxr-xr-x. 9 7161 wheel      4096 Mar 28 12:51 mysql
-rwxr--r--. 1 root root  668866560 Jun  1 15:07 mysql-5.7.12-linux-glibc2.5-x86_64.tar
-rw-r--r--. 1 7161 wheel 638960236 Mar 28 12:54 mysql-5.7.12-linux-glibc2.5-x86_64.tar.gz
-rw-r--r--. 1 7161 wheel  29903372 Mar 28 12:48 mysql-test-5.7.12-linux-glibc2.5-x86_64.tar.gz
drwxr-xr-x. 2 root root       4096 Dec  4  2009 sbin
drwxr-xr-x. 6 root root       4096 Dec  2 14:36 share
drwxr-xr-x. 2 root root       4096 Dec  4  2009 src
[root@localhost local]$ chown -R mysql mysql/
[root@localhost local]$ chgrp -R mysql mysql/
[root@localhost local]$ cd mysql/

5.安装和初始化数据库

[root@localhost mysql]$ bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
2016-06-01 15:23:25 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2016-06-01 15:23:30 [WARNING] The bootstrap log isn‘t empty:
2016-06-01 15:23:30 [WARNING] 2016-06-01T22:23:25.491840Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead
2016-06-01T22:23:25.492256Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2016-06-01T22:23:25.492260Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)

如果改变默认安装路径,则需要  1)/etc/my.cnf、/etc/init.d/mysqld中修改  basedir=’/apps/mysql’  datadir=’/apps/mysql/data’  2)创建ln  mkdir -p /usr/local/mysql/bin  ln -s /apps/mysql/bin/mysqld /usr/local/mysql/bin/mysqld


[root@localhost mysql]$

[root@localhost mysql]$ cp -a ./support-files/my-default.cnf /etc/my.cnf
[root@localhost mysql]$ cp -a ./support-files/mysql.server  /etc/init.d/mysqld
[root@localhost mysql]$ cd bin/
[root@localhost bin]# ./mysqld_safe --user=mysql &
[1] 2932
[root@localhost bin]# 2016-06-01T22:27:09.708557Z mysqld_safe Logging to ‘/usr/local/mysql/data/localhost.localdomain.err‘.
2016-06-01T22:27:09.854913Z mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
[root@localhost bin]# /etc/init.d/mysqld restart
Shutting down MySQL..2016-06-01T22:27:50.498694Z mysqld_safe mysqld from pid file /usr/local/mysql/data/localhost.localdomain.pid ended
 SUCCESS! 
Starting MySQL. SUCCESS! 
[1]+  Done                    ./mysqld_safe --user=mysql
[root@localhost bin]$ 
//设置开机启动
[root@localhost bin]$ chkconfig --level 35 mysqld on
[root@localhost bin]$

6.初始化密码

mysql5.7会生成一个初始化密码,而在之前的版本首次登陆不需要登录。

[root@localhost bin]$ cat /root/.mysql_secret 
# Password set for user ‘root@localhost‘ at 2016-06-01 15:23:25 
,xxxxxR5H9
[root@localhost bin]$./mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.12

Copyright (c) 2000, 2016, 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> SET PASSWORD = PASSWORD(‘123456‘);
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

7.添加远程访问权限

mysql> use mysql; 
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A


Database changed
mysql> update user set host = ‘%‘ where user = ‘root‘;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0


mysql> select host, user from user;
+-----------+-----------+
| host      | user      |
+-----------+-----------+
| %         | root      |
| localhost | mysql.sys |
+-----------+-----------+
//重启生效
/etc/init.d/mysqld restart

【 引用】

https://www.cnblogs.com/flywind/p/6019631.html

centOS7 安装nginx+php+mysql

标签:vim   title   web服务   http服务   ogg   centos   准备   注意   pidfile   

人气教程排行