linux下安装php7+mysql5.7+nginx

来源:互联网 发布:ilust studio mac 编辑:程序博客网 时间:2024/05/17 10:54

环境:
CentOS7.1 X64
MySQL5.7.10
PHP7.0.0
Tengine/2.1.1 (nginx/1.6.2)

参考:http://blog.haohtml.com/archives/15340

一。安装常用扩展库

1
2
3
sudoyum -y installgcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-develbzip2bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers libevent libevent-devel libcurl libcurl-devel net-tools
 
sudoyum -y installlibmcrypt libmcrypt-devel

如果通过Yum安装不了libmcrypt的话,直接源码编译

1
2
3
4
5
6
wget -O libmcrypt-2.5.8.tar.gz"http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz?big_mirror=0"
tarzxvf libmcrypt-2.5.8.tar.gz
cdlibmcrypt-2.5.8
./configure
make
sudomake install

添加www用户,php-fpm和nginx统一使用此用户

1
2
sudogroupadd www
sudouseradd -g www www

===========================

一.  安装数据库 MySQL5.7.10

1
2
3
cd~/soft/
groupadd mysql
useradd-r -g mysql mysql
1
2
3
4
5
6
7
8
9
10
11
12
wget http://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.10-linux-glibc2.5-x86_64.tar.gz
tarzxvf mysql-5.7.10-linux-glibc2.5-x86_64.tar.gz
mvmysql-5.7.10-linux-glibc2.5-x86_64 /usr/local/mysql
cd/usr/local/mysql
chown-R mysql .
chgrp-R mysql .
 
bin/mysqld--initialize
2015-12-08T09:20:19.342869Z 1 [Note] A temporary password is generated forroot@localhost: wsOq8Khjue(2
 
chown-R root .
chown-R mysql data

这里使用“bin/mysqld --initialize”命令后,系统为root用户自动分配了一个密码,后面需要使用这个密码登录到mysql中,并重新修改成自己的密码。

# 添加my.cnf配置文件

1
cpsupport-files/my-default.cnf/etc/my.cnf

修改 vi /etc/my.cnf 文件,将socket文件位置修改如下

socket=/tmp/mysql.sock

# create mysql pid work dir

1
2
3
4
mkdir/var/run/mysqld/
chown-R mysql:mysql /var/run/mysqld/
 
bin/mysqld_safe--user=mysql &

# Next command is optional

1
cpsupport-files/mysql.server/etc/init.d/mysql.server

#使用上面系统自动的mysql密码登录

1
bin/mysql-u root -p

登录后,如果不修改密码的话,系统会提示

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

这里修改成自己的root密码

1
mysql>SET PASSWORD = PASSWORD('123456');

===========================
二. 安装php7

1
2
3
4
5
tarzxvf php-7.0.0.tar.gz
cdphp-7.0.0
./configure--prefix=/usr/local/php7--with-config-file-path=/usr/local/php7/etc--enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysqli --with-pdo-mysql --with-iconv-dir--with-freetype-dir--with-jpeg-dir--with-png-dir--with-zlib --with-libxml-dir=/usr--enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --enable-ftp--with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --disable-phar --with-gettext --disable-fileinfo --enable-maintainer-zts
make
sudomake install

1.如果出现“configure: error: Don't know how to define struct flock on this system, set --enable-opcache=no”之类的错误,解决办法如下:

1
2
sudosh -c 'echo "/usr/local/lib" >> /etc/ld.so.conf.d/local.conf'
sudosh -c ldconfig -v

2.如果提示“collect2: ld returned 1 exit status
make: *** [sapi/cli/php] Error 1

解决办法如下:

make ZEND_EXTRA_LIBS='-liconv'

1
2
3
4
5
sudocp php.ini-production /usr/local/php7/etc/php.ini
sudocp sapi/fpm/init.d.php-fpm/etc/init.d/php7-fpm
sudochmod +x /etc/init.d/php7-fpm
sudocp /usr/local/php7/etc/php-fpm.conf.default/usr/local/php7/etc/php-fpm.conf
sudocp /usr/local/php7/etc/php-fpm.d/www.conf.default/usr/local/php7/etc/php-fpm.d/www.conf

# 配置opcache

1
sudovim /usr/local/php7/etc/php.ini

# 加入

1
zend_extension=/usr/local/php7/lib/php/extensions/no-debug-zts-20151012/opcache.so

# 启动 (/usr/local/php7/sbin/php-fpm)

1
sudo/etc/init.d/php7-fpmstart

然后查看是否有9000端口在监听,有则表示OK.

1
netstat-an | grepLISTEN

查看PHP版本

[root@localhost php-7.0.0alpha1]# /usr/local/php7/bin/php -v
PHP 7.0.0 (cli) (built: Dec 8 2015 08:03:25) ( ZTS )
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies

 

对于nginx mysql的安装请参考下面网址

更多参考:http://blog.haohtml.com/tag/lnmp

------------------------

最近鸟哥于2015-6-12日又搞出来了一个高性能的配置管理扩展Yaconf ,目前只支持php7,如果感兴趣的话,可以试试,见:http://www.laruence.com/2015/06/12/3051.html

======================

安装NGINX

1
2
3
4
5
6
wgetftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.37.tar.gz
tarzxvf pcre-8.37.tar.gz
cdpcre-8.37
./configure
make&& sudomake install
cd../
1
2
3
4
5
6
wget http://tengine.taobao.org/download/tengine-2.1.1.tar.gz
tarzxvf tengine-2.1.1.tar.gz
cdtengine-2.1.1
./configure--user=www --group=www --prefix=/usr/local/nginx--with-http_stub_status_module --with-http_ssl_module
make&& sudomake install
cd../

修改 /usr/local/nginx/conf/nginx.conf,删除user nobody;行前面的注释,并修改为 user www www;
将以下几行前面的注释删除,将修改fastcgi_param后面的路径

1
2
3
4
5
6
7
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
include fastcgi_params;
}

测试nginx.conf配置文件

1
/usr/local/nginx/sbin/nginx-t

启用nginx

1
/usr/local/nginx/sbin/nginx

重新加载配置文件

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

测试是否支持php

1
vi/usr/local/nginx/html/phpinfo.php

输入内容

1
 <?php phpinfo();?>

浏览 http://ip/phpinfo.php ,可以看到php的相关信息,可以查看扩展是否支持.也可以使用命令行下输入

1
curl http://ip/phpinfo.php

检查。

五.全局配置

1
vi/etc/rc.local

按shift+g快捷键,在末尾增加以下内容:

1
ulimit-SHn 65535
0 0