您当前的位置:首页 > php

CentOS 7编译安装Tengine+PHP+MariaDB全程笔记

环境是 7 64bit,Updated 9 July 2014。512M内存虚拟机。pRnlinux系统宝典
先更新下系统:pRnlinux系统宝典

  1. [root@linuxidc ~]# yum update -y

安装必要软件:pRnlinux系统宝典

  1. [root@linuxidc ~]# yum install gcc automake autoconf libtool make gcc-c++ zlib-devel openssl-devel vim which bzip2 -y

编译安装pcre:pRnlinux系统宝典

  1. [root@linuxidc ~]# cd /usr/local/src/
  2. [root@linuxidc src]# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.35.tar.gz
  3. [root@linuxidc src]# tar zvxf pcre-8.35.tar.gz
  4. [root@linuxidc src]# cd pcre-8.35
  5. [root@linuxidc pcre-8.35]#./configure
  6. [root@linuxidc pcre-8.35]# make && make install

编译安装openssl:pRnlinux系统宝典

  1. [root@linuxidc pcre-8.35]# cd /usr/local/src/
  2. [root@linuxidc src]# wget http://www.openssl.org/source/openssl-1.0.1h.tar.gz
  3. [root@linuxidc src]# tar zvxf openssl-1.0.1h.tar.gz
  4. [root@linuxidc src]# cd openssl-1.0.1h
  5. [root@linuxidc openssl-1.0.1h]#./config
  6. [root@linuxidc openssl-1.0.1h]# make && make install

编译安装zlibpRnlinux系统宝典

  1. [root@linuxidc openssl-1.0.1h]# cd /usr/local/src/
  2. [root@linuxidc src]# wget http://zlib.net/zlib-1.2.8.tar.gz
  3. [root@linuxidc src]# tar zvxf zlib-1.2.8.tar.gz
  4. [root@linuxidc src]# cd zlib-1.2.8
  5. [root@linuxidc zlib-1.2.8]#./configure
  6. [root@linuxidc zlib-1.2.8]# make && make install

编译安装jemalloc:pRnlinux系统宝典

  1. [root@linuxidc zlib-1.2.8]# cd /usr/local/src/
  2. [root@linuxidc src]# wget http://www.canonware.com/download/jemalloc/jemalloc-3.6.0.tar.bz2
  3. [root@linuxidc src]# tar jxvf jemalloc-3.6.0.tar.bz2
  4. [root@linuxidc src]# cd jemalloc-3.6.0
  5. [root@linuxidc jemalloc-3.6.0]#./configure
  6. [root@linuxidc jemalloc-3.6.0]# make && make install
  7. [root@linuxidc jemalloc-3.6.0]# echo '/usr/local/lib'>/etc/ld.so.conf.d/local.conf
  8. [root@linuxidc jemalloc-3.6.0]# ldconfig
  9. 建立www用户组和用户,禁止www登陆shell
  10. [root@linuxidc jemalloc-3.6.0]# groupadd www
  11. [root@linuxidc jemalloc-3.6.0]# useradd -g www www
  12. [root@linuxidc jemalloc-3.6.0]# usermod -s /sbin/nologin www

创建虚拟主机使用目录,并赋予相应权限:pRnlinux系统宝典

  1. [root@linuxidc jemalloc-3.6.0]# mkdir -p /usr/www/example.com/{public_html,logs}
  2. [root@linuxidc jemalloc-3.6.0]# chmod -R +w /usr/www/
  3. [root@linuxidc jemalloc-3.6.0]# chown -R www:www /usr/www/

编译安装Tengine:pRnlinux系统宝典

  1. [root@linuxidc jemalloc-3.6.0]# cd /usr/local/src/
  2. [root@linuxidc src]# wget http://tengine.taobao.org/download/tengine-2.0.3.tar.gz
  3. [root@linuxidc src]# tar zvxf tengine-2.0.3.tar.gz
  4. [root@linuxidc src]# cd tengine-2.0.3
  5. [root@linuxidc tengine-2.0.3]#./configure --prefix=/usr/local/nginx
  6. --user=www --group=www
  7. --with http_stub_status_module
  8. --with-http_ssl_module
  9. --with-http_gzip_static_module
  10. --with-openssl=/usr/local/src/openssl-1.0.1h
  11. --with-zlib=/usr/local/src/zlib-1.2.8
  12. --with-pcre=/usr/local/src/pcre-8.35
  13. --with-jemalloc
  14. [root@linuxidc tengine-2.0.3]# make && make install

修改nginx.conf文件:pRnlinux系统宝典

  1. [root@linuxidc tengine-2.0.3]# mkdir /usr/local/nginx/conf/domains
  2. [root@linuxidc tengine-2.0.3]# vim /usr/local/nginx/conf/nginx.conf

修改pRnlinux系统宝典

  1. #user nobody;
  2. worker_processes 1;
  3. #error_log logs/error.log;
  4. #error_log logs/error.log notice;
  5. #error_log logs/error.log info;
  6. #pid logs/nginx.pid;
  7. events {
  8. worker_connections 1024;
  9. }

pRnlinux系统宝典

  1. user www www;
  2. worker_processes 4;
  3. error_log logs/error.log crit;
  4. #error_log logs/error.log notice;
  5. #error_log logs/error.log info;
  6. pid logs/nginx.pid;
  7. events {
  8. use epoll;
  9. worker_connections 65535;
  10. }

修改pRnlinux系统宝典

  1. http {
  2. include mime.types;
  3. default_type application/octet-stream;

pRnlinux系统宝典

  1. http {
  2. include mime.types;
  3. include domains/*.conf;
  4. default_type application/octet-stream;

:wq保存pRnlinux系统宝典
测试Nginx:pRnlinux系统宝典

  1. [root@linuxidc tengine-2.0.3]# cd /usr/local/nginx
  2. [root@linuxidc nginx]# ldconfig
  3. [root@linuxidc nginx]#./sbin/nginx -t

输出pRnlinux系统宝典

  1. the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
  2. configuration file /usr/local/nginx/conf/nginx.conf test is successful

测试成功pRnlinux系统宝典
添加Nginx到开机自动启动:pRnlinux系统宝典

  1. [root@linuxidc nginx]# vim /usr/lib/systemd/system/nginx.service

加入pRnlinux系统宝典
[pRnlinux系统宝典

  1. Unit]
  2. Description=The nginx HTTP and reverse proxy server
  3. After=syslog.target network.target remote-fs.target nss-lookup.target
  4. [Service]
  5. Type=forking
  6. PIDFile=/usr/local/nginx/logs/nginx.pid
  7. ExecStartPre=/usr/local/nginx/sbin/nginx -t
  8. ExecStart=/usr/local/nginx/sbin/nginx
  9. ExecReload=/bin/kill -s HUP $MAINPID
  10. ExecStop=/bin/kill -s QUIT $MAINPID
  11. PrivateTmp=true
  12. [Install]
  13. WantedBy=multi-user.target

:wq保存pRnlinux系统宝典

  1. [root@linuxidc nginx]# systemctl enable nginx

关闭默认防火墙:pRnlinux系统宝典

  1. [root@linuxidc nginx]# systemctl stop firewalld.service
  2. [root@linuxidc nginx]# systemctl disable firewalld.service

安装iptables并开启80端口pRnlinux系统宝典

  1. [root@linuxidc nginx]# yum install iptables-services -y
  2. [root@linuxidc nginx]# vim /etc/sysconfig/iptables

增加pRnlinux系统宝典

  1. -A INPUT -p tcp -m state --state NEW -m tcp --dport 80-j ACCEPT

因为这台VPS的SSH端口为60000,修改pRnlinux系统宝典

  1. -A INPUT -p tcp -m state --state NEW -m tcp --dport 22-j ACCEPT

pRnlinux系统宝典

  1. -A INPUT -p tcp -m state --state NEW -m tcp --dport 60000-j ACCEPT

:wq保存pRnlinux系统宝典
重启iptables并设定开机自动启动:pRnlinux系统宝典

  1. [root@linuxidc nginx]# systemctl restart iptables.service
  2. [root@linuxidc nginx]# systemctl enable iptables.service

安装MariaDB:pRnlinux系统宝典

  1. [root@linuxidc nginx]# cd /etc/yum.repos.d/
  2. [root@linuxidc yum.repos.d]# vim MariaDB.repo

输入pRnlinux系统宝典

  1. # MariaDB 10.0 CentOS repository list - created 2014-09-30 09:33 UTC
  2. # http://mariadb.org/mariadb/repositories/
  3. [mariadb]
  4. name =MariaDB
  5. baseurl = http://yum.mariadb.org/10.0/centos7-amd64
  6. gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
  7. gpgcheck=1

:wq保存pRnlinux系统宝典

  1. [root@linuxidc yum.repos.d]# yum install MariaDB-server MariaDB-client -y

报错,存在冲突包,删除之pRnlinux系统宝典

  1. [root@linuxidc yum.repos.d]# rpm -ev net-snmp-1:5.7.2-18.el7.x86_64
  2. [root@linuxidc yum.repos.d]# rpm -ev mariadb-libs-1:5.5.37-1.el7_0.x86_64

再安装pRnlinux系统宝典

  1. [root@linuxidc yum.repos.d]# yum install MariaDB-server MariaDB-client -y

成功pRnlinux系统宝典
启动MariaDB服务并添加开机自动启动:pRnlinux系统宝典

  1. [root@linuxidc yum.repos.d]# service start mysql
  2. [root@linuxidc yum.repos.d]# chkconfig mysql on

安装编译PHP的必要应用:pRnlinux系统宝典

  1. [root@linuxidc yum.repos.d]# yum install -y gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng
  2. libpng-devel freetype freetype-devel libpng libpng-devel
  3. libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel
  4. glib2 glib2-devel bzip2 bzip2-devel ncurses curl openssl-devel
  5. gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel
  6. gmp-devel readline-devel libxslt-devel expat-devel xmlrpc-c xmlrpc-c-devel file

编译安装libmcrypt:pRnlinux系统宝典

  1. [root@linuxidc yum.repos.d]# cd /usr/local/src/
  2. [root@linuxidc src]# wget https://vps.googlecode.com/files/libmcrypt-2.5.8.tar.gz
  3. [root@linuxidc src]# tar zxvf libmcrypt-2.5.8.tar.gz
  4. [root@linuxidc src]# cd libmcrypt-2.5.8
  5. [root@linuxidc libmcrypt-2.5.8]#./configure
  6. [root@linuxidc libmcrypt-2.5.8]# make && make install

编译安装PHP:pRnlinux系统宝典

  1. [root@linuxidc libmcrypt-2.5.8]# cd /usr/local/src/
  2. [root@linuxidc src]# wget http://cn2.php.net/distributions/php-5.6.0.tar.gz
  3. [root@linuxidc src]# tar zxvf php-5.6.0.tar.gz
  4. [root@linuxidc src]# cd php-5.6.0
  5. [root@linuxidc php-5.6.0]#./configure --prefix=/usr/local/php-5.6.0
  6. --with-mysql --with-mysql-sock
  7. --with-mysqli --enable-fpm --enable-soap
  8. --with-libxml-dir --with-openssl --with-mcrypt
  9. --with-mhash --with-pcre-regex --with-sqlite3
  10. --with-zlib --enable-bcmath
  11. --with-iconv --with-bz2 --enable-calendar
  12. --with-curl --with-cdb --enable-dom --enable-exif --enable-fileinfo --enable-filter
  13. --with-pcre-dir --enable-ftp --with-gd --with-openssl-dir
  14. --with-jpeg-dir --with-png-dir --with-zlib-dir
  15. --with-freetype-dir --enable-gd-native-ttf --enable-gd-jis-conv
  16. --with-gettext --with-gmp --with-mhash --enable-json --enable-mbstring
  17. --disable-mbregex --disable-mbregex-backtrack --with-libmbfl
  18. --with-onig --enable-pdo --with-pdo-mysql --with-zlib-dir
  19. --with-pdo-sqlite --with-readline --enable-session --enable-shmop
  20. --enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem
  21. --enable-sysvshm --enable-wddx --with-libxml-dir --with-xsl --enable-zip
  22. --enable-mysqlnd-compression-support --with-pear --disable-fileinfo

因为只有512M内存所以加了--disable-fileinfo,不然编译会报错pRnlinux系统宝典

  1. [root@linuxidc php-5.6.0]# make && make install

复制配置文件:pRnlinux系统宝典

  1. [root@linuxidc php-5.6.0]# cp /usr/local/php-5.6.0/etc/php-fpm.conf.default/usr/local/php-5.6.0/etc/php-fpm.conf
  2. [root@linuxidc php-5.6.0]# cp /usr/local/src/php-5.6.0/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
  3. [root@linuxidc php-5.6.0]# cp /usr/local/src/php-5.6.0/php.ini-production /usr/local/php-5.6.0/lib/php.ini

修改配置文件:pRnlinux系统宝典

  1. [root@linuxidc php-5.6.0]# vim /usr/local/php-5.6.0/etc/php-fpm.conf

找到这些值修改pRnlinux系统宝典

  1. pm.max_children =50
  2. pm.start_servers =20
  3. pm.min_spare_servers =5
  4. pm.max_spare_servers =35

去掉pRnlinux系统宝典

  1. ;pm.max_requests =500

的注释,然后pRnlinux系统宝典
:wq保存pRnlinux系统宝典
设置php-fpm开机自动启动pRnlinux系统宝典

  1. [root@linuxidc php-5.6.0]# chmod a+x /etc/init.d/php-fpm
  2. [root@linuxidc php-5.6.0]# chkconfig php-fpm on

将PHP的bin目录加入环境变量:pRnlinux系统宝典

  1. [root@linuxidc php-5.6.0]# chmod +x /etc/profile
  2. [root@linuxidc php-5.6.0]# vim /etc/profile.d/php.sh

加入pRnlinux系统宝典

  1. PATH=$PATH:/usr/local/php5.6.0/bin
  2. export PATH

:wq保存pRnlinux系统宝典

  1. [root@linuxidc php-5.6.0]# chmod +x /etc/profile.d/php.sh
  2. [root@linuxidc php-5.6.0]# source /etc/profile
  3. [root@linuxidc php-5.6.0]# ln -s /usr/local/php-5.6.0/sbin/php-fpm /bin/php-fpm

创建网站配置文件:pRnlinux系统宝典

  1. [root@linuxidc php-5.6.0]# vim /usr/local/nginx/conf/domains/example.com.conf

输入pRnlinux系统宝典

  1. server {
  2. server_name example.com;
  3. listen 80;
  4. root /usr/www/example.com/public_html;
  5. access_log /usr/www/example.com/logs/access.log;
  6. error_log /usr/www/example.com/logs/error.log;
  7. index index.php;
  8. location /{
  9. try_files $uri $uri//index.php?q=$uri&$args;
  10. }
  11. location ~* /.(jpg|jpeg|gif|css|png|js|ico|html)$ {
  12. access_log off;
  13. expires max;
  14. }
  15. location ~//.ht {
  16. deny all;
  17. }
  18. location ~ /.php$ {
  19. fastcgi_pass 127.0.0.1:9000;
  20. fastcgi_index index.php;
  21. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  22. include /usr/local/nginx/conf/fastcgi_params;
  23. }
  24. }

:wq保存pRnlinux系统宝典
重启VPS:pRnlinux系统宝典

  1. [root@linuxidc php-5.6.0]# reboot

相关阅读pRnlinux系统宝典

CentOS 6.4制作Tengine的rpm包 pRnlinux系统宝典

Tengine动态开启模块试用 pRnlinux系统宝典

CentOS 6.3用ICC编译PHP5.4.8+Percona5.5.27+Tengine1.4.1 pRnlinux系统宝典

基于淘宝Tengine和Scribe的WEB日志收集方案 pRnlinux系统宝典

基于Tengine部署LNMP环境 pRnlinux系统宝典

Tengine 的详细介绍pRnlinux系统宝典
Tengine 的下载地址pRnlinux系统宝典



沪ICP备10206494号-4