基础准备
yum provides ifconfig
yum install -y net-tools vim wget unzip
工具安装(gcc-c++在编译libmcrypt时用到)
yum install -y make \
gcc \
gcc-c++ \
autoconf \
cmake \
libxml2-devel \
openssl-devel \
bzip2-devel \
libcurl-devel \
libpng-devel \
libjpeg-turbo-devel \
libwebp-devel \
libXpm-devel \
freetype-devel \
gmp-devel \
unixODBC-devel \
readline-devel \
net-snmp-devel \
expat-devel \
libxslt-devel
ln -s /usr/lib64/libexpat.* /usr/lib/
mkdir -p /data/soft
cd /data/soft
wget -c http://cn2.php.net/distributions/php-7.1.4.tar.gz
tar zxvf php-7.1.4.tar.gz
cd /data/soft
wget -c https://github.com/htacg/tidy-html5/archive/master.zip -O tidy-html5.zip
unzip tidy-html5.zip -d tidy-html5
cd tidy-html5/tidy-html5-master/
cd build/cmake/
cmake ../..
make
make install
cd ../../../../
如果要编译到PHP里,还要cd 到PHP的目录代码把ext/tidy/*.c的代码里的 "buffio.h" 转成 "tidybuffio.h"
cd /data/soft/php-7.1.4/
sed -i 's/buffio.h/tidybuffio.h/' ext/tidy/*.c
centos源不能安装libmcrypt-devel,由于版权的原因没有自带mcrypt的包
wget -c http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz/download -O ./libmcrypt-2.5.8.tar.gz
编译
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8/
./configure
make
make install
/sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install
make
make install
cd ../../
正式编译
php -i |grep ini
编译的php.ini的默认位置是指定目录下的
cd php-7.1.4
./configure --sysconfdir=/etc --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx \
--enable-bcmath \
--enable-calendar \
--enable-exif \
--enable-ftp \
--enable-mbstring \
--enable-pcntl \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sysvsem --enable-sysvshm --enable-sysvmsg \
--enable-wddx --with-libexpat-dir \
--enable-zip \
--with-bz2 \
--with-curl \
--with-zlib \
--with-gd --with-jpeg-dir --with-png-dir --with-zlib-dir --with-webp-dir --with-xpm-dir --with-freetype-dir \
--with-gettext \
--with-gmp \
--with-mcrypt \
--with-mhash \
--with-unixODBC=/usr \
--with-pdo-odbc=unixODBC,/usr \
--with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd \
--with-openssl \
--with-readline \
--with-snmp \
--with-tidy \
--with-xmlrpc \
--with-xsl \
--with-freetype-dir \
--enable-opcache
pthreads (需要线程安全支持)
要使用 pthreads 扩展,需要构建 PHP 时启用 ZTS (Zend Thread Safety)。(--enable-maintainer-zts 选项, Windows 平台为 --enable-zts)
编译安装
make
make install
Installing shared extensions: /usr/local/lib/php/extensions/no-debug-non-zts-20160303/
Installing PHP CLI binary: /usr/local/bin/
Installing PHP CLI man page: /usr/local/php/man/man1/
Installing PHP FPM binary: /usr/local/sbin/
Installing PHP FPM defconfig: /etc/
Installing PHP FPM man page: /usr/local/php/man/man8/
Installing PHP FPM status page: /usr/local/php/php/fpm/
Installing phpdbg binary: /usr/local/bin/
Installing phpdbg man page: /usr/local/php/man/man1/
Installing PHP CGI binary: /usr/local/bin/
Installing PHP CGI man page: /usr/local/php/man/man1/
Installing build environment: /usr/local/lib/php/build/
Installing header files: /usr/local/include/php/
Installing helper programs: /usr/local/bin/
program: phpize
program: php-config
Installing man pages: /usr/local/php/man/man1/
page: phpize.1
page: php-config.1
Installing PEAR environment: /usr/local/lib/php/
[PEAR] Archive_Tar - already installed: 1.4.2
[PEAR] Console_Getopt - already installed: 1.4.1
[PEAR] Structures_Graph- already installed: 1.1.1
[PEAR] XML_Util - already installed: 1.4.2
[PEAR] PEAR - already installed: 1.10.3
Wrote PEAR system config file at: /etc/pear.conf
You may want to add: /usr/local/lib/php to your php.ini include_path
/data/soft/php-7.1.4/build/shtool install -c ext/phar/phar.phar /usr/local/bin
ln -s -f phar.phar /usr/local/bin/phar
Installing PDO headers: /usr/local/include/php/ext/pdo/
需要pecl安装的扩展
https://github.com/php7-extensions 有较多php7扩展
memcache
memcached
redis
igbinary
imagick
xhprof
memcache 有github包
cd /data/soft
wget -c https://codeload.github.com/websupport-sk/pecl-memcache/zip/NON_BLOCKING_IO_php7 -O pecl-memcache.zip
unzip pecl-memcache.zip
cd pecl-memcache-NON_BLOCKING_IO_php7/
/data/server/php7/bin/phpize
./configure --with-php-config=/data/server/php7/bin/php-config
make
make install
cd ../
memcached 原生支持
wget -c https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz
tar zxvf libmemcached-1.0.18.tar.gz
cd libmemcached-1.0.18
./configure
make
make install
cd ../
wget -c http://pecl.php.net/get/memcached-3.0.3.tgz
tar zxvf memcached-3.0.3.tgz
cd memcached-3.0.3
phpize
./configure --with-php-config=php-config --disable-memcached-sasl
make
make install
cd ../
redis 原生支持
wget -c http://pecl.php.net/get/redis-3.1.2.tgz
tar zxvf redis-3.1.2.tgz
cd redis-3.1.2
phpize
./configure --with-php-config=php-config
make
make install
cd ../
igbinary 原生支持
wget -c http://pecl.php.net/get/igbinary-2.0.1.tgz
tar zxvf igbinary-2.0.1.tgz
cd igbinary-2.0.1
phpize
./configure --with-php-config=php-config
make
make install
cd ../
imagick 原生这个也可以用 也有github包
安装ImageMagick
wget -c ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick.tar.gz
tar zxvf ImageMagick.tar.gz
# 这个名字会变
cd ImageMagick-6.9.1-0/
./configure
make
make install
cd ../
wget -c http://pecl.php.net/get/imagick-3.4.3.tgz
tar zxvf imagick-3.4.3.tgz
cd imagick-3.4.3
phpize
./configure --with-php-config=php-config
make
make install
cd ../
swoole 原生支持
wget -c http://pecl.php.net/get/swoole-1.9.9.tgz
tar zxvf swoole-1.9.9.tgz
cd swoole-1.9.9
phpize
./configure --with-php-config=php-config
make
make install
cd ../
xhprof 原生暂时没有pecl包,https://github.com/Yaoguais/phpng-xhprof 目前可以用
wget -c https://codeload.github.com/Yaoguais/phpng-xhprof/zip/master -O phpng-xhprof.zip
unzip phpng-xhprof.zip
cd phpng-xhprof-master
phpize
./configure --with-php-config=php-config
make
make install
cd ../
PHP配置
在PHP源码目录下
cd /data/soft/php-7.1.4
cp php.ini-production /etc/php.ini
cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/php-fpm.service
cp /etc/php-fpm.conf.default /etc/php-fpm.conf
cp /etc/php-fpm.d/www.conf.default /etc/php-fpm.d/www.conf
mkdir -p /etc/php.d
vim /etc/php.ini
;expose_php = On
expose_php = Off
;short_open_tag = Off
short_open_tag = On
post_max_size = 30M
upload_max_filesize = 30M
date.timezone = Asia/Shanghai
编辑完保存
echo -e "[opcache]\nzend_extension=opcache.so\nopcache.enable=1\nopcache.enable_cli=1" > /etc/php.d/opcache.ini
echo "extension=igbinary.so" > /etc/php.d/igbinary.ini
echo "extension=imagick.so" > /etc/php.d/imagick.ini
echo "extension=memcached.so" > /etc/php.d/memcached.ini
echo "extension=memcache.so" > /etc/php.d/memcache.ini
echo "extension=redis.so" > /etc/php.d/redis.ini
echo "extension=swoole.so" > /etc/php.d/swoole.ini
echo "extension=phpng_xhprof.so" > /etc/php.d/phpng_xhprof.ini
php -m |grep -E "OPcache|igbinary|imagick|memcache|memcached|redis|xhprof|swoole"
php -v看一下
PHP 7.1.4 (cli) (built: Aug 11 2016 02:14:40) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.1.4, Copyright (c) 1999-2016, by Zend Technologies
vim /etc/php-fpm.d/www.conf
把php-fpm产生的文件用户组改成nginx
user = nginx
group = nginx
如果小内存设置为动态,如果是公司内存大,设置static可以在高并发有不错的表现
pm = static
pm.max_children = 128 (内存量/30) 4G 64/128 8G 128/256
; listen = 127.0.0.1:9000
listen = /var/run/php-fpm.sock
; 如果用上面这个 nginx要如下配置
; fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
;request_slowlog_timeout = 0
;request_slowlog_timeout = 1s
;slowlog = /var/log/php-fpm/www-slow.log
;connect() to unix:/data/server/php7/var/run/php-fpm.sock failed (13: Permission denied) 开启下面几行
listen.owner = nginx
listen.group = nginx
listen.mode = 0660
systemctl enable php-fpm
systemctl start php-fpm
php -m 如下扩展
[PHP Modules]
bcmath
bz2
calendar
Core
ctype
curl
date
dom
exif
fileinfo
filter
ftp
gd
gettext
gmp
hash
iconv
igbinary
imagick
json
libxml
mbstring
mcrypt
memcache
memcached
mysqli
mysqlnd
odbc
openssl
pcntl
pcre
PDO
pdo_mysql
PDO_ODBC
pdo_sqlite
Phar
posix
readline
redis
Reflection
session
shmop
SimpleXML
snmp
soap
sockets
SPL
sqlite3
standard
swoole
sysvmsg
sysvsem
sysvshm
tidy
tokenizer
wddx
xhprof
xml
xmlreader
xmlrpc
xmlwriter
xsl
Zend OPcache
zip
zlib
[Zend Modules]
Zend OPcache
安装 Nginx
cd /data/soft
新建 nginx 用户
/usr/sbin/groupadd nginx
/usr/sbin/useradd -g nginx nginx
## 随便安装一下
wget -c http://nginx.org/download/nginx-1.12.0.tar.gz
tar zxvf nginx-1.12.0.tar.gz
cd nginx-1.12.0
mkdir -p /var/cache/nginx
### 伪装NGINX
vim src/core/nginx.h
#define NGINX_VERSION "1.10.1"
#define NGINX_VER "nginx/" NGINX_VERSION
修改成
#define NGINX_VERSION "1.0"
#define NGINX_NAME "BServer"
#define NGINX_VER NGINX_NAME "/" NGINX_VERSION
vim src/http/ngx_http_header_filter_module.c
static char ngx_http_server_string[] = "Server: nginx" CRLF;
修改成
static char ngx_http_server_string[] = "Server: " NGINX_NAME CRLF;
vim src/http/ngx_http_special_response.c
"<hr><center>nginx</center>" CRLF
修改成
"<hr><center>" NGINX_NAME "</center>" CRLF
安装需要的工具及类库
yum install -y gcc pcre-devel openssl-devel zlib-devel
## 默认安装
./configure --prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-threads \
--with-stream \
--with-stream_ssl_module \
--with-http_slice_module \
--with-mail \
--with-mail_ssl_module \
--with-file-aio \
--with-http_v2_module
make
make install
Configuration summary
+ using threads
+ using system PCRE library
+ using system OpenSSL library
+ using system zlib library
nginx path prefix: "/etc/nginx"
nginx binary file: "/usr/sbin/nginx"
nginx modules path: "/etc/nginx/modules"
nginx configuration prefix: "/etc/nginx"
nginx configuration file: "/etc/nginx/nginx.conf"
nginx pid file: "/var/run/nginx.pid"
nginx error log file: "/var/log/nginx/error.log"
nginx http access log file: "/var/log/nginx/access.log"
nginx http client request body temporary files: "/var/cache/nginx/client_temp"
nginx http proxy temporary files: "/var/cache/nginx/proxy_temp"
nginx http fastcgi temporary files: "/var/cache/nginx/fastcgi_temp"
nginx http uwsgi temporary files: "/var/cache/nginx/uwsgi_temp"
nginx http scgi temporary files: "/var/cache/nginx/scgi_temp"
配置自启动
vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
systemctl enable nginx
systemctl start nginx
配置服务器
mkdir -p /etc/nginx/conf.d/
vim /etc/nginx/nginx.conf
#user nobody;
user nginx;
worker_processes 1; # 看看是几核,设置为几
error_log /data/server/nginx/var/log/nginx/error.log warn;
pid /data/server/nginx/var/run/nginx.pid;
把
http {
server_tokens off;
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 /var/log/nginx/access.log main;
gzip on;
gzip_min_length 1k;
gzip_buffers 16 64k;
gzip_http_version 1.1;
gzip_comp_level 6;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
client_max_body_size 30M;
include /etc/nginx/conf.d/*.conf;
}
mkdir -p /var/www
vim /etc/nginx/conf.d/apps.conf
server {
listen 80;
server_name localhost;
#charset utf-8;
root /var/www;
index index.php index.html index.htm;
location / {
if (!-f $request_filename) {
rewrite ^/(.+)$ /index.php?$1& last;
}
}
location ~ \.php$ {
# fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
安装 mysql5.7
wget -c https://repo.mysql.com/mysql57-community-release-el7-11.noarch.rpm
yum localinstall mysql57-community-release-el7-11.noarch.rpm
yum install -y mysql-community-server
systemctl enable mysqld
systemctl start mysqld
查看临时密码
grep 'temporary password' /var/log/mysqld.log
mysql -uroot -p
set password = password('Mark*123456')
alter user 'root'@'localhost' password expire never;
flush privileges;
exit
mysql -uroot -pMark*123456
grant all privileges on *.* to apps@'%' identified by 'Mark*123456';
alter user 'apps'@'%' password expire never;
flush privileges;
安装 memcached
yum install -y memcached
systemctl enable memcached
systemctl start memcached
systemctl stop memcached
安装 redis
yum install -y epel-release
yum install -y redis
systemctl enable redis
systemctl start redis
systemctl stop redis