linux下安装php7+mysql5.7+nginx

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

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

一。安装常用扩展库

sudo yum -y install gcc gcc-c++ autoconf 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 libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers libevent libevent-devel libcurl libcurl-devel net-tools

sudo yum -y install libmcrypt libmcrypt-devel libaio

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

wget -O libmcrypt-2.5.8.tar.gz "http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz?big_mirror=0"
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make
sudo make install

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

sudo groupadd www
sudo useradd -g www www

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

一.  安装数据库 MySQL5.7.10

cd ~/soft/
groupadd mysql
useradd -g mysql -d /usr/local/mysql -s /sbin/nologin mysql

wget http://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.10-linux-glibc2.5-x86_64.tar.gz
tar zxvf mysql-5.7.10-linux-glibc2.5-x86_64.tar.gz
mv mysql-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 for root@localhost: wsOq8Khjue(2

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

# 添加my.cnf配置文件

cp support-files/my-default.cnf /etc/my.cnf

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

socket=/tmp/mysql.sock

#将MySQL作成系统服务

cp support-files/mysql.server /etc/init.d/mysqld

#把msql的脚本文件拷到系统的启动目录下

cd /etc/init.d/
chkconfig --add mysqld
chkconfig mysqld on #让系统启动时自动打开mysql服务,如果指定级别,用--level参数

#为了使用mysql命令方便,我们直接将/usr/local/mysql/bin目录添加到环境变量 $PATH中

echo "export PATH=$PATH:/usr/local/mysql/bin">>/etc/profile
source /etc/profile
mysql -u root -p

输入上面自动生成的随机密码。登录后,如果不修改密码的话,系统会提示

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

这里修改成自己的root密码(alter user user() identified by '123456')

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

对于mysql 的启动还有另一种方式就是使用 bin/mysqld_safe --user=mysql & 命令,这种方法会使用子进程的方式出现,当kill它的进程号时,会自动又产生一个新的进程号。这所以不使用这种方式启动,是为了尽早发现mysql的问题,避免出现如有表损坏的情况下情况下仍然提供服务而出现严重的问题。(Linux下安装MySQL多实例: http://blog.haohtml.com/archives/17300 )

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

tar zxvf php-7.0.4.tar.gz
cd php-7.0.4
./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
sudo make install

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

sudo sh -c 'echo "/usr/local/lib" >> /etc/ld.so.conf.d/local.conf'
sudo sh -c ldconfig -v

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

解决办法如下:

make ZEND_EXTRA_LIBS='-liconv'

sudo cp php.ini-production /usr/local/php7/etc/php.ini
sudo cp sapi/fpm/init.d.php-fpm /etc/init.d/php7-fpm
sudo chmod +x /etc/init.d/php7-fpm
sudo cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
sudo cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf

# 配置opcache

sudo vim /usr/local/php7/etc/php.ini

# 加入

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

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

sudo /etc/init.d/php7-fpm start

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

netstat -an | grep LISTEN

查看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

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.37.tar.gz
tar zxvf pcre-8.37.tar.gz
cd pcre-8.37
./configure
make && sudo make install
cd ../
wget http://tengine.taobao.org/download/tengine-2.1.2.tar.gz
tar zxvf tengine-2.1.2.tar.gz
cd tengine-2.1.2
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make && sudo make install
cd ../

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

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配置文件

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

启用nginx

/usr/local/nginx/sbin/nginx

重新加载配置文件

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

测试是否支持php

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

输入内容

 <?php phpinfo();?>

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

curl http://ip/phpinfo.php

检查。

五.全局配置

vi /etc/rc.local

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

ulimit -SHn 65535

六. 安装常用PHP扩展
Redis: https://github.com/phpredis/phpredis#installation
Swoole https://github.com/swoole/swoole-src