centOS 部署服务器(二)
(1)安装nginx
1.下载地址: http://nginx.org/en/download.html ,并解压到目录下
2.安装依赖包 yum -y install pcre* yum -y install openssl*
如果安装出现在下面的错误是缺少编译环境。安装编译源码所需的工具和库
./configure: error: C compiler cc is not found
#yum install gcc gcc-c++ ncurses-devel perl
3.执行./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --with-pcre
编译make,make install(如果是非root用户 make 和sudo make install 分开 同理,其他的安装包也是这样)
# mkdir vhost
# vim ./nginx.conf (在最后大括号前添加一行并保存退出: include vhost/*.conf; )
6. 可在vhost目录内新建虚拟主机配置文件,以.conf结尾,内容可参考nginx.conf中的server部分
(2)安装php:
1.下载地址:http://php.net/downloads.php
2.安装依赖包 :yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel
3. 由于centOS没有libmcrypt,所以要先下载第三方源
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysqli --with-iconv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-zlib --enable-pdo --with-pdo-mysql --enable-opcache
然后先make 如果不是root用户则要实用sudo make install
修改php.ini文件
extension=exif.so(添加php图片扩展)
(3)安装composer
curl -sS https://getcomposer.org/installer | php
执行这个命令前要建立php的软连接,ln -s /usr/local/php/bin/php /usr/local/bin
mv composer.phar /usr/local/bin/composer
(4)安装redis
1.下载地址:wget http://download.redis.io/redis-stable.tar.gz
2.解压以及编译: 进入到redis目录,将配置文件redis.conf复制到/etc/redis/6379.conf(当然得新建/etc/redis目录)
make
make PREFIX=/usr/local/redis install
拷贝运行命令:
cp /usr/local/redis/bin/redis-server /usr/local/bin
cp /usr/local/redis/bin/redis-cli /usr/local/bin
修改配置信息:
mkdir /etc/redis
cp redis.conf /etc/redis/6379.conf
mkdir /var/lib/redi
s
mkdir /var/redis
mkdir /var/redis/log
mkdir /var/redis/run
3.修改6379.conf :
bind 127.0.0.1(默认连接到主机)
daemonize yes(这个是设置服务在后台运行)
dir /home/redis_db(将其权限设置为777)
pidfile /var/redis/run/6379.pid
logfile /var/redis/log/6379.log
pidfile /tmp/redis.pid
requirepass yourPassword
redis-server /etc/redis/6379.conf 运行redis
4.通过phpize安装 phpredis :
使用phpredis会遇到
Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable. Then, rerun this script
这时就要要yum -y install m4 autoconf
①git clone https://github.com/phpredis/phpredis.git cd phpredis
②如果是php
7,则要先切换到php7分支:git checkout -b php7 origin/php7
③检查PHP扩展:/usr/local/php/bin/phpize (不然不会出现configure文件)
④建立编译连接:./configure --with-php-config=/usr/local/php/bin/php-config
⑤make
⑥make install
⑦会看到 /usr/local/php/lib/php/extensions/no-debug-non-zts-20151012/
目录下面多了个redis.so文件
⑧修改php.ini vim /usr/local/php/etc/php.ini,
post_max_size = 50M(原来为8M)
upload_max_filesize = 64M
添加 extension=redis.so
添加 extension=exif.so
⑨重启nginx和php-fpm,启动redis-service(redis-service /etc/redis/6379.conf) 输入phpinfo() 就会看到如下图:
![](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA+8AAAC/CAIAAAAAfnoYAAAVrElEQVR4nO3dvU4i78MG4PdY5iy2N7Faz8EtiCdAa8sxYO8J2FvY2/+TTX7uGgsLSSiQEALKWwwwX88zwILA4HXlLtZhvkQZbx4e2P+bfbHPz8/JZPL+/t5qtR4fZyJytGm1Wv8BAP+q1Wr9/fv37e3t/f19Mpl8fn5+ddOezWb/99UH+OI2f3+ZJEnS7v7LrSJSSLzNP3TOr27XuYzdXiXnnYcdXhc5Q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yufRHGNTdv8Om/0zbX5+8qpKfQAu6fNA+zCit6+WFgzvf7i5mnTNr9qb7PoDjdu87H9FI+Wa/MXgfXVeYCd0+YBdqH2XbDVShwaXs+67nrz5tfZW+SzJp9u2vM9h+fNV3ad209uxdw3XV0v9AzGx10C7Jo2D7AL0TYfnnhTv+p6bX6NvUXnv1f3Wtvms69Lw+vlzeufYWjzADunzQPswkaTynfS5tfZ2+pPrNm0zde/6zX0QkP+INo8wK5p8wC7UNe161t63c7WG5uP7+1wY/PaPMB+aPMAu1D/HtXqJ9YUW/HTzUVwRs6a8+bje8u/ZFD4eJqL8rz5QtPeft68Ng+wH9o8wC6s+vzI6ptSSzZv82vtreYzbcK37+ozbbR5gL3Q5gF2IfJ/O1XHtGMT7P+hza+3t3APr/bv/Jabfd58/Qf0zLR5gC+kzQPsQvR/as235er0lvA267f5dfYWWKfmf6bd7P+CLU/Z1+YB9kybBwCAptLmAQCgqbR5AABoKm0eAACaSpsHAICm0uYBAKCptHkAAGgqbR4AAJpKmwcAgKbS5gEAoKm0eQAAaCptHgAAmkqbBwCAptLmAQCgqbR5AABoKm0eAACaSpsHAICm0uYBAKCptHkAAGgqbR4AAJrq/wGg9iBgRS7waAAAAABJRU5ErkJggg==)
5.添加php图片Exif信息拓展
默认情况下,PHP读取图片Exif信息模块是不开启的,我们需要先开启这个模块
cd /home/downloads/php-7.0.11/ext/exif(就是解压缩后php的目录)
phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
会看到 /usr/local/php/lib/php/extensions/no-debug-non-zts-20151012/
目录下面多了个exif.so文件