zoukankan      html  css  js  c++  java
  • Centos7 编译安装 Nginx PHP Mariadb Memcached 扩展 ZendOpcache扩展 (实测 笔记 Centos 7.3 + Openssl 1.1.0e + Mariadb 10.1.22 + Nginx 1.12.0 + PHP 7.1.4 + Laravel 5.4 )

    环境:

    系统硬件:vmware vsphere (CPU:2*4核,内存2G,双网卡)

    系统版本:CentOS-7-x86_64-Minimal-1611.iso


    安装步骤:


    1.准备

    1.0 查看硬件信息

    查看物理cpu个数
    [root@centos ~]# grep 'physical id' /proc/cpuinfo | sort -u | wc -l

    查看核心数量
    [root@centos ~]# grep 'core id' /proc/cpuinfo | sort -u | wc -l

    查看线程数
    [root@centos ~]# grep 'processor' /proc/cpuinfo | sort -u | wc -l

    查看硬盘空间占用

    [root@centos ~]# df -h

    查看目录空间占用

    [root@centos ~]# du -msh /usr/local/src

    查看物理内存,以及swap使用情况

    [root@centos ~]# free -h

    ******************************************

    把 /usr/local/src 目录,转到 /data 下

    [root@centos ~]# mkdir -p /data

    [root@centos ~]# mv /usr/local/src /data

    [root@centos ~]# ln -s /data/src /usr/local/src

    ******************************************

    1.1 主机名设置

    当前主机名查看

    [root@centos ~]# hostname

    主机名设置

    [root@centos ~]# hostnamectl --static set-hostname tCentos

    [root@centos ~]# systemctl restart network

    [root@centos ~]# hostname

    tCentos

    1.2 设置静态IP、DNS地址(网络设备名称有可能不一样,这里是eno16780032,如使用DHCP获取动态IP,可忽略)

    [root@centos ~]# vi /etc/sysconfig/network-scripts/ifcfg-eno16780032

    找到BOOTPROTO,并且修改(设为静态网址)

    BOOTPROTO="static"

    在最后添加三行内容(添加本机IP,子网掩码,网关)

    IPADDR="192.168.1.10"
    NETMASK="255.255.255.0"
    GATEWAY="192.168.1.1"

    :wq 保存退出

    [root@centos ~]# shutdonw -r now

    [root@centos ~]# vi /etc/resolv.conf

    添加以下几个DNS地址

    nameserver 114.114.114.114
    nameserver 192.168.1.1
    nameserver 8.8.8.8

    :wq 保存退出

    [root@centos ~]# systemctl restart network

    [root@centos ~]# ip addr|grep inet

    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
    inet 192.168.1.10/24 brd 192.168.1.255 scope global eno16780032
    inet6 fe80::250:56ff:feb0:30f2/64 scope link

    1.3 更新时间,设置定时同步时间

    [root@centos ~]# yum install -y ntpdate

    [root@centos ~]# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

    手动设置系统时间(测试用)

    [root@centos ~]# date -s "2000-1-1"

    [root@centos ~]# /usr/sbin/ntpdate us.pool.ntp.org

    查看当前系统时间

    [root@centos ~]# date

    设置定时任务,自动执行

    [root@centos ~]# mkdir -p /data/crond

    [root@centos ~]# crontab -e

    添加以下内容 (每天 02:00同步一次,并且日志记录到 /data/crond/ntpdate.log)

    00 02 * * * /usr/sbin/ntpdate time.nist.gov 1>>/data/crond/ntpdate.log 2>&1

    :wq 保存退出

    1.4 安装基本软件包

    [root@centos ~]# yum install vim wget lsof gcc gcc-c++ bzip2 firewalld openssl-devel mlocate -y

    配置Vim显示格式

    [root@centos ~]# vim /etc/vimrc

    在末尾添加以下内容

    set nocompatible
    set number
    filetype on
    set history=1000
    set background=dark
    syntax on
    set autoindent
    set smartindent
    set tabstop=2
    set shiftwidth=2
    set showmatch
    set guioptions-=T
    set vb t_vb=
    set ruler
    set nohls
    set incsearch
    if has("vms")
    set nobackup
    else
    set backup
    endif

    :wq 保存退出 

    VIM格式化使用方法(打开文件后,输入以下命令,第二个G是shift+g)

    gg=G

    1.5 打开selinux ( centos 7.3某个版本设置为enforcing会导致没法重启)

    [root@centos ~]# vim /etc/selinux/config

    找到这一行,去掉前面的#注释

    SELINUX=enforcing

    保存,退出


    重启后,查询是否关闭(显示Enforcing表示启用,Disabled则表示关闭)

    [root@centos ~]# shutdown -r now

    [root@centos ~]# getenforce

    Enforcing

    1.6 更新系统,显示系统版本(使用阿里云源)

    [root@centos ~]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

    [root@centos ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

    [root@centos ~]# yum clean all

    [root@centos ~]# yum makecache

    [root@centos ~]# yum update -y

    更新完成后重启,查看内核版本

    [root@centos ~]# shutdown -r now

    [root@centos ~]# cat /etc/redhat-release

    CentOS Linux release 7.3.1611 (Core)

    [root@centos ~]# uname -r

    3.10.0-514.16.1.el7.x86_64

    查看当前所有内核版本

    [root@centos ~]#  rpm -qa | grep kernel-devel
    kernel-devel-3.10.0-514.16.1.el7.x86_64
    kernel-devel-3.10.0-514.10.2.el7.x86_64

    清除多余内核版本 (有需要可以删除)

    [root@centos ~]# yum remove kernel-devel-3.10.0-514.10.2.el7.x86_64

    更新完成后重启,在启动菜单选择内核版本时可以查看到删除结果

    [root@centos ~]# shutdown -r now

    1.7 设置PUTTY远程登录时,不使用密码,使用密钥文件登录(如不需要,可忽略)

    1.7.1 服务器上创建目录

    [root@centos ~]# mkdir -p /root/.ssh

    1.7.2 在"客户机"生成对称密钥,把客户机上的公钥复制到服务器(公钥文件:id_rsa.pub)

    [root@centos ~] ssh-keygen -t rsa

    根据提示操作,生成公钥

    上传到服务器指定目录

    [root@centos ~] scp id_rsa.pub root@192.168.1.10/root/.ssh

    *** 或使用软件远程复制id_rsa.pub到服务器/root/.ssh中。


    1.7.3 查看服务器上,公钥是否已经存在

    [root@centos ~]# cd /root/.ssh

    [root@centos ~]# ll
    -rw-r--r-- 1 root root 394 12月 5 09:33 id_rsa.pub

    导入密钥到authorized_keys

    [root@centos ~]# cat id_rsa.pub >> authorized_keys

    [root@centos ~]# ll /root/.ssh
    -rw-r--r-- 1 root root 394 12月 5 09:37 authorized_keys
    -rw-r--r-- 1 root root 394 12月 5 09:33 id_rsa.pub

    导入后,删除公钥文件

    [root@centos ~]# rm id_rsa.pub

    设置目录和文件读取权限

    [root@centos ~]# chmod 700 /root/.ssh

    [root@centos ~]# chmod 600 /root/.ssh/authorized_keys


    1.7.4 设置sshd配置文件

    [root@centos ~]# vim /etc/ssh/sshd_config

    找到GSSAPICleanupCredentials,并且修改为以下内容

    GSSAPICleanupCredentials yes

    :wq 保存退出


    重启sshd服务,让其生效

    [root@centos ~]# systemctl restart sshd


    1.7.5 客户端设置PUTTY,进行远程登录

    打开软件 PuTTYgen

    点击load 选择之前客户机生成私钥文件id_rsa, 点击save private key 生成 pKey.ppk文件

    打开软件 PuTTY

    点击Session,在HostName(or IP address)输入服务器地址

    点击Connection下的DATA,在Auto-login username中输入登录账号(当前账号为root)

    点击Connection下的SSH下的Auth,点击Browse 选择之前生成 pKeyppk文件

    点击Session,在Saved Sessions中,输入需要保存的Session名称,点击保存


    1.7.6 设置完成后,即可以远程连接到服务器

    打开软件 PuTTY

    点击Session,在"Default Settings"下,找到之前已经保存的Session,双击打开连接

    如果显示 Authenticating with public key "xxxxx-xxxx"时,即表未成功


    1.8 设置新用户,并且使用密码和证书双重认证远程登录。同时禁止root远程登录  (如不需要,可忽略)

    1.8.1 root登录后,修改root密码 (安全建议:密码为15位,大小字母+数字+特殊字符)

    [root@centos ~]# passwd

    1.8.2 添加新用户,并且设置密码

    [root@centos ~]# adduser vicowong

    [root@centos ~]# passwd vicowong

    1.8.3 创建目录,复制密钥相关文件到用户目录,并且设置权限

    [root@centos ~]# mkdir /home/vicowong/.ssh -p

    [root@centos ~]# cp /root/.ssh/authorized_keys /home/vicowong/.ssh

    [root@centos ~]# chmod 700 /home/vicowong/.ssh

    [root@centos ~]# chmod 600 /home/vicowong/.ssh/authorized_keys

    [root@centos ~]# chown vicowong:vicowong /home/vicowong/.ssh

    [root@centos ~]# chown vicowong:vicowong /home/vicowong/.ssh/authorized_keys

    1.8.4 设置防火墙,设置远程连接端口(这里是26322)

    [root@centos ~]# systemctl enable firewalld

    [root@centos ~]# systemctl start firewalld

    [root@centos ~]# systemctl status firewalld

    [root@centos ~]# firewall-cmd --zone=public --add-port=26322/tcp --permanent 

    [root@centos ~]# firewall-cmd --reload

    [root@centos ~]# iptables -L|grep ACCEPT

    1.8.5 安装semanage(用于设置selinux策略) 

    [root@centos ~]# yum install -y policycoreutils-python selinux-policy selinux-policy-targeted 

    查看当前 selinux 是否启用 即 Enforcing 状态 (否则有可能设置 selinux 策略不成功)

    [root@centos ~]# getenforce

    查看当前 selinux 关于远程ssh连接端口的设置

    [root@centos ~]# semanage port -l | grep ssh

    ssh_port_t                     tcp      22

    添加新端口
    [root@centos ~]# semanage port -a -t ssh_port_t -p tcp 26322

    1.8.6 设置sshd配置文件

    [root@centos ~]# vim /etc/ssh/sshd_config

    找到以下内容,并且进行修改

    Port 26322

    Protocol 2

    ServerKeyBits 1024

    PermitRootLogin no

    AllowUsers vicowong

    StrictModes yes

    RSAAuthentication yes

    PubkeyAuthentication yes

    AuthorizedKeysFile  .ssh/authorized_keys

    PermitEmptyPasswords no

    PasswordAuthentication yes

    AuthenticationMethods publickey,password

    X11Forwarding no

    MaxStartups 10:30:60

    :wq 保存退出


    重启sshd服务,让其生效

    [root@centos ~]# systemctl restart sshd

    1.8.7 使用新用户登录(重新打开一个新终端,原来的终端先不关,避免因设置不当导致没法连接远程)

    打开软件 PuTTY,点击之前保存的Sessions,点击Load读取之前的配置

    在Port框输入端口(当前账号为26322)

    点击Connection下的DATA,在Auto-login username中输入登录账号(当前账号为vicowong)

    点击Session  点击Save。保存当前修改。

    点击Open,打开终端。

    1.8.8 设置后,必须远程将进行密码和证书双重认证。

    远程登录会以vicowong这个账号进行登录。安装维护需要root权限时,可以使用su实现

    [root@centos ~]# su root 

    1.8.9 开机自动禁止被ping (设置为 1:禁止,0:允许)

    [root@centos ~]# chmod +x /etc/rc.d/rc.local

    [root@centos ~]# vim /etc/rc.d/rc.local 

    打开后,在最后增加一行

    echo 1 >/proc/sys/net/ipv4/icmp_echo_ignore_all

    :wq 保存退出

    [root@centos ~]# cat /proc/sys/net/ipv4/icmp_echo_ignore_all

    1

    1.9 升级 gcc (更新过程时间很长,根据需要更新)

    所有源码包统一放到指定目录(可事前下载直接通过FTP上传)

    [root@centos ~]# ll /usr/local/src

    1.9.1 下载 gcc,解压 

    [root@centos ~]# cd /usr/local/src

    [root@centos ~]# wget http://gcc.parentingamerica.com/releases/gcc-6.3.0/gcc-6.3.0.tar.gz

    [root@centos ~]# tar zvxf gcc-6.3.0.tar.gz

    [root@centos ~]# cd gcc-6.3.0

    1.9.2 下载依赖文件,并且刷新

    [root@centos ~]# ./contrib/download_prerequisites

    [root@centos ~]# ldconfig

    1.9.3 创建编辑目录

    [root@centos ~]# mkdir gcc-build-6.3.0

    [root@centos ~]# cd /usr/local/src/gcc-6.3.0/gcc-build-6.3.0


    1.9.4 编译 

    [root@centos ~]# ../configure --enable-languages=c,c++ --disable-multilib --enable-checking=release --prefix=/usr

    # --prefix=/usr 指定安装目录(覆盖原来的目录)
    # --enable-languages,说明你要让你的gcc支持那些语言
    # --disable-multilib不生成编译为其他平台可执行代码的交叉编译器
    # --disable-checking生成的编译器在编译过程中不做额外检查,也可以使用
    # --enable-checking=xxx来增加一些检查

    1.9.5 编译、安装

    [root@centos ~]# make  && make install

    文件改名,避免运行 ldconfig 命令出现以下错误  “

    ldconfig: /lib64/libstdc++.so.6.0.22-gdb.py is not an ELF file - it has the wrong magic bytes at the start.”

    [root@centos ~]# mv /usr/lib64/libstdc++.so.6.0.22-gdb.py  /usr/lib64/bak_libstdc++.so.6.0.22-gdb.py 

    [root@centos ~]# ldconfig

    1.9.6 重启,查看版本,检查是否成功更新

    [root@centos ~]# shutdown -r now

    [root@centos ~]# gcc --version

    [root@centos ~]# g++ --version

    1.10 安装cmake

    [root@centos ~]# cd /usr/local/src/

    [root@centos ~]# wget https://cmake.org/files/v3.8/cmake-3.8.1.tar.gz

    [root@centos ~]# tar zvxf cmake-3.8.1.tar.gz

    [root@centos ~]# cd cmake-3.8.1

    [root@centos ~]# ./bootstrap && make && make install

    1.11 更新安装openssl (依赖zlib库)

    [root@centos ~]# cd /usr/local/src/

    [root@centos ~]# wget http://zlib.net/zlib-1.2.11.tar.gz

    [root@centos ~]# tar zvxf zlib-1.2.11.tar.gz

    [root@centos ~]# cd zlib-1.2.11

    [root@centos ~]# ./configure && make && make install

    [root@centos ~]# openssl version

    [root@centos ~]# cd /usr/local/src/

    [root@centos ~]# wget https://www.openssl.org/source/openssl-1.1.0e.tar.gz

    [root@centos ~]# tar zvxf openssl-1.1.0e.tar.gz

    [root@centos ~]# cd openssl-1.1.0e

    [root@centos ~]# ./config shared zlib --prefix=/usr && make && make install


    #更新软连接 (如果编译时没有指定-prefix=/usr 需要添加软连接,指定/usr目录时即可忽略以下步骤 )

    [root@centos ~]# mv /usr/bin/openssl /usr/bin/openssl_bak

    [root@centos ~]# mv /usr/include/openssl/ /usr/include/openssl_bak

    [root@centos ~]# ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl

    [root@centos ~]# ln -s /usr/local/ssl/include/openssl/ /usr/include/openssl

    [root@centos ~]# echo "/usr/local/ssl/lib" >> /etc/ld.so.conf


    #查看最新版本

    [root@centos ~]# ldconfig -v | grep ssl

    [root@centos ~]# openssl version


    2.安装mariadb

    2.1 安装依赖

    [root@centos ~]# yum install ncurses-devel zlib-devel openssl-devel  bzip2 m4 -y

    2.2 安装bison(需要 m4 库)

    [root@centos ~]# cd /usr/local/src/

    [root@centos ~]# wget http://ftp.gnu.org/gnu/bison/bison-3.0.4.tar.gz

    [root@centos ~]# tar zvxf bison-3.0.4.tar.gz

    [root@centos ~]# cd bison-3.0.4

    [root@centos ~]# ./configure && make && make install


    2.3 安装jemalloc(需要 bzip2 库解压)

    [root@centos ~]# cd /usr/local/src/

    [root@centos ~]# wget https://github.com/jemalloc/jemalloc/releases/download/4.5.0/jemalloc-4.5.0.tar.bz2

    [root@centos ~]# tar xjf jemalloc-4.5.0.tar.bz2

    [root@centos ~]# cd jemalloc-4.5.0

    [root@centos ~]# ./configure && make && make install

    [root@centos ~]# echo '/usr/local/lib' > /etc/ld.so.conf.d/local.conf

    [root@centos ~]# ldconfig

    2.4 安装libevent(依赖openssl库)

    ***********************************

    [root@centos ~]# yum reinstall openssl-devel  -y

    [root@centos ~]# ldconfig

    [root@centos ~]# cd /usr/local/src

    [root@centos ~]# wget https://sourceforge.net/projects/levent/files/libevent/libevent-2.0/libevent-2.0.22-stable.tar.gz

    [root@centos ~]# tar zvxf libevent-2.0.22-stable.tar.gz

    [root@centos ~]# cd libevent-2.0.22-stable

    [root@centos ~]# ./configure --prefix=/usr && make && make install

    [root@centos ~]# ll /usr/lib | grep libevent

    [root@centos ~]# updatedb

    [root@centos ~]# locate libevent

    如果libevent的lib目录不在LD_LIBRARY_PATH里,可以使用以下命令加入

    [root@centos ~]# export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr


    2.5 创建mysql需要的目录、配置用户和用户组

    [root@centos ~]# groupadd mysql

    [root@centos ~]# useradd -g mysql mysql -s /sbin/nologin

    [root@centos ~]# mkdir -p /data/mysql

    [root@centos ~]# chown -R mysql:mysql /data/mysql


    2.6 编译mariadb(需要 cmake ncurses-devel bison 库)

    [root@centos ~]# cd /usr/local/src/

    [root@centos ~]# wget https://mirrors.tuna.tsinghua.edu.cn/mariadb//mariadb-10.1.23/source/mariadb-10.1.23.tar.gz

    [root@centos ~]# tar zvxf mariadb-10.1.23.tar.gz

    [root@centos ~]# cd mariadb-10.1.23

    [root@centos ~]# cmake
    -DCMAKE_BUILD_TYPE=Release
    -DCMAKE_INSTALL_PREFIX=/opt/mysql
    -DINSTALL_DOCDIR=share/doc/mariadb-10.1.23
    -DINSTALL_DOCREADMEDIR=share/doc/mariadb-10.1.23
    -DINSTALL_MANDIR=share/man
    -DINSTALL_MYSQLSHAREDIR=share/mysql
    -DINSTALL_MYSQLTESTDIR=share/mysql/test
    -DINSTALL_PLUGINDIR=lib/mysql/plugin
    -DINSTALL_SBINDIR=sbin
    -DINSTALL_SCRIPTDIR=bin
    -DINSTALL_SQLBENCHDIR=share/mysql/bench
    -DINSTALL_SUPPORTFILESDIR=share/mysql 
    -DMYSQL_DATADIR=/data/mysql
    -DMYSQL_UNIX_ADDR=/tmp/mysql.sock
    -DWITH_EXTRA_CHARSETS=complex
    -DWITH_EMBEDDED_SERVER=ON
    -DTOKUDB_OK=0

    [root@centos ~]# make && make install


    2.7 创建软连接

    [root@centos ~]# ln -s /opt/mysql/lib/lib* /usr/lib/

    [root@centos ~]# ln -s /opt/mysql/bin/mysql /bin

    [root@centos ~]# ln -s /opt/mysql/bin/mysqldump /bin

    [root@centos ~]# ln -s /opt/mysql/bin/mysqlbinlog /bin

    2.8 修改配置文件

    [root@centos ~]# cp ./support-files/my-large.cnf /etc/my.cnf

    [root@centos ~]# vim /etc/my.cnf

    在[client]下添加以下内容

    default-character-set = utf8

    在[mysqld]下添加以下内容

    datadir = /data/mysql
    character-set-server = utf8

    :wq 保存退出


    2.9 初始化数据库

    [root@centos ~]# cd /opt/mysql

    [root@centos ~]# ./bin/mysql_install_db --basedir=/opt/mysql --datadir=/data/mysql --user=mysql

    [root@centos ~]# ./bin/mysqld_safe --datadir=/data/mysql

    确认运行后,按可以按CTRL+Z结束

    [root@centos ~]# ps -ef|grep mysqld

    [root@centos ~]# lsof -n | grep jemalloc


    2.10 设置数据库ROOT密码,移除删除临时用户,删除测试数据库等(根据提示操作)

    [root@centos ~]# ./bin/mysql_secure_installation

    输入当前密码。(默认为空,回车即可)

    Enter current password for root (enter for none):

    是否设置root密码,输入Y,后,输入两次密码

    Set root password? [Y/n] y

    New password:

    Re-enter new password:

    是否移除匿名用户,输入Y

    Remove anonymous users? [Y/n] y

    是否禁止root远程登录,输入Y

    Disallow root login remotely? [Y/n] y

    是否删除测试数据库,输入Y

    Remove test database and access to it? [Y/n] y

    是否重新读取权限表数据

    Reload privilege tables now? [Y/n] y

    2.11 登录数据库,查看数据库状态

    [root@centos ~]# mysql -u root -p

    MariaDB [(none)]> status;

    MariaDB [(none)]> show engines;

    MariaDB [(none)]> SHOW VARIABLES LIKE '%have%ssl%';

    MariaDB [(none)]> exit;


    2.12 设置mysql开机自动启动服务

    [root@centos ~]# vim /etc/systemd/system/mysqld.service

    录入以下内容

    [Unit]
    Description=MySQL Community Server
    After=network.target
    After=syslog.target

    [Install]
    WantedBy=multi-user.target
    Alias=mysql.service

    [Service]
    User=mysql
    Group=mysql

    # Execute pre and post scripts as root
    PermissionsStartOnly=true

    # Needed to create system tables etc.

    # Start main service
    ExecStart=/opt/mysql/bin/mysqld_safe

    # Don't signal startup success before a ping works

    # Give up if ping don't get an answer
    TimeoutSec=30

    Restart=always
    PrivateTmp=false


    :wq 保存


    [root@centos ~]# systemctl enable mysqld.service

    [root@centos ~]# systemctl list-unit-files|grep enabled|grep mysql

    [root@centos ~]# systemctl daemon-reload


    2.13 重启,确认是否已自动启动服务

    [root@centos ~]# shutdown -r now

    [root@centos ~]# systemctl start mysqld.service

    [root@centos ~]# systemctl status mysqld.service -l

    [root@centos ~]# ps -ef|grep mysqld

    [root@centos ~]# lsof -n | grep jemalloc


    2.14 增加远程访问用户,并且打开防火墙3306端口(不远程连接数据,可忽略)

    [root@centos ~]# mysql -u root -p

    MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;

    MariaDB [(none)]> FLUSH PRIVILEGES;

    MariaDB [(none)]> exit;

    (root是用户名,%是主机名或IP地址,这里的%代表任意主机或IP地址,也可指定唯一的IP地址;密码是MyPassword )


    2.15 防火墙添加3306端口(不远程连接数据,可忽略)

    [root@centos ~]# iptables -L|grep ACCEPT

    [root@centos ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent

    [root@centos ~]# firewall-cmd --reload

    [root@centos ~]# iptables -L|grep ACCEPT

    3.编译安装Nginx

    3.1安装依赖

    [root@centos ~]# yum install zlib-devel openssl-devel -y


    3.2 安装Pcre

    [root@centos ~]# cd /usr/local/src/

    [root@centos ~]# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz

    [root@centos ~]# tar zvxf pcre-8.39.tar.gz

    [root@centos ~]# cd pcre-8.39

    [root@centos ~]# ./configure && make && make install

    3.3 创建www用户和组,创建www虚拟主机使用的目录,以及Nginx使用的日志目录,并且赋予他们适当的权限

    [root@centos ~]# groupadd www

    [root@centos ~]# useradd -g www www -s /sbin/nologin

    [root@centos ~]# mkdir -p /data/www/web

    [root@centos ~]# chmod +w /data/www/web

    [root@centos ~]# chown -R www:www /data/www/web

    3.4 安装nginx

    [root@centos ~]# cd /usr/local/src/

    [root@centos ~]# wget http://nginx.org/download/nginx-1.12.0.tar.gz

    [root@centos ~]# tar zvxf nginx-1.12.0.tar.gz

    [root@centos ~]# cd nginx-1.12.0

    [root@centos ~]# ./configure --prefix=/opt/nginx
    --user=www
    --group=www
    --with-http_stub_status_module
    --with-http_ssl_module
    --with-http_gzip_static_module
    --with-openssl=/usr/local/src/openssl-1.1.0e
    --with-zlib=/usr/local/src/zlib-1.2.11
    --with-pcre=/usr/local/src/pcre-8.39
    --with-ld-opt="-ljemalloc"
    --with-http_v2_module

    [root@centos ~]# make && make install


    3.5 配置nginx,以支持静态网页访问

    [root@centos ~]# vim /opt/nginx/conf/nginx.conf

    打开配置文件,删除原所有内容,添加以下新内容:

    user www www;
    worker_processes auto;
    error_log logs/error.log crit;
    pid logs/nginx.pid;

    events {
      use epoll;
      worker_connections 1024;
    }

    http {

      fastcgi_buffers 8 16k;
      fastcgi_buffer_size 32k;

      include mime.types;
      default_type application/octet-stream;


      # 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 logs/access.log main;

      sendfile on;
      # tcp_nopush on;

      # keepalive_timeout 0;
      keepalive_timeout 65;

      # gzip on;

      include /opt/nginx/conf/vhosts/*.conf;
    }

    :wq 保存退出  ( 保存前先 gg=G 格式化)

    * 如果需要支持http2,参考以下设置(需要https证书,并且OpenSSL 1.0.2+)

    server {

      listen 443 ssl http2;

      ssl_certificate server.crt;

      ssl_certificate_key server.key;

      ...

    }

    * 完成后,可以在浏览器中,打开此网站,查看是否已经支持http2

    chrome://net-internals/#http2

    * HTTPS性能评估:https://www.ssllabs.com/ssltest/

    创建网站配置文件目录

    [root@centos ~]# mkdir -p /opt/nginx/conf/vhosts

    创建网站配置文件

    [root@centos ~]# vim /opt/nginx/conf/vhosts/web.conf

    添加以下内容

    server {
      listen 80;
      server_name 192.168.1.10;
      set $root /data/www/web;
      root $root;

      location / {
        index index.html index.htm;
      } 
    }

    :wq 保存退出  ( 保存前先 gg=G 格式化)

    3.6 建立测试首页

    [root@centos ~]# vim /data/www/web/index.html

    <html>
    <head><title>nginx index.html</title></head>
    <body>
    <h1>index.html</h1>
    </body>
    </html>

    保存,退出 


    3.7 测试和运行

    [root@centos ~]# cd /opt/nginx

    [root@centos ~]# ldconfig

    [root@centos ~]# ./sbin/nginx -c /opt/nginx/conf/nginx.conf -t

    如果显示下面信息,即表示配置没问题

    nginx: the configuration file /opt/nginx/conf/nginx.conf syntax is ok
    nginx: configuration file /opt/nginx/conf/nginx.conf test is successful


    查看jemalloc是否生效,需要先启动nginx

    [root@centos ~]# ./sbin/nginx -c /opt/nginx/conf/nginx.conf

    [root@centos ~]# lsof -n | grep jemalloc

    ginx 2346 root mem REG 253,1 1824470 51571788 /usr/local/lib/libjemalloc.so.1
    nginx 2347 www mem REG 253,1 1824470 51571788 /usr/local/lib/libjemalloc.so.1
    nginx 2348 www mem REG 253,1 1824470 51571788 /usr/local/lib/libjemalloc.so.1
    nginx 2349 www mem REG 253,1 1824470 51571788 /usr/local/lib/libjemalloc.so.1
    nginx 2350 www mem REG 253,1 1824470 51571788 /usr/local/lib/libjemalloc.so.1


    3.8 防火墙添加80端口

    [root@centos ~]# iptables -L|grep ACCEPT

    [root@centos ~]# firewall-cmd --zone=public --add-port=80/tcp --permanent

    [root@centos ~]# firewall-cmd --reload

    [root@centos ~]# iptables -L|grep ACCEPT

    3.9 浏览器打开

    http://192.168.1.10

    显示出欢迎内容,则表示成功

    3.10 作为服务,开机后启动

    [root@centos ~]# vim /etc/systemd/system/nginx.service

    增加以下内容

    [Unit]
    Description=The nginx HTTP and reverse proxy server
    After=syslog.target network.target remote-fs.target nss-lookup.target

    [Service]
    Type=forking
    PIDFile=/opt/nginx/logs/nginx.pid
    ExecStartPre=/opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf -t
    ExecStart=/opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf
    ExecReload=/bin/kill -s HUP $MAINPID
    ExecStop=/bin/kill -s QUIT $MAINPID
    PrivateTmp=true

    [Install]
    WantedBy=multi-user.target

    :wq 保存退出


    [root@centos ~]# systemctl enable nginx.service

    [root@centos ~]# systemctl list-unit-files|grep enabled|grep nginx


    3.11 启动服务

    [root@centos ~]# ./sbin/nginx -s stop

    [root@centos ~]# systemctl daemon-reload

    [root@centos ~]# systemctl start nginx.service

    [root@centos ~]# systemctl status nginx.service -l

    [root@centos ~]# ps -ef|grep nginx

    [root@centos ~]# lsof -n | grep jemalloc

    4 安装PHP

    4.1 更新依赖

    [root@centos ~]# yum install 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 krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers libXpm* gcc gcc-c++ -y


    4.2 安装libiconv (加强系统对支持字符编码转换的功能)

    [root@centos ~]# cd /usr/local/src

    [root@centos ~]# wget http://ftp.gnu.org/gnu/libiconv/libiconv-1.14.tar.gz

    [root@centos ~]# tar zvxf libiconv-1.14.tar.gz

    [root@centos ~]# cd libiconv-1.14

    [root@centos ~]# ./configure --prefix=/usr/local

    [root@centos ~]# cd srclib

    [root@centos ~]# sed -i -e '/gets is a security/d' ./stdio.in.h

    [root@centos ~]# cd ..

    [root@centos ~]# make && make install

    [root@centos ~]# ln -sf /usr/local/lib/libiconv.so.2 /usr/lib64/

    [root@centos ~]# ldconfig

    4.3 安装libmcrypt,libltdl(加密算法库,PHP扩展mcrypt功能对此库有依耐关系,要使用mcrypt必须先安装此库)

    [root@centos ~]# cd /usr/local/src

    [root@centos ~]# wget http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz

    [root@centos ~]# tar zvxf libmcrypt-2.5.8.tar.gz

    [root@centos ~]# cd libmcrypt-2.5.8

    [root@centos ~]# ./configure && make && make install

    [root@centos ~]# cd libltdl/

    [root@centos ~]# ./configure --enable-ltdl-install && make && make install

    [root@centos ~]# ln -sf /usr/local/lib/libmcrypt.* /usr/lib64/

    [root@centos ~]# ln -sf /usr/local/bin/libmcrypt-config /usr/lib64/

    [root@centos ~]# ldconfig


    4.4 安装mhash (hash加密算法库)

    [root@centos ~]# cd /usr/local/src/

    [root@centos ~]# wget http://sourceforge.net/projects/mhash/files/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz

    [root@centos ~]# tar zvxf mhash-0.9.9.9.tar.gz

    [root@centos ~]# cd mhash-0.9.9.9

    [root@centos ~]# ./configure && make && make install

    [root@centos ~]# ln -sf /usr/local/lib/libmhash.* /usr/lib64/

    [root@centos ~]# ldconfig


    4.6 安装mcrypt

    [root@centos ~]# cd /usr/local/src/

    [root@centos ~]# wget http://sourceforge.net/projects/mcrypt/files/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz

    [root@centos ~]# tar zvxf mcrypt-2.6.8.tar.gz

    [root@centos ~]# cd mcrypt-2.6.8

    [root@centos ~]# ./configure && make && make install


    4.5 安装re2c

    [root@centos ~]# cd /usr/local/src/

    [root@centos ~]# wget http://sourceforge.net/projects/re2c/files/0.15.3/re2c-0.15.3.tar.gz

    [root@centos ~]# tar zvxf re2c-0.15.3.tar.gz

    [root@centos ~]# cd re2c-0.15.3

    [root@centos ~]# ./configure && make && make install



    4.6 安装php (已经安装mariadb,nginx,ldap)

    4.6.1 创建mysql软连接、ldap软连接

    [root@centos ~]# mkdir -p /opt/mysql/include/mysql

    [root@centos ~]# ln -s /opt/mysql/include/* /opt/mysql/include/mysql/

    [root@centos ~]# ln -s /usr/lib64/libldap* /usr/lib

    [root@centos ~]# ln -s /usr/lib64/liblber* /usr/lib


    4.6.2 安装

    [root@centos ~]# cd /usr/local/src/

    [root@centos ~]# wget http://am1.php.net/distributions/php-7.1.4.tar.gz

    [root@centos ~]# tar zvxf php-7.1.4.tar.gz

    [root@centos ~]# cd php-7.1.4

    [root@centos ~]# ./configure
    --prefix=/opt/php
    --with-config-file-path=/opt/php/etc
    --with-openssl
    --with-mysqli=shared,mysqlnd
    --with-pdo-mysql=shared,mysqlnd
    --with-iconv-dir=/usr/local
    --with-libxml-dir=/usr
    --with-freetype-dir
    --with-jpeg-dir
    --with-png-dir
    --with-zlib
    --with-curl
    --with-mhash
    --with-ldap
    --with-ldap-sasl
    --with-mcrypt
    --with-gd
    --with-xmlrpc
    --with-libdir=/lib/
    --with-kerberos
    --with-pcre-regex
    --with-zlib-dir
    --with-bz2
    --with-gettext
    --disable-rpath
    --enable-pdo
    --enable-xml
    --enable-bcmath
    --enable-shmop
    --enable-sysvsem
    --enable-inline-optimization
    --enable-mbregex
    --enable-fpm
    --enable-mbstring
    --enable-gd-native-ttf
    --enable-pcntl
    --enable-sockets
    --enable-zip
    --enable-soap
    --enable-opcache
    --enable-calendar
    --enable-ctype
    --enable-exif
    --enable-session
    --enable-ftp

    [root@centos ~]# make ZEND_EXTRA_LIBS='-liconv' && make install


    4.6.3 复制配置文件

    [root@centos ~]# cp php.ini-production /opt/php/etc/php.ini


    4.6.4 开启系统HugePages

    [root@centos ~]# sysctl vm.nr_hugepages=512

    [root@centos ~]# cat /proc/meminfo | grep Huge

    AnonHugePages: 106496 kB
    HugePages_Total: 512
    HugePages_Free: 504
    HugePages_Rsvd: 27
    HugePages_Surp: 0
    Hugepagesize: 2048 kB

    设置永久有效(重启后自动开启HugePages)

    [root@centos ~]# vim /etc/sysctl.conf

    vm.nr_hugepages=512

    :wq 保存退出

    4.6.5 修改php配置文件,支持ZendOpcache

    [root@centos ~]# ll /opt/php/lib/php/extensions/no-debug-non-zts-20160303

    [root@centos ~]# vim /opt/php/etc/php.ini

    在文件中搜索; extension_dir = "./" ,并在下面添加以下内容(如果extension_dir已存在,只添加后面的内容)

    extension_dir = "/opt/php/lib/php/extensions/no-debug-non-zts-20160303/"

    zend_extension="opcache.so"
    opcache.memory_consumption=128
    opcache.interned_strings_buffer=8
    opcache.max_accelerated_files=20000
    opcache.revalidate_freq=60
    opcache.fast_shutdown=1
    opcache.enable=1
    opcache.enable_cli=1
    opcache.huge_code_pages=1
    opcache.file_cache=/tmp

    :wq 保存退出

    4.6.6 修改php配置文件,支持pdo_mysql,mysqli

    [root@centos ~]# vim /opt/php/etc/php.ini

    在文件中搜索; extension_dir = "./" ,并在下面添加以下内容(如果extension_dir已存在,只添加后面的一行)

    extension_dir = "/opt/php/lib/php/extensions/no-debug-non-zts-20160303/"

    extension = "pdo_mysql.so"
    extension = "mysqli.so"

    :wq 保存退出


    4.6.7 安装xdebug扩展(调试PHP用,不需要时可忽略)

    [root@centos ~]# cd /usr/local/src/

    [root@centos ~]# wget http://xdebug.org/files/xdebug-2.5.0.tgz

    [root@centos ~]# tar zvxf xdebug-2.5.0.tgz

    [root@centos ~]# cd xdebug-2.5.0

    [root@centos ~]# /opt/php/bin/phpize

    [root@centos ~]# ./configure --enable-xdebug --with-php-config=/opt/php/bin/php-config

    [root@centos ~]# make && make install


    修改php配置文件,支持xdebug

    [root@centos ~]# vim /opt/php/etc/php.ini

    在文件中搜索; extension_dir = "./" ,并在下面添加以下内容(如果extension_dir已存在,只添加后面的一行)

    extension_dir = "/opt/php/lib/php/extensions/no-debug-non-zts-20160303/"

    [xdebug]
    zend_extension = "xdebug.so"
    xdebug.remote_enable=1
    xdebug.remote_connect_back=on
    xdebug.remote_port=8080
    xdebug.idekey=PHPSTORM
    xdebug.remote_autostart=1

    :wq 保存退出

    4.6.8 安装memcahced扩展 (需要 libmemcached 库)

    [root@centos ~]# cd /usr/local/src

    [root@centos ~]# wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz

    [root@centos ~]# tar zvxf libmemcached-1.0.18.tar.gz

    [root@centos ~]# cd libmemcached-1.0.18

    [root@centos ~]# ./configure --with-memcached --prefix=/opt/libmemcached && make && make install

    [root@centos ~]# cd /usr/local/src

    [root@centos ~]# yum install git -y

    [root@centos ~]# git clone https://github.com/php-memcached-dev/php-memcached.git

    [root@centos ~]# cd php-memcached

    [root@centos ~]# git checkout php7

    [root@centos ~]# /opt/php/bin/phpize

    [root@centos ~]# ./configure --with-php-config=/opt/php/bin/php-config --with-libmemcached-dir=/opt/libmemcached

    [root@centos ~]# make && make install

    [root@centos ~]# ll /opt/php/lib/php/extensions/no-debug-non-zts-20160303/


    修改php配置文件,支持memcache

    [root@centos ~]# vim /opt/php/etc/php.ini

    在文件中搜索; extension_dir = "./" ,并在下面添加以下内容(如果extension_dir已存在,只添加后面的几行)

    extension_dir = "/opt/php/lib/php/extensions/no-debug-non-zts-20160303/"

    extension = "memcached.so"

    4.6.9 安装redis扩展 

    [root@centos ~]# cd /usr/local/src

    [root@centos ~]# yum install git -y 

    [root@centos ~]# git clone https://github.com/phpredis/phpredis/

    [root@centos ~]# cd phpredis

    [root@centos ~]# git checkout php7

    [root@centos ~]# /opt/php/bin/phpize

    [root@centos ~]# ./configure --with-php-config=/opt/php/bin/php-config

    [root@centos ~]# make && make install

    [root@centos ~]# ll /opt/php/lib/php/extensions/no-debug-non-zts-20160303/


    修改php配置文件,支持redis

    [root@centos ~]# vim /opt/php/etc/php.ini

    在文件中搜索; extension_dir = "./" ,并在下面添加以下内容(如果extension_dir已存在,只添加后面的几行)

    extension_dir = "/opt/php/lib/php/extensions/no-debug-non-zts-20160303/"

    extension = "redis.so"

    4.6.10 安装php-fpm

    [root@centos ~]# cp /opt/php/etc/php-fpm.conf.default /opt/php/etc/php-fpm.conf

    [root@centos ~]# cp /opt/php/etc/php-fpm.d/www.conf.default /opt/php/etc/php-fpm.d/web.conf

    [root@centos ~]# vim /opt/php/etc/php-fpm.conf


    修改内容,并且让其它生效

    [global]
    pid = run/php-fpm.pid

    error_log = log/php-fpm.log

    emergency_restart_threshold = 10

    emergency_restart_interval = 1m

    process_control_timeout = 5s

    :wq 保存退出


    [root@centos ~]# vim /opt/php/etc/php-fpm.d/web.conf

    修改内容,并且让其它生效

    user = www

    group = www

    pm.max_children = 35

    pm.start_servers = 20

    pm.min_spare_servers = 5

    pm.max_spare_servers = 35

    :wq 保存退出


    # php-fpm.conf 重要参数详解

    # pid = run/php-fpm.pid
    # pid设置,默认在安装目录中的var/run/php-fpm.pid,建议开启

    # error_log = log/php-fpm.log
    # 错误日志,默认在安装目录中的var/log/php-fpm.log

    # log_level = notice
    # 错误级别. 可用级别为: alert(必须立即处理), error(错误情况), warning(警告情况), notice(一般重要信息), debug(调试信息). 默认: notice.

    # emergency_restart_threshold = 60
    # emergency_restart_interval = 60s
    # 表示在emergency_restart_interval所设值内出现SIGSEGV或者SIGBUS错误的php-cgi进程数如果超过 emergency_restart_threshold个,php-fpm就会优雅重启。这两个选项一般保持默认值。

    # process_control_timeout = 0
    # 设置子进程接受主进程复用信号的超时时间. 可用单位: s(秒), m(分), h(小时), 或者 d(天) 默认单位: s(秒). 默认值: 0.
    # daemonize = yes
    # 后台执行fpm,默认值为yes,如果为了调试可以改为no。在FPM中,可以使用不同的设置来运行多个进程池。 这些设置可以针对每个进程池单独设置。

    # listen = 127.0.0.1:9000
    # fpm监听端口,即nginx中php处理的地址,一般默认值即可。可用格式为: 'ip:port', 'port', '/path/to/unix/socket'. 每个进程池都需要设置.

    # listen.backlog = -1
    # backlog数,-1表示无限制,由操作系统决定,此行注释掉就行。backlog含义参考:http://www.3gyou.cc/?p=41

    # listen.allowed_clients = 127.0.0.1
    # 允许访问FastCGI进程的IP,设置any为不限制IP,如果要设置其他主机的nginx也能访问这台FPM进程,listen处要设置成本地可被访问的IP。默认值是any。每个地址是用逗号分隔. 如果没有设置或者为空,则允许任何服务器请求连接

    # listen.owner = www
    # listen.group = www
    # listen.mode = 0666
    # unix socket设置选项,如果使用tcp方式访问,这里注释即可。

    # user = www
    # group = www
    # 启动进程的帐户和组

    # pm = dynamic #对于专用服务器,pm可以设置为static。
    # 如何控制子进程,选项有static和dynamic。如果选择static,则由pm.max_children指定固定的子进程数。如果选择dynamic,则由下开参数决定:
    # pm.max_children #,子进程最大数
    # pm.start_servers #,启动时的进程数
    # pm.min_spare_servers #,保证空闲进程数最小值,如果空闲进程小于此值,则创建新的子进程
    # pm.max_spare_servers #,保证空闲进程数最大值,如果空闲进程大于此值,此进行清理

    # pm.max_requests = 1000
    # 设置每个子进程重生之前服务的请求数. 对于可能存在内存泄漏的第三方模块来说是非常有用的. 如果设置为 '0' 则一直接受请求. 等同于 PHP_FCGI_MAX_REQUESTS 环境变量. 默认值: 0.

    # pm.status_path = /status
    # FPM状态页面的网址. 如果没有设置, 则无法访问状态页面. 默认值: none. munin监控会使用到

    # ping.path = /ping
    # FPM监控页面的ping网址. 如果没有设置, 则无法访问ping页面. 该页面用于外部检测FPM是否存活并且可以响应请求. 请注意必须以斜线开头 (/)。

    # ping.response = pong
    # 用于定义ping请求的返回相应. 返回为 HTTP 200 的 text/plain 格式文本. 默认值: pong.

    # request_terminate_timeout = 0
    # 设置单个请求的超时中止时间. 该选项可能会对php.ini设置中的'max_execution_time'因为某些特殊原因没有中止运行的脚本有用. 设置为 '0' 表示 'Off'.当经常出现502错误时可以尝试更改此选项。

    # request_slowlog_timeout = 10s
    # 当一个请求该设置的超时时间后,就会将对应的PHP调用堆栈信息完整写入到慢日志中. 设置为 '0' 表示 'Off'

    # slowlog = log/$pool.log.slow
    # 慢请求的记录日志,配合request_slowlog_timeout使用

    # rlimit_files = 1024
    # 设置文件打开描述符的rlimit限制. 默认值: 系统定义值默认可打开句柄是1024,可使用 ulimit -n查看,ulimit -n 2048修改。

    # rlimit_core = 0
    # 设置核心rlimit最大限制值. 可用值: 'unlimited' 、0或者正整数. 默认值: 系统定义值.

    # chroot =
    # 启动时的Chroot目录. 所定义的目录需要是绝对路径. 如果没有设置, 则chroot不被使用.

    # chdir =
    # 设置启动目录,启动时会自动Chdir到该目录. 所定义的目录需要是绝对路径. 默认值: 当前目录,或者/目录(chroot时)

    # catch_workers_output = yes
    # 重定向运行过程中的stdout和stderr到主要的错误日志文件中. 如果没有设置, stdout 和 stderr 将会根据FastCGI的规则被重定向到 /dev/null . 默认值: 空.


    4.7.11 配置nginx,支持php

    创建网站配置文件(网站目录/data/www/web)

    [root@centos ~]# vim /opt/nginx/conf/vhosts/web.conf

    添加以下内容

    server {
    listen 80;
    server_name 192.168.1.10;

    set $root /data/www/web;

    root $root;

    location / {
    index index.html index.php;

    }
    location ~ .php {
    root /data/www/web;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;

    }

    }

    :wq 保存退出 ( 保存前先 gg=G 格式化)

    4.6.12 将php-fpm服务加到开机启动服务

    [root@centos ~]# cp /usr/local/src/php-7.1.4/sapi/fpm/php-fpm.service /etc/systemd/system/

    [root@centos ~]# vim /etc/systemd/system/php-fpm.service

    删除原来内容,替换成以下内容

    [Unit]
    Description=The PHP FastCGI Process Manager
    After=syslog.target network.target

    [Service]
    Type=simple
    PIDFile=/opt/php/var/run/php-fpm.pid
    ExecStart=/opt/php/sbin/php-fpm --nodaemonize --fpm-config /opt/php/etc/php-fpm.conf
    ExecReload=/bin/kill -USR2 $MAINPID

    [Install]
    WantedBy=multi-user.target

    保存,退出


    [root@centos ~]# systemctl enable php-fpm.service

    [root@centos ~]# systemctl list-unit-files|grep enabled|grep php-fpm

    [root@centos ~]# systemctl daemon-reload

    [root@centos ~]# systemctl start php-fpm.service

    [root@centos ~]# systemctl status php-fpm.service -l


    4.6.13 编写测试页面

    [root@centos ~]# mkdir -p /data/www/web

    [root@centos ~]# vim /data/www/web/index.php

    输入以下内容

    <html>
    <head><title>hello php</title></head>
    <body>
    <?php phpinfo();?>
    </body>
    </html>

    :wq 保存退出


    [root@centos ~]# systemctl restart nginx

    [root@centos ~]# systemctl restart php-fpm

    浏览器访问:http://192.168.1.10/index.php

    5 安装memcached服务

    5.1 安装memcached (需要libevent库)

    [root@centos ~]# cd /usr/local/src

    [root@centos ~]# wget http://memcached.org/files/memcached-1.4.33.tar.gz

    [root@centos ~]# tar zvxf memcached-1.4.33.tar.gz

    [root@centos ~]# cd memcached-1.4.33

    [root@centos ~]# ./configure --prefix=/opt/memcached --with-libevent=/usr

    [root@centos ~]# make && make install


    5.2 设置用户、运行参数,以及开机启动

    [root@centos ~]# groupadd memcached

    [root@centos ~]# useradd -g memcached memcached -s /sbin/nologin

    [root@centos ~]# vim /etc/sysconfig/memcached

    添加以下内容

    PORT="11211"
    IP="127.0.0.1"
    USER="memcached"
    MAXCONN="1024"
    CACHESIZE="64"
    OPTIONS=""

    :wq 保存退出


    [root@centos ~]# vim /etc/systemd/system/memcached.service

    添加以下内容

    [Unit]
    Description=Memcached
    Before=httpd.service
    After=network.target

    [Service]
    Type=simple
    EnvironmentFile=-/etc/sysconfig/memcached
    ExecStart=/opt/memcached/bin/memcached -l $IP -u $USER -p $PORT -m $CACHESIZE -c $MAXCONN $OPTIONS

    [Install]
    WantedBy=multi-user.target


    :wq 保存退出


    [root@centos ~]# systemctl enable memcached.service

    [root@centos ~]# systemctl list-unit-files|grep enabled|grep memcached

    [root@centos ~]# systemctl daemon-reload

    [root@centos ~]# systemctl start memcached.service

    [root@centos ~]# systemctl status memcached.service -l


    5.3 防火墙添加11211端口(如果不需要外部访问,可忽略)

    [root@centos ~]# iptables -L|grep ACCEPT

    [root@centos ~]# firewall-cmd --zone=public --add-port=11211/tcp --permanent

    [root@centos ~]# firewall-cmd --reload

    [root@centos ~]# iptables -L|grep ACCEPT


    5.4 测试PHP支持(PHP需要安装memcached扩展)

    [root@centos ~]# vim /data/www/web/index.php

    添加以下内容

    <html>
    <head><title>hello php</title></head>
    <body>

    <h1 style="text-align:center;">

    <?php
    $mem = new Memcached;

    $mem->addServer('127.0.0.1',11211);
    $mem->set('test',"hello memcached");

    $val=$mem->get('test');

    echo $val;
    ?>

    </h1>

    <?php phpinfo();?>
    </body>
    </html>

    :wq 保存退出

    浏览器访问:http://192.168.1.10/index.php

    6.配置Laravel

    6.1 安装composer

    6.1.1 关掉xdebug扩展 (也可以不关闭,但会影响composer的速度)

    [root@centos ~]# vim /opt/php/etc/php.ini

    找到以下内容,注释掉

    ;[xdebug]

    ;zend_extension = "xdebug.so"
    ;xdebug.remote_enable=1
    ;xdebug.remote_connect_back=on
    ;xdebug.remote_port=8080
    ;xdebug.idekey=PHPSTORM
    ;xdebug.remote_autostart=1

    :wq 保存退出

    [root@centos ~]# systemctl restart php-fpm


    6.2 添加php软连接

    [root@centos ~]# /opt/php/bin/php --version

    [root@centos ~]# ln -s /opt/php/bin/php /usr/local/bin/php

    [root@centos ~]# php --version


    6.3 下载 composer 脚本文件

    [root@centos ~]# cd /usr/local/src

    [root@centos ~]# wget https://getcomposer.org/download/1.4.1/composer.phar

    [root@centos ~]# chmod +x composer.phar

    [root@centos ~]# ll /usr/local/src/composer.phar

    -rwxr-xr-x 1 root root 1815925 1月 8 2017 composer.phar

    检查composer版本

    [root@centos ~]# /usr/local/src/composer.phar -V

    会提示以下内容,可以忽略不管,主要是查看版本

    Do not run Composer as root/super user! See https://getcomposer.org/root for details
    Composer version 1.4.1 2017-03-10 09:29:45

    创建软连接

    [root@centos ~]# ln -s /usr/local/src/composer.phar /usr/local/bin/composer

    [root@centos ~]# ll /usr/local/bin/composer

    lrwxrwxrwx 1 root root 28 1月 6 07:15 /usr/local/bin/composer -> /usr/local/src/composer.phar

    [root@centos ~]# composer -V

    Do not run Composer as root/super user! See https://getcomposer.org/root for details
    Composer version 1.4.1 2017-03-10 09:29:45


    更改composer到国内源(速度快很多)

    [root@centos ~]# composer config -g repo.packagist composer https://packagist.phpcomposer.com

    composer 自更新 (成功后会出再提示内容)

    [root@centos ~]# composer self-update

    Updating to version 1.4.1 (stable channel).

    重启

    [root@centos ~]# shutdown -r now


    6.4 初始化laravel项目

    6.4.1 进入项目目录

    [root@centos ~]# cd /data/www/

    6.4.2 创建laravel项目

    [root@centos ~]# composer create-project laravel/laravel --prefer-dist laravel5

    [root@centos ~]# ll /data/www/


    6.4.3 修改项目权限,以及storage和vendor文件夹(否则没法正常显示)

    [root@centos ~]# chown -R www:www /data/www/laravel5/

    [root@centos ~]# chmod -R 766 /data/www/laravel5/storage

    6.4.4.创建配置网站文件 

    因为之前的网站 web.conf 使用80端口,为避免IP、域名和端口产生冲突,需要先改名为 web.conf.bak

    [root@centos ~]# mv /opt/nginx/conf/vhosts/web.conf /opt/nginx/conf/vhosts/web.conf.bak

    新建 laravel5 网站的配置文件

    [root@centos ~]# vim /opt/nginx/conf/vhosts/laravel5.conf

    录入以下内容 (注意端口不要重复。)

    server {
    listen 80;
    server_name 192.168.1.10;
    set $root_dir /data/www/laravel5/public/;

    root $root_dir;

    location / {
    index index.html index.php;
    try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ .php {
    root $root_dir;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $root_dir$fastcgi_script_name;
    include fastcgi_params;
    }
    }

    :wq 保存退出

    *********************

    vhosts目录下的所有 ***.conf 配置文件,任意两个配置文件,相同IP或者域名时,端口都不能重复。

    如 vhosts下的4个配置文件,不会造成IP、域名 和端口冲突

    listen 80;
    server_name 192.168.1.10;

    listen 8080;
    server_name 192.168.1.10;

    listen 80;
    server_name 192.168.1.11;

    listen 80;
    server_name www.abc.com;

    *********************

    6.4.5 修改php.ini 防止攻击者欺骗PHP去执行一些不应该执行的代码

    [root@centos ~]# vim /opt/php/etc/php.ini

    添加以下内容
    cgi.fix_pathinfo=0

    :wq 保存退出

    重启服务,使用浏览器打开

    [root@centos ~]# systemctl restart nginx

    [root@centos ~]# systemctl restart php-fpm

    查看 laravel 版本

    [root@centos ~]# cd /data/www/laravel5

    [root@centos ~]# php artisan --version

    Laravel Framework 5.4.22

    用浏览器打开 http://192.168.1.10/index.php 

    显示出Laravel的LOGO则表示成功

  • 相关阅读:
    C#中sizeof的用法
    C#托管堆对象实例包含什么
    C#引用类型转换的几种方式
    C#中结构(struct)的部分初始化和完全初始化
    C#值类型装箱后能改变其值吗
    C#程序集系列13,如何让CLR选择不同版本的程序集
    C#程序集系列12,C#编译器和CLR如何找寻程序集
    C#程序集系列11,全局程序集缓存
    C#程序集系列10,强名称程序集
    C#程序集系列09,程序集签名
  • 原文地址:https://www.cnblogs.com/vicowong/p/5024792.html
Copyright © 2011-2022 走看看