系统环境:centos 7.3
软件环境:MysqL 5.6.12 采用二进制免编译安装包
Nginx 1.12.1 增加扩展模块 Nginx_http_concat_module
# 安装依赖包
yum install -y gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libpng libpng-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses curl openssl-devel gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel readline-devel libxslt-devel expat-devel xmlrpc-c xmlrpc-c-devel libmcrypt libmcrypt-devel libaio
#======================安装MysqL 5.6.12==========================
#下载MysqL 5.6.12
cd /usr/local/src
wget https://cdn.MysqL.com//archives/MysqL-5.6/MysqL-5.6.12-linux-glibc2.5-x86_64.tar.gz
#解压MysqL
tar -zxvf /usr/local/src/MysqL-5.6.12-linux-glibc2.5-x86_64.tar.gz -C /usr/local
useradd -s /sbin/nologin MysqL
cd /usr/local
mv MysqL-5.6.12-linux-glibc2.5-x86_64 MysqL
mkdir -pv /data/MysqL
chown -R MysqL.MysqL /data/MysqL
#初始化MysqL
cd /usr/local/MysqL
./scripts/MysqL_install_db --user=MysqL --basedir=/usr/local/MysqL --datadir=/data/MysqL
mv /etc/my.cnf /etc/my.cnf.bak
cat > /etc/my.cnf <<EOF
[MysqL]
default-character-set=utf8
socket=/tmp/MysqL.sock
[MysqLd]
skip-name-resolve
port = 3306
socket=/tmp/MysqL.sock
basedir=/usr/local/MysqL
datadir=/data/MysqL
max_connections=200
character-set-server=utf8
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=16M
EOF
#更改启动脚本,并添加到开机启动
cp support-files/MysqL.server /etc/init.d/MysqLd
chmod 755 /etc/init.d/MysqLd
/etc/init.d/MysqLd start
chkconfig --add MysqLd
chkconfig MysqLd on
netstat -tulnp |grep MysqL //查看是否监听3306端口
#====================安装PHP 7.17==============================
#下载PHP 7.1.7
cd /usr/local/src
wget http://cn2.PHP.net/distributions/PHP-7.1.7.tar.gz
#解压PHP:
tar -zxvf PHP-7.1.7.tar.gz
useradd -s /sbin/nologin PHP-fpm
#进入PHP解压目录,配置编译参数:
cd /usr/local/src/PHP-7.1.7
./configure '--prefix=/usr/local/PHP' '--with-config-file-path=/usr/local/PHP/etc' '--with-config-file-scan-dir=/usr/local/PHP/etc/conf.d' '--enable-fpm' '--with-fpm-user=PHP-fpm' '--with-fpm-group=PHP-fpm' '--enable-soap' '--with-openssl' '--with-openssl-dir' '--with-mcrypt' '--with-pcre-regex' '--with-zlib' '--with-iconv' '--with-bz2' '--enable-calendar' '--with-curl' '--with-cdb' '--enable-dom' '--enable-exif' '--with-pcre-dir' '--enable-ftp' '--with-gd' '--with-jpeg-dir' '--with-png-dir' '--with-freetype-dir' '--with-gettext' '--with-gmp' '--with-mhash' '--enable-mbstring' '--with-libmbfl' '--with-onig' '--enable-pdo' '--with-pdo-MysqL=MysqLnd' '--with-zlib-dir' '--with-readline' '--enable-session' '--enable-shmop' '--enable-simplexml' '--enable-sockets' '--enable-sysvmsg' '--enable-sysvsem' '--enable-sysvshm' '--enable-wddx' '--with-libxml-dir' '--with-xsl' '--enable-zip' '--enable-MysqLnd' '--with-MysqL-sock=/tmp/MysqL.sock' '--with-MysqLi=/usr/local/MysqL/bin/MysqL_config' '--without-pear'
#编译及安装
make && make install
#复制PHP 主配置:
cp PHP.ini-production /usr/local/PHP/etc/PHP.ini
cp /usr/local/PHP/etc/PHP-fpm.conf.default /usr/local/PHP/etc/PHP-fpm.conf
cp /usr/local/PHP/etc/PHP-fpm.d/www.conf.default /usr/local/PHP/etc/PHP-fpm.d/www.conf
sed -i '1,$s#;pid = run/PHP-fpm.pid#pid = /usr/local/PHP/var/run/PHP-fpm.pid#g' /usr/local/PHP/etc/PHP-fpm.conf
sed -i '1,$s#;error_log = log/PHP-fpm.log#error_log = /usr/local/PHP/var/log/PHP-fpm.log#g' /usr/local/PHP/etc/PHP-fpm.conf
echo "include=/usr/local/PHP/etc/PHP-fpm.d/*.conf" >> /usr/local/PHP/etc/PHP-fpm.conf
cat <<EOF > /usr/local/PHP/etc/PHP-fpm.d/www.conf
[global]
pid = /usr/local/PHP/var/run/PHP-fpm.pid
error_log = /usr/local/PHP/var/log/PHP-fpm.log
[www]
listen = 127.0.0.1:9000
user = PHP-fpm
group = PHP-fpm
listen.owner = Nginx
listen.group = Nginx
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024
EOF
#测试PHP-fpm 配置:
/usr/local/PHP/sbin/PHP-fpm -t
#centos 7 systemctl启动PHP-fpm
cp /usr/local/src/PHP-7.1.7/sapi/fpm/PHP-fpm.service /usr/lib/systemd/system/
systemctl enable PHP-fpm.service
systemctl start PHP-fpm.service
sed -i 's/expose_PHP = On/expose_PHP = Off/g' /usr/local/PHP/etc/PHP.ini
#下载phalcon模块
cd /usr/local/src
git clone https://github.com/dreamsxin/cphalcon7.git
cd cphalcon7/ext
#准备环境,配置编译参数
./configure --with-PHP-config=/usr/local/PHP/bin/PHP-config >> $LOG_INS 2>&1
#编译及安装
make && make install
mkdir /usr/local/PHP/etc/conf.d
echo "extension = phalcon.so" >> /usr/local/PHP/etc/conf.d/phalcon.ini
#重新加载配置
/usr/local/PHP/sbin/PHP-fpm -t
systemctl restart PHP-fpm.service
#===================安装Nginx 1.12.1 ==============================
#下载
cd /usr/local/src && wget http://Nginx.org/download/Nginx-1.12.1.tar.gz && git clone git://github.com/alibaba/Nginx-http-concat.git
#解压:
tar zxf Nginx-1.12.1.tar.gz
useradd -s /sbin/nologin Nginx
#进入解压目录,配置编译参数:
cd ./Nginx-1.12.1 && ./configure --prefix=/usr/local/Nginx --with-http_realip_module --with-http_sub_module --with-http_gzip_static_module --with-http_stub_status_module --with-pcre --add-module=/usr/local/src/Nginx-http-concat
#编译及安装
make && make install
#设置软链接
ln -s /usr/local/lib/libmaxminddb.so.0 /usr/lib64
ln -s /usr/local/lib/libprofiler.so.0 /usr/lib64
ln -s /usr/local/lib/libunwind.so.8 /usr/lib64
#检测初始化完成的Nginx 配置是否有问题
/usr/local/Nginx/sbin/Nginx -t
#centos 7创建Nginx启动脚本
cat <<EOF > /usr/lib/systemd/system/Nginx.service
[Unit]
Description=Nginx
Documentation=http://Nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
PIDFile=/usr/local/Nginx/logs/Nginx.pid
ExecStartPre=/usr/local/Nginx/sbin/Nginx -t -c /usr/local/Nginx/conf/Nginx.conf
ExecStart=/usr/local/Nginx/sbin/Nginx -c /usr/local/Nginx/conf/Nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
[Install]
WantedBy=multi-user.target
EOF
#将Nginx加入到开机启动
systemctl enable Nginx.service
cp /usr/local/Nginx/conf/Nginx.conf{,.bak}
#重新Nginx 配置:
cat << EOF > /usr/local/Nginx/conf/Nginx.conf
error_log /var/log/Nginx_error.log crit;
pid /usr/local/Nginx/logs/Nginx.pid;
worker_processes auto;
worker_rlimit_nofile 65535;
events {
use epoll;
worker_connections 65535;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server_tokens off;
charset utf-8;
tcp_nopush on;
tcp_nodelay on;
gzip on;
gzip_min_length 100;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 6;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm index.PHP;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.PHP\$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.PHP;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
EOF
echo "<?PHP echo PHPinfo(); ?>" >/usr/local/Nginx/html/index.PHP
#备份index.html:
mv /usr/local/Nginx/html/index.html{,.bak}
#启动Nginx:
#service Nginx start
systemctl start Nginx.service
#清空防火墙配置
iptables -F
echo "PATH=$PATH:/usr/local/PHP/bin:/usr/local/Nginx/sbin:/usr/local/MysqL/bin:/usr/local/PHP/sbin" >> /etc/profile
#刷新环境变量配置,使其立即生效:
source /etc/profile
浏览器访问ip,会出现PHP的相关信息。