linux下安裝php7+mysql5.7+nginx


環境:
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
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

如果通過Yum安裝不了libmcrypt的話,直接源碼編譯

1
2
3
4
5
6
tar zxvf libmcrypt-2.5.8. tar .gz
cd libmcrypt-2.5.8
. /configure
make
sudo make install

添加www用戶,php-fpm和nginx統一使用此用戶

1
2
sudo groupadd www
sudo useradd -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
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
 
chown -R root .
chown -R mysql data

這里使用“bin/mysqld --initialize”命令后,系統為root用戶自動分配了一個密碼,后面需要使用這個密碼登錄到mysql中,並重新修改成自己的密碼。

# 添加my.cnf配置文件

1
cp support-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
cp support-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
tar zxvf php-7.0.0. tar .gz
cd php-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
sudo make install

1.如果出現“configure: error: Don't know how to define struct flock on this system, set --enable-opcache=no”之類的錯誤,解決辦法如下:

1
2
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'

1
2
3
4
5
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

1
sudo vim /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-fpm start

然后查看是否有9000端口在監聽,有則表示OK.

1
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

1
2
3
4
5
6
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 ../
1
2
3
4
5
6
wget http: //tengine .taobao.org /download/tengine-2 .1.1. tar .gz
tar zxvf tengine-2.1.1. tar .gz
cd tengine-2.1.1
. /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后面的路徑

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

注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
粤ICP备14056181号  © 2014-2021 ITdaan.com