设为首页 收藏本站
查看: 757|回复: 0

[经验分享] CentOS5.8 + Nginx + MySQL + PHP + Xcache编译安装

[复制链接]

尚未签到

发表于 2018-4-27 11:03:21 | 显示全部楼层 |阅读模式
  大纲
  一、环境准备
  二、编译安装Nginx
  三、通用二进制包安装MySQL
  四、编译安装PHP
  五、整合Nginx和PHP
  六、编译安装Xcache
  

  

  

  

  一、环境准备
  系统环境
  CentOS5.8 x86_64
  软件包

  •   nginx-1.8.0.tar.gz
  •   mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz(二进制通用安装包)
  •   php-5.6.17.tar.gz
  •   xcache-3.2.0.tar.gz
  拓扑图
DSC0000.jpg

  

1、时间同步
[root@soysauce ~]# ntpdate s2c.time.edu.cn
18 Jan 12:44:37 ntpdate[25250]: adjust time server 202.112.10.36 offset -0.007795 sec2、关闭iptables和selinux
[root@soysauce ~]# sed -r -i  "s/^(SELINUX=).*/\1permissive/g" /etc/sysconfig/selinux
[root@soysauce ~]# setenforce 0
[root@soysauce ~]# getenforce
Permissive3、下载所需的软件包
nginx
[root@soysauce ~]# wget http://nginx.org/download/nginx-1.8.0.tar.gz
mysql
[root@soysauce ~]# wget https://downloads.mariadb.com/archives/mysql-5.6/mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz
php
[root@soysauce ~]# wget http://cn2.php.net/get/php-5.6.17.tar.gz/from/this/mirror
Xcache
[root@soysauce ~]# wget --no-check-certificate https://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.gz二、编译安装Nginx
1、解决依赖关系
[root@soysauce ~]# yum groupinstall -y "Development Tools" "Development Libraries"
[root@soysauce ~]# yum install openssl-devel pcre-devel2、创建nginx用户和组

[root@soysauce ~]# groupadd -r nginx
[root@soysauce ~]# useradd -r -g nginx nginx3、编译安装
[root@soysauce ~]# tar xf nginx-1.8.0.tar.gz
[root@soysauce ~]# cd nginx-1.8.0
[root@soysauce nginx-1.8.0]# ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  Makefile  man  objs  README  src
[root@soysauce nginx-1.8.0]# ./configure \
  --prefix=/usr \
  --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/nginx.pid  \
  --lock-path=/var/lock/nginx.lock \
  --user=nginx \
  --group=nginx \
  --with-http_ssl_module \
  --with-http_flv_module \
  --with-http_stub_status_module \
  --with-http_gzip_static_module \
  --http-client-body-temp-path=/var/tmp/nginx/client/ \
  --http-proxy-temp-path=/var/tmp/nginx/proxy/ \
  --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
  --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
  --http-scgi-temp-path=/var/tmp/nginx/scgi \
  --with-pcre
显示我们自定义的配置信息和编译选项
Configuration summary
  + using system PCRE library
  + using system OpenSSL library
  + md5: using OpenSSL library
  + sha1: using OpenSSL library
  + using system zlib library
  nginx path prefix: "/usr"
  nginx binary file: "/usr/sbin/nginx"
  nginx configuration prefix: "/etc/nginx"
  nginx configuration file: "/etc/nginx/nginx.conf"
  nginx pid file: "/var/run/nginx/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/tmp/nginx/client/"
  nginx http proxy temporary files: "/var/tmp/nginx/proxy/"
  nginx http fastcgi temporary files: "/var/tmp/nginx/fcgi/"
  nginx http uwsgi temporary files: "/var/tmp/nginx/uwsgi"
  nginx http scgi temporary files: "/var/tmp/nginx/scgi"
编译安装
[root@soysauce nginx-1.8.0]# make && make install
补充:
Nginx可以使用Tmalloc(快速、多线程的malloc库及优秀性能分析工具)来加速内存分配
使用此功能需要事先安装gperftools,而后在编译nginx添加--with-google_perftools_module选项即可4、为nginx提供SysV init脚本
[root@soysauce nginx-1.8.0]# vim /etc/rc.d/init.d/nginx
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig:   - 85 15
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse \
#               proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /etc/nginx/nginx.conf
# config:      /etc/sysconfig/nginx
# pidfile:     /var/run/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
   # make required directories
   user=`nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
   options=`$nginx -V 2>&1 | grep 'configure arguments:'`
   for opt in $options; do
       if [ `echo $opt | grep '.*-temp-path'` ]; then
           value=`echo $opt | cut -d "=" -f 2`
           if [ ! -d "$value" ]; then
               # echo "creating" $value
               mkdir -p $value && chown -R $user $value
           fi
       fi
   done
}
start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    make_dirs
    echo -n $"Starting $prog: "
    daemon $nginx -c $NGINX_CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}
stop() {
    echo -n $"Stopping $prog: "
    killproc $prog -QUIT
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}
restart() {
    configtest || return $?
    stop
    sleep 1
    start
}
reload() {
    configtest || return $?
    echo -n $"Reloading $prog: "
    killproc $nginx -HUP
    RETVAL=$?
    echo
}
force_reload() {
    restart
}
configtest() {
  $nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
    status $prog
}
rh_status_q() {
    rh_status >/dev/null 2>&1
}
case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
            ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
        exit 2
esac
添加执行权限,并加入到服务列表中
[root@soysauce nginx-1.8.0]# chmod +x /etc/rc.d/init.d/nginx
[root@soysauce nginx-1.8.0]# chkconfig --add nginx
[root@soysauce nginx-1.8.0]# chkconfig nginx on
[root@soysauce nginx-1.8.0]# chkconfig --list nginx
nginx          0:off1:off2:on3:on4:on5:on6:off5、启动Nginx服务
[root@soysauce nginx-1.8.0]# service nginx start
Starting nginx:                                            [  OK  ]
查看80端口是否处于监听状态
[root@soysauce nginx-1.8.0]# netstat -tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address      Foreign Address    State       PID/Program name   
tcp        0      0 0.0.0.0:111        0.0.0.0:*          LISTEN      2820/portmap        
tcp        0      0 0.0.0.0:80         0.0.0.0:*          LISTEN      30414/nginx         
tcp        0      0 0.0.0.0:22         0.0.0.0:*          LISTEN      25126/sshd         
tcp        0      0 0.0.0.0:922        0.0.0.0:*          LISTEN      2860/rpc.statd      
tcp        0      0 127.0.0.1:6011     0.0.0.0:*          LISTEN      24814/sshd         
tcp        0      0 :::22              :::*               LISTEN      25126/sshd         
tcp        0      0 ::1:6011           :::*               LISTEN      24814/sshd  

  三、通用二进制包安装MySQL
  1、准备数据存放的文件系统
创建一个分区
[root@soysauce ~]# fdisk /dev/hda
The number of cylinders for this disk is set to 44384.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-44384, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-44384, default 44384): +10G
Command (m for help): p
Disk /dev/hda: 21.4 GB, 21474836480 bytes
15 heads, 63 sectors/track, 44384 cylinders
Units = cylinders of 945 * 512 = 483840 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/hda1               1       20669     9766071   83  Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@soysauce ~]# partprobe /dev/hda
[root@soysauce ~]# cat /proc/partitions
major minor  #blocks  name
   3     0   20971520 hda
   3     1    9766071 hda1
   8     0   20971520 sda
   8     1     104391 sda1
   8     2   20860402 sda2
253     0   18776064 dm-0
253     1    2064384 dm-1
格式化分区,创建文件系统
[root@soysauce ~]# mke2fs -j /dev/hda1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
1221600 inodes, 2441517 blocks
122075 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2503999488
75 block groups
32768 blocks per group, 32768 fragments per group
16288 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
Writing inode tables: done                           
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 30 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
创建挂载目录,并挂载
[root@soysauce ~]# mkdir /mydata
[root@soysauce ~]# mount /dev/hda1 /mydata
[root@soysauce ~]# mkdir /mydata/data
[root@soysauce ~]# ls /mydata/
data  lost+found
修改属主属组为mysql
[root@soysauce ~]# chown -R mysql.mysql /mydata/data/  2、新建用户以安全方式运行进程
  
[root@soysauce ~]# groupadd -g 3306 mysql
[root@soysauce ~]# useradd -u 3306 -g mysql -M -s /sbin/nologin -d /mydata/data/ mysql  3、安装并初始化mysql-5.6.26
  
解压并初始化mysql
[root@soysauce ~]# cd /tmp/
[root@soysauce ~]# tar xf mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz -C /usr/local/
[root@soysauce ~]# cd /usr/local/
[root@soysauce local]# ln -sv mysql-5.6.26-linux-glibc2.5-x86_64  mysql
create symbolic link `mysql' to `mysql-5.6.26-linux-glibc2.5-x86_64'
[root@soysauce local]# cd mysql
[root@soysauce mysql]# chown -R root.mysql ./*
[root@soysauce mysql]# ll
total 240
drwxr-xr-x 2 root mysql 4096 Jan 16 12:48 bin
-rw-r--r-- 1 root mysql 17987 Jul 15 2015 COPYING
drwxr-xr-x 3 root mysql 4096 Jan 16 12:49 data
drwxr-xr-x 2 root mysql 4096 Jan 16 12:49 docs
drwxr-xr-x 3 root mysql 4096 Jan 16 12:48 include
-rw-r--r-- 1 root mysql 104897 Jul 15 2015 INSTALL-BINARY
drwxr-xr-x 3 root mysql 4096 Jan 16 12:49 lib
drwxr-xr-x 4 root mysql 4096 Jan 16 12:49 man
-rw-r--r-- 1 root root 1439 Jan 16 22:05 my.cnf
drwxr-xr-x 10 root mysql 4096 Jan 16 12:49 mysql-test
-rw-r--r-- 1 root mysql 2496 Jul 15 2015 README
drwxr-xr-x 2 root mysql 4096 Jan 16 12:49 scripts
drwxr-xr-x 28 root mysql 4096 Jan 16 12:49 share
drwxr-xr-x 4 root mysql 4096 Jan 16 12:49 sql-bench
drwxr-xr-x 2 root mysql 4096 Jan 16 12:49 support-files
初始化mysql
[root@soysauce mysql]# scripts/mysql_install_db --user=mysql --datadir=/mydata/data/
Installing MySQL system tables...2016-01-19 10:03:08 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-01-19 10:03:08 0 [Note] ./bin/mysqld (mysqld 5.6.26) starting as process 3958 ...
2016-01-19 10:03:09 3958 [Note] InnoDB: Using atomics to ref count buffer pool pages
2016-01-19 10:03:09 3958 [Note] InnoDB: The InnoDB memory heap is disabled
2016-01-19 10:03:09 3958 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2016-01-19 10:03:09 3958 [Note] InnoDB: Memory barrier is not used
2016-01-19 10:03:09 3958 [Note] InnoDB: Compressed tables use zlib 1.2.3
2016-01-19 10:03:09 3958 [Note] InnoDB: Using Linux native AIO
2016-01-19 10:03:09 3958 [Note] InnoDB: Not using CPU crc32 instructions
2016-01-19 10:03:09 3958 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2016-01-19 10:03:09 3958 [Note] InnoDB: Completed initialization of buffer pool
2016-01-19 10:03:09 3958 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2016-01-19 10:03:09 3958 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2016-01-19 10:03:09 3958 [Note] InnoDB: Database physically writes the file full: wait...
2016-01-19 10:03:10 3958 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2016-01-19 10:03:14 3958 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2016-01-19 10:03:17 3958 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2016-01-19 10:03:17 3958 [Warning] InnoDB: New log files created, LSN=45781
2016-01-19 10:03:17 3958 [Note] InnoDB: Doublewrite buffer not found: creating new
2016-01-19 10:03:17 3958 [Note] InnoDB: Doublewrite buffer created
2016-01-19 10:03:17 3958 [Note] InnoDB: 128 rollback segment(s) are active.
2016-01-19 10:03:17 3958 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-01-19 10:03:17 3958 [Note] InnoDB: Foreign key constraint system tables created
2016-01-19 10:03:17 3958 [Note] InnoDB: Creating tablespace and datafile system tables.
2016-01-19 10:03:17 3958 [Note] InnoDB: Tablespace and datafile system tables created.
2016-01-19 10:03:17 3958 [Note] InnoDB: Waiting for purge to start
2016-01-19 10:03:17 3958 [Note] InnoDB: 5.6.26 started; log sequence number 0
2016-01-19 10:03:19 3958 [Note] Binlog end
2016-01-19 10:03:19 3958 [Note] InnoDB: FTS optimize thread exiting.
2016-01-19 10:03:19 3958 [Note] InnoDB: Starting shutdown...
2016-01-19 10:03:20 3958 [Note] InnoDB: Shutdown completed; log sequence number 1625977
OK
Filling help tables...2016-01-19 10:03:20 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-01-19 10:03:20 0 [Note] ./bin/mysqld (mysqld 5.6.26) starting as process 3980 ...
2016-01-19 10:03:20 3980 [Note] InnoDB: Using atomics to ref count buffer pool pages
2016-01-19 10:03:20 3980 [Note] InnoDB: The InnoDB memory heap is disabled
2016-01-19 10:03:20 3980 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2016-01-19 10:03:20 3980 [Note] InnoDB: Memory barrier is not used
2016-01-19 10:03:20 3980 [Note] InnoDB: Compressed tables use zlib 1.2.3
2016-01-19 10:03:20 3980 [Note] InnoDB: Using Linux native AIO
2016-01-19 10:03:20 3980 [Note] InnoDB: Not using CPU crc32 instructions
2016-01-19 10:03:20 3980 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2016-01-19 10:03:21 3980 [Note] InnoDB: Completed initialization of buffer pool
2016-01-19 10:03:21 3980 [Note] InnoDB: Highest supported file format is Barracuda.
2016-01-19 10:03:21 3980 [Note] InnoDB: 128 rollback segment(s) are active.
2016-01-19 10:03:21 3980 [Note] InnoDB: 5.6.26 started; log sequence number 1625977
2016-01-19 10:03:21 3980 [Note] Binlog end
2016-01-19 10:03:21 3980 [Note] InnoDB: FTS optimize thread exiting.
2016-01-19 10:03:21 3980 [Note] InnoDB: Starting shutdown...
2016-01-19 10:03:22 3980 [Note] InnoDB: Shutdown completed; log sequence number 1625987
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
  ./bin/mysqladmin -u root password 'new-password'
  ./bin/mysqladmin -u root -h soysauce password 'new-password'
Alternatively you can run:
  ./bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
  cd . ; ./bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
  cd mysql-test ; perl mysql-test-run.pl
Please report any problems at http://bugs.mysql.com/
The latest information about MySQL is available on the web at
  http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
WARNING: Found existing config file ./my.cnf on the system.
Because this file might be in use, it was not replaced,
but was used in bootstrap (unless you used --defaults-file)
and when you later start the server.
The new default config file was created as ./my-new.cnf,
please compare it with your file and take the changes you need.  4、为mysql提供主配置文件
[root@soysauce mysql]# cp support-files/my-default.cnf  /etc/my.cnf
[root@soysauce mysql]# vim /etc/my.cnf
[root@soysauce mysql]# tail -5 /etc/my.cnf
[mysqld]
datadir = /mydata/data
innodb_file_per_table = ON
log-bin = master-bin
socket = /tmp/mysql.sock  5、为mysql提供sysv服务脚本
[root@soysauce mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@soysauce mysql]# chkconfig --add mysqld
[root@soysauce mysql]# chkconfig mysqld on
[root@soysauce mysql]# chkconfig --list mysqld
mysqld         0:off1:off2:on3:on4:on5:on6:off  6、输出man文档路径、库文件路径头文件路径、PATH环境变量
输出man文档路径
[root@soysauce ~]# vim /etc/man.config
MANPATH  /usr/local/mysql/man
输出库文件路径
[root@soysauce ~]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
[root@soysauce ~]# ldconfig
输出头文件路径
[root@soysauce ~]# ln -sv /usr/local/mysql/include  /usr/include/mysql
输出PATH环境变量
[root@soysauce ~]# echo 'export PATH=$PATH:/usr/local/mysql/bin/mysql' > /etc/profile.d/mysql.sh
[root@soysauce ~]# . /etc/profile.d/mysql.sh  7、启动mysql
[root@soysauce mysql]# service mysqld start
Starting MySQL........                                     [  OK  ]
查看监听端口
[root@soysauce mysql]# netstat -tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address       Foreign Address     State       PID/Program name   
tcp        0      0 0.0.0.0:111         0.0.0.0:*LISTEN      2820/portmap        
tcp        0      0 0.0.0.0:80          0.0.0.0:*           LISTEN      3197/nginx         
tcp        0      0 0.0.0.0:22          0.0.0.0:*           LISTEN      25126/sshd         
tcp        0      0 127.0.0.1:6010      0.0.0.0:*           LISTEN      24814/sshd         
tcp        0      0 0.0.0.0:922         0.0.0.0:*           LISTEN      2860/rpc.statd      
tcp        0      0 127.0.0.1:6011      0.0.0.0:*           LISTEN      24814/sshd         
tcp        0      0 127.0.0.1:6012      0.0.0.0:*           LISTEN      3461/sshd           
tcp        0      0 :::3306             :::*                LISTEN      5407/mysqld         
tcp        0      0 :::22               :::*                LISTEN      25126/sshd         
tcp        0      0 ::1:6010            :::*                LISTEN      24814/sshd         
tcp        0      0 ::1:6011            :::*                LISTEN      24814/sshd         
tcp        0      0 ::1:6012            :::*                LISTEN      3461/sshd     
连接测试
[root@soysauce mysql]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.26-log MySQL Community Server (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (1.61 sec)
mysql> \q
Bye  

  四、编译安装PHP
  1、解决依赖关系
[root@soysauce php-5.6.17]# yum install -y libmcrypt-devel libxml2-devl bzip2-devel libcurl-devel  2、编译安装php

[root@soysauce ~]# tar xf php-5.6.17.tar.gz
[root@soysauce ~]# cd php-5.6.17
[root@soysauce php-5.6.17]# ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql \
--enable-fpm --enable-sockets --enable-sysvshm  --with-mysqli=/usr/local/mysql/bin/mysql_config \
--enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib-dir \
--with-libxml-dir=/usr --enable-xml  --with-mhash --with-mcrypt  --with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d --with-bz2 --with-curl --with-gd --with-openssl
编译安装
[root@soysauce php-5.6.17]# make
[root@soysauce php-5.6.17]# make test
[root@soysauce php-5.6.17]# make install
为php提供配置文件
[root@soysauce php-5.6.17]# cp php.ini-production /etc/php.ini  3、配置php-fpm
为php-fpm提供Sysv init脚本
[root@soysauce php-5.6.17]# cp sapi/fpm/init.d.php-fpm  /etc/rc.d/init.d/php-fpm
[root@soysauce php-5.6.17]# chmod +x /etc/rc.d/init.d/php-fpm
[root@soysauce php-5.6.17]# chkconfig --add php-fpm
[root@soysauce php-5.6.17]# chkconfig php-fpm on
[root@soysauce php-5.6.17]# chkconfig --list php-fpm
php-fpm        0:off1:off2:on3:on4:on5:on6:off
为php-fpm提供配置文件
[root@soysauce php-5.6.17]# cd /usr/local/php/etc/
[root@soysauce etc]# cp php-fpm.conf.default php-fpm.conf
编辑php-fpm的配置文件
[root@soysauce etc]# vim /usr/local/php/etc/php-fpm.d/www.conf.default
pm.max_children = 150
pm.start_servers = 8
pm.min_spare_servers = 5
pm.max_spare_servers = 10
pid = /usr/local/php/var/run/php-fpm.pid  4、启动php-fpm
[root@soysauce php-5.6.17]# service php-fpm start
查看监听端口
[root@soysauce php-5.6.17]# netstat -tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address        Foreign Address    State       PID/Program name   
tcp        0      0 127.0.0.1:9000       0.0.0.0:*          LISTEN      25645/php-fpm      
tcp        0      0 0.0.0.0:111          0.0.0.0:*          LISTEN      2820/portmap        
tcp        0      0 0.0.0.0:80           0.0.0.0:*          LISTEN      25846/nginx         
tcp        0      0 0.0.0.0:22           0.0.0.0:*          LISTEN      25126/sshd         
tcp        0      0 0.0.0.0:922          0.0.0.0:*          LISTEN      2860/rpc.statd      
tcp        0      0 127.0.0.1:6012       0.0.0.0:*          LISTEN      3461/sshd           
tcp        0      0 127.0.0.1:6014       0.0.0.0:*          LISTEN      12959/sshd         
tcp        0      0 :::3306              :::*               LISTEN      5669/mysqld         
tcp        0      0 :::22                :::*               LISTEN      25126/sshd         
tcp        0      0 ::1:6012             :::*               LISTEN      3461/sshd           
tcp        0      0 ::1:6014             :::*               LISTEN      12959/sshd  

  五、整合Nginx和PHP
  1、编辑/etc/nginx/nginx.conf,启用如下选项
[root@soysauce php-5.6.17]# vim /etc/nginx/nginx.conf
location ~ \.php$ {
            root       /web/html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi_params;
        }  2、编辑/etc/nginx/fastcgi_params,将其内容更改为如下内容
[root@soysauce php-5.6.17]# vim /etc/nginx/fastcgi_params
fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx;
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;
fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;  3、在所支持的主页面格式中添加php格式的主页
[root@soysauce php-5.6.17]# vim /etc/nginx/nginx.conf
location / {
            root   /web/html;
            index  index.php index.html index.htm;
        }

新建index.php测试页
cat > /web/html/index.php << EOF
<?php
phpinfo();
?>
重启nginx服务
[root@soysauce ~]# service nginx start
Starting nginx:                                            [  OK  ]  打开浏览器访问测试
DSC0001.jpg

  

  六、编译安装Xcache
  1、编译安装Xcache

[root@soysauce ~]# tar xf xcache-3.2.0.tar.gz
[root@soysauce ~]# # cd xcache-3.2.0
[root@soysauce xcache-3.2.0]# /usr/local/php/bin/phpize
[root@soysauce xcache-3.2.0]# ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config
[root@soysauce xcache-3.2.0]# make && make install  2、编辑php.ini,整合php和xcache
[root@soysauce xcache-3.2.0]# mkdir /etc/php.d
[root@soysauce xcache-3.2.0]# cp xcache.ini /etc/php.d  3、重新启动php-fpm
[root@soysauce xcache-3.2.0]# service php-fpm restart
Stopping php-fpm:                                          [  OK  ]
Starting php-fpm:                                          [  OK  ]  

  再次用浏览器访问测试,可以看到Xcache已经被整合进php了
DSC0002.jpg

  

  到此一个基本的LNMP平台搭建完成
  

  

  

  

  

  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-452658-1-1.html 上篇帖子: Linux 服务器如何禁止 ping 以及开启 ping 下篇帖子: CentOS 国内yum源
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表