技术更新,好久没有更新开发环境了,根据官方文档和网友的分享吧工作环境编译了一遍,过程分享给大家。
centos 7最小化安装(CentOS-7-x86_64-Minimal-1511.iso)

yum search ifconfig 不然自己ip都看不到
yum install net-tools.x86_64 wget

1
2
3
# cd /etc/yum.repos.d/
# cp CentOS-Base.repo CentOS-Base.repo.backup
# wget -O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

安装系统包

1
# yum -y install wget python-lockfile lrzsz bison vim cmake unzip gcc gcc-c++ make automake autoconf curl curl-devel 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 e2fsprogs e2fsprogs-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel openldap-clients openldap-servers libevent libevent-devel net-tools nss_ldap pcre-devel gd kernel kernel-headers perl php-common php-gd libtool* patch libmcrypt libmcrypt-devel

如果没有mkdir命令,yum install python-lockfile
如果 libmcrypt libmcrypt-devel 没找到

下载libmcrypt(https://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz/download)

下载mash(https://sourceforge.net/projects/mhash/)

下载mcrypt(https://sourceforge.net/projects/mcrypt/files/latest/download)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# tar xzf libmcrypt-2.5.8.tar.gz
# cd libmcrypt-2.5.8
# ./configure
# make && make install
#
# tar xzf mhash-0.9.9.9.tar.gz
# cd mhash-0.9.9.9
# ./configure
# make && make install
#
# tar xzf mcrypt-2.6.8.tar.gz
# cd mcrypt-2.6.8
# LD_LIBRARY_PATH=/usr/local/lib ./configure
# make && make install

安装Nginx

官网下载最新版本(http://nginx.org/)

1
2
3
4
# tar xzf nginx-1.10.1.tar.gz
# cd nginx-1.10.1
# ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --pid-path=/usr/local/nginx/nginx.pid --conf-path=/usr/local/nginx/nginx.conf
# make && make install

nginx启动的shell: /etc/rc.d/init.d/nginx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#! /bin/bash
# chkconfig: 35 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse
set -e
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="nginx daemon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
SCRIPTNAME=/etc/init.d/$NAME
test -x $DAEMON || exit 0
d_start(){
    $DAEMON || echo -n " already running"
}
d_stop() {
    $DAEMON -s quit || echo -n " not running"
}
d_reload() {
    $DAEMON -s reload || echo -n " counld not reload"
}
case "$1" in
start)
    echo -n "Starting $DESC:$NAME"
    d_start
    echo "."
;;
stop)
    echo -n "Stopping $DESC:$NAME"
    d_stop
    echo "."
;;
reload)
    echo -n "Reloading $DESC configuration..."
    d_reload
    echo "reloaded."
;;
restart)
    echo -n "Restarting $DESC: $NAME"
    d_stop
    sleep 2
    d_start
    echo "."
;;
*)
    echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2
    exit 3
;;
esac
exit 0

启动 nginx

1
# service nginx start

编译PHP

php.net 官网下载PHP7(http://php.net/downloads.php)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# tar xzf php-7.0.8.tar.gz
# cd php-7.0.8
# ./configure --prefix=/usr/local/php7 \
--with-config-file-path=/usr/local/php7/etc \
--with-config-file-scan-dir=/usr/local/php7/etc/php.d \
--with-mcrypt=/usr/include \
--enable-mysqlnd \
--with-mysqli \
--with-pdo-mysql \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--with-gd \
--with-iconv \
--with-zlib \
--enable-xml \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--enable-mbregex \
--enable-mbstring \
--enable-ftp \
--enable-gd-native-ttf \
--with-openssl \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--without-pear \
--with-gettext \
--enable-session \
--with-curl \
--with-jpeg-dir \
--with-freetype-dir \
--enable-opcache
# make && make install
# cp php.ini-production  /usr/local/php7/etc/php.ini
# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
# chmod +x /etc/init.d/php-fpm
# chkconfig --add php-fpm
# chkconfig php-fpm on
#
# cd /usr/local/php7/etc
# cp php-fpm.conf.default php-fpm.conf
# cp php-fpm.d/www.conf.default php-fpm.d/www.conf
#
# service php-fpm start

此时应该可以通过 验证PHP的安装信息了
修改nginx的php相关配置

1
2
3
4
5
6
7
8
9
10
11
        location ~ \.php {
            root           /media/psf/Home/Documents/website;
               proxy_buffer_size  128k;
               proxy_buffers   32 32k;
               proxy_busy_buffers_size 128k;
               fastcgi_pass    127.0.0.1:9000;
               fastcgi_index   index.php;
               fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
               fastcgi_param  PHP_VALUE        open_basedir=$document_root:/tmp/:/proc/;
               include fastcgi_params;
        }

编译MySQL

mysql 官网下载(http://dev.mysql.com/downloads/mysql/)
网页下面的 Select Platform 选择 Source Code,
下载网页下面的 mysql-5.7.13.tar.gz mysql-boost-5.7.13.tar.gz

1
2
3
4
5
6
7
8
9
# groupadd mysql
# useradd -g mysql mysql
# usermod -s /bin/false mysql
# mkdir -p /data/mysql
# chown mysql:mysql /data/mysql
#
# tar xzf mysql-boost-5.7.13.tar.gz
# tar xzf mysql-5.7.13.tar.gz
# cd mysql-5.7.13

从MySQL 5.7.5开始Boost库是必需的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysql \
-DWITH_BOOST=boost \
-DSYSCONFDIR=/usr/local/mysql/etc \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DENABLE_DTRACE=0 \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DWITH_EMBEDDED_SERVER=1
# make && make install
# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
# chmod +x /etc/init.d/mysqld
# chkconfig --add mysqld
# chkconfig mysqld on
#
# /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql/
# mkdir /var/run/mariadb
# chown mysql:mysql -R /var/run/mariadb
# mkdir /var/log/mariadb
# chown mysql:mysql -R /var/log/mariadb
# service mysqld start
 
# /usr/local/mysql/bin/mysql -uroot -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
mysql> flush privileges;
mysql> exit;

此时可以安装一个phpMyAdmin测试一下数据库了。

安装redis

官网:http://redis.io/
下载 redis 目前最新版是:redis-3.2.1.tar.gz

1
2
3
4
5
6
# tar xzf redis-3.2.1.tar.gz
# cd redis-3.2.1
# make PREFIX=/usr/local/redis install
# mkdir /usr/local/redis/etc
# cp redis.conf /usr/local/redis/etc/6379.conf
# mkdir /data/redis

修改配置文件/usr/local/redis/etc/6379.conf
dir 参数改为 /data/redis
daemonize 参数改为 yes

1
# vim /etc/init.d/redis

添加启动shell

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/sh
# chkconfig: 2345 10 90
# description: Start and Stop redis
 
REDISPORT=6379
EXEC=/usr/local/redis/bin/redis-server
REDIS_CLI=/usr/local/redis/bin/redis-cli
 
PIDFILE=/data/redis/6379.pid
CONF="/usr/local/redis/etc/6379.conf"
 
case "$1" in
    start)
        if [ -f $PIDFILE ]
        then
                echo "$PIDFILE exists, process is already running or crashed."
        else
                echo "Starting Redis server..."
                $EXEC $CONF
        fi
        if [ "$?"="0" ]
        then
                echo "Redis is running..."
        fi
        ;;
    stop)
        if [ ! -f $PIDFILE ]
        then
                echo "$PIDFILE exists, process is not running."
        else
                PID=$(cat $PIDFILE)
                echo "Stopping..."
               $REDIS_CLI -p $REDISPORT  SHUTDOWN
                sleep 2
               while [ -x $PIDFILE ]
               do
                        echo "Waiting for Redis to shutdown..."
                       sleep 1
                done
                echo "Redis stopped"
        fi
        ;;
    restart|force-reload)
        ${0} stop
        ${0} start
        ;;
    *)
    echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2
    exit 1
esac

启动redis服务

1
# service redis start

redis安装完成,如果需要多个redis服务,可以cp多个配置文件和多个redis服务器脚本

安装redis for php模块

官网下载(https://github.com/phpredis/phpredis)

1
2
3
4
5
6
7
unzip phpredis-develop.zip
cd phpredis-develop
/usr/local/php7/bin/phpize
./configure --with-php-config=/usr/local/php7/bin/php-config
make
make install
vim /usr/local/php7/etc/php.ini +

添加一行

1
extension=redis.so

重启php-fpm

1
service php-fpm restart

此时查看phpinfo的页面,应该可以看到redis模块的信息

安装swoole模块

官网下载(https://github.com/swoole/swoolw-src/releases)

1
2
3
4
5
6
# mv 1.8.6-stable.tar.gz swoole-1.8.6-stable.tar.gz
# tar xzf swoole-1.8.6-stable.tar.gz
# cd swoole-src-1.8.6-stable/
# ./configure --with-php-config=/usr/local/php7/bin/php-config
# make && make install
# vim /usr/local/php7/etc/php.ini +

添加一行

1
extension=swoole.so

重启php-fpm

1
service php-fpm restart

此时查看phpinfo的页面,应该可以看到swoole模块的信息

安装 Node.js

官网下载(https://nodejs.org/en/download/)

1
2
3
4
5
6
# tar xzf node-v4.4.6.tar.gz
# cd node-v4.4.6
# ./configure --prefix=/usr/local/node
# make && make install
#
# vim + /etc/profile

最后增加一行

1
export PATH=/usr/local/mysql/bin:/usr/local/php7/bin:/usr/local/node/bin:$PATH

立即生效

1
# source /etc/profile

安装pm2

1
# npm install -g pm2

注意:本站博文均系原创,欢迎转载,请注明出处和原网址