centos7系统上架设nginx+php7+redis

首先直接用yum安装基础依赖库和工具
yum -y install gcc gcc-c++ autoconf automake make libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel pcre pcre-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 gd-devel wget git

1、安装nginx

wget http://nginx.org/download/nginx-1.14.0.tar.gz

tar -zxvf nginx-1.14.0.tar.gz

cd nginx-1.14.0

./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_flv_module --with-http_mp4_module --with-http_gzip_static_module --with-http_realip_module --with-http_secure_link_module --with-http_ssl_module


make && make install

groupadd -r www
useradd -r -g www -s /bin/false -M www

配置nginx自启动文件

vi /usr/lib/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=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

chmod +x /usr/lib/systemd/system/nginx.service

systemctl enable nginx

systemctl start nginx

2、安装php

到php官网下载相应的php7版本,然后解压

tar zxvf php-7.1.18.tar.gz

cd php-7.1.18

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-mbstring --enable-ftp --with-curl --enable-sockets --enable-soap --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-zlib-dir --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-gd-native-ttf --enable-exif --enable-libxml --enable-fpm --enable-pcntl --with-openssl

make && make install

设置php配置文件

cp php.ini-production /usr/local/php/etc/php.ini
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf

vi php-fpm.conf
    pid = run/php-fpm.pid

cd /usr/local/php/etc/php-fpm.d
cp www.conf.default www.conf

配置php自启动文件

vi /usr/lib/systemd/system/php-fpm.service

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

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

[Install]
WantedBy=multi-user.target

chmod +x /usr/lib/systemd/system/php-fpm.service

systemctl enable php-fpm

systemctl start php-fpm

3、安装php的redis扩展

wget http://pecl.php.net/get/redis-4.0.2.tgz

tar zxvf redis-4.0.2.tgz

cd redis-4.0.2

/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install

安装完成后,编辑php的配置文件
vi /usr/local/php/etc/php.ini

在最的一行添加
extension=redis.so

你可能感兴趣的:(服务器环境架设)