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

摘要:
此时,使用浏览器访问localhost以查看Tengine的欢迎界面。安装MariaDB。这里给出了使用yum源代码的安装方法。

  安装环境:CentOS7 3.10.0-693.5.2.el7.x86_64

  准备源码包:

    pcre-8.41.tar.gz

    openssl-1.0.1h.tar.gz

    zlib-1.2.11.tar.gz

    jemalloc-4.5.0.tar.bz2

    tengine-2.1.0.tar.gz

    libmcrypt-2.5.8.tar.gz

    php-7.1.11.tar.gz

  首先安装nginx

  安装基础依赖:

#yum install -y gcc automake autoconf libtool make gcc-c++ zlib-devel openssl-devel vim which bzip2

  编译安装pcre:

# tar zvxf pcre-8.41.tar.gz
# cd pcre-8.41
# ./configure --prefix=/usr/local/TPM
# make && make install

  编译安装openssl:

# tar zvxf openssl-1.0.1h.tar.gz
# cd openssl-1.0.1h
# ./config --prefix=/usr/local/TPM
# make && make install

  编译安装zlib:

# tar zvxf zlib-1.2.11.tar.gz
# cd zlib-1.2.11
# ./configure --prefix=/usr/local/TPM
# make && make install

  编译安装jemalloc:

# tar jxvf jemalloc-4.5.0.tar.bz2
# cd jemalloc-4.5.0
# ./configure --prefix=/usr/local/TPM
# make && make install

  建立www用户组和用户,禁止www登陆shell:

# groupadd www
# useradd -g www www
# usermod -s /sbin/nologin www

  创建虚拟主机使用目录,并赋予相应权限:

# mkdir -p /var/www/example.com/{public_html,logs}
# chmod -R +w /var/www/
# chown -R www:www /var/www/

  编译安装Tengine:

# cd /usr/local/src/
# wget http://tengine.taobao.org/download/tengine-2.1.0.tar.gz
# tar zvxf tengine-2.1.0.tar.gz
# cd tengine-2.1.0
# ./configure --prefix=/usr/local/TPM/nginx --user=www --group=www 
    --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module  
    --with-openssl=/usr/local/src/openssl-1.0.1h --with-zlib=/usr/local/src/zlib-1.2.11 
    --with-pcre=/usr/local/src/pcre-8.41 --with-jemalloc=/usr/local/src/jemalloc-4.5.0 
# make && make install

  修改nginx.conf文件:

# mkdir /usr/local/TPM/nginx/conf/domains
# vim /usr/local/TPM/nginx/conf/nginx.conf

  修改

#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}

  为

user www www;
worker_processes 4;
error_log logs/error.log crit;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid logs/nginx.pid;
events {
use epoll;
worker_connections 65535;
}

  修改

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

  为

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

  测试Nginx:

# cd /usr/local/nginx
# ldconfig
# ./sbin/nginx -t
//有以下输出信息则为测试成功
the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
configuration file /usr/local/nginx/conf/nginx.conf test is successful

  添加Nginx到开机自动启动:

# vim /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

  设定开机启动:

# systemctl enable nginx

  开启防火墙的80端口,或关闭防火墙(不推荐)。

  此时使用浏览器访问localhost可看到Tengine的欢迎界面。

  安装MariaDB

  此处给出使用yum源的安装方法。

  添加源:

# cd /etc/yum.repos.d/
# vim MariaDB.repo

  输入内容:

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

  安装MariaDB:

# yum install MariaDB-server MariaDB-client -y

  启动MariaDB服务并添加开机自动启动:

# systemctl start mysql
# systemctl enable mysql

  安装编译PHP

  安装编译PHP的依赖:

# yum install -y gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel 
    freetype freetype-devel libpng libpng-devel libxml2 libxml2-devel zlib 
    zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses 
    curl openssl-devel gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel 
    gmp-devel readline-devel libxslt-devel expat-devel xmlrpc-c xmlrpc-c-devel file

  编译安装libmcrypt:

# tar zxvf libmcrypt-2.5.8.tar.gz
# cd libmcrypt-2.5.8
# ./configure
# make && make install

  编译安装PHP:

# tar -zxvf php-7.1.11.tar.gz
# cd /tmp/build/php-7.1.11
# ./configure --prefix=/usr/local/TPM/php-7.1.11 --with-mysql --with-mysql-sock 
    --with-mysqli --enable-fpm --enable-soap --with-libxml-dir --with-openssl 
    --with-mcrypt=/usr/local/TPM/ --with-mhash --with-pcre-regex --with-sqlite3 
    --with-zlib --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl 
    --with-cdb --enable-dom --enable-exif --enable-fileinfo --enable-filter 
    --with-pcre-dir --enable-ftp --with-gd --with-openssl-dir --with-jpeg-dir 
    --with-png-dir --with-zlib-dir --with-freetype-dir --enable-gd-native-ttf 
    --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash --enable-json 
    --enable-mbstring --disable-mbregex --disable-mbregex-backtrack --with-libmbfl 
    --with-onig --enable-pdo --with-pdo-mysql --with-zlib-dir --with-pdo-sqlite 
    --with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets 
    --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-libxml-dir 
    --with-xsl --enable-zip --enable-mysqlnd-compression-support --enable-pcntl --with-pear
# make && make install

  复制配置文件及启动文件:

# cp /usr/local/TPM/php-7.1.11/etc/php-fpm.conf.default /usr/local/TPM/php-7.1.11/etc/php-fpm.conf
# cd /usr/local/TPM/php-7.1.11/etc/php-fpm.d/www.conf.default /usr/local/TPM/php-7.1.11/etc/php-fpm.d/www.conf
# cp /tmp/build/php-7.1.11/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

  设置php-fpm开机自动启动:

# chmod a+x /etc/init.d/php-fpm
# chkconfig php-fpm on

  将PHP的bin目录加入环境变量:

# chmod +x /etc/profile
# vim /etc/profile.d/php.sh

  输入内容:

PATH=$PATH:/usr/local/php5.6.32/bin
export PATH

  重载环境变量并配置启动文件:

# chmod +x /etc/profile.d/php.sh
# source /etc/profile
# ln -s /usr/local/TPM/php-7.1.11/sbin/php-fpm /bin/php-fpm

  创建网站配置文件:

# vim /usr/local/TPM/nginx/conf/domains/example.com.conf

  输入内容:

server {
    server_name example.com;
    listen 80;
    root /var/www/example.com/public_html;
    access_log /var/www/example.com/logs/access.log;
    error_log /var/www/example.com/logs/error.log;
    index index.php;
    location /{
    try_files $uri $uri//index.php?q=$uri&$args;
    }
    location ~* .(jpg|jpeg|gif|css|png|js|ico|html)$ {
    access_log off;
    expires max;
    }
    location ~/.ht {
    deny all;
    }
    location ~ .php$ {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include /usr/local/nginx/conf/fastcgi_params;
    }
}

  重启nginx:

# systemctl restart nginx

  创建测试phpinfo.php:

# cd /var/www/example.com/public_html
# vim phpinfo.php

  输入内容:

<?php
    phpinfo();
?>

  此时使用浏览器访问localhost/phpinfo.php可看到PHP的安装信息。

免责声明:文章转载自《CentOS 7编译安装Tengine+PHP+MariaDB全程笔记》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇SpringCloud 分布式配置中心外键关联的修改 级联 修改表行记录的操作下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

netbeans工具使用xdebug断点调试php源码

对有有经验的程序员,使用echo、print_r()、print_f()、var_dump()等函数足以调试php代码,如果需要在IDE工具中使用断点调试,xdebug就是一个非常好的php调试工具。对于不熟悉的代码,可以用Xdebug一步一步的查看请求过程和代码执行过程。 准备工作本地部署的server环境,推荐用phpStudy(内置xdebug),开...

PHP文本的读写

1 <?php 2 $txtPart="test0.txt"; //export 3 $txtPartContent=fopen($txtPart,"r"); //读文件,返回TRUE,FALSE 4 if($txtPartContent){ //若文件存在继续 5 while(!fe...

PHP与RBAC设计思路讲解与源码

在说权限管理前,应该先知道权限管理要有哪些功能: (1)、用户只能访问,指定的控制器,指定的方法 (2)、用户可以存在于多个用户组里 (3)、用户组可以选择,指定的控制器,指定的方法  (4)、可以添加控制器和方法 RBAC(Role-Based Access Control,基于角色的访问控制),就是用户通过角色与权限进行关联。简单地说,一个用户拥有若...

Nginx核心知识100讲学习笔记(陶辉)Nginx架构基础(四)

一、红黑树 1、红黑树 2、红黑树复杂度 3、使用红黑树的模块 1、本地内存做的红黑树 ngx_conf_module ngx_event_timer_rbtree #管理定时器的红黑树 2、管理定时器的红黑树 Ngx_http_file_cache Ngx_http_geo_module Ngx_http_limit_conn_module Ng...

nginx重定向

原文链接地址:http://seanlook.com/2015/05/17/nginx-location-rewrite/ location正则写法 一个示例: location = / { # 精确匹配 / ,主机名后面不能带任何字符串 [ configuration A ] } location / { # 因为所有的地址都以 /...

Nginx 目录浏览基础与进阶

目录 1、简述 2、配置目录浏览 3、进阶版配置 3.1 添加第三方模块 3.2 修改配置文件 3.3 重启测试 3.4 自定义主题 1、简述 Nginx作为一款优秀的web服务器,其默认不允许列出站点的整个目录,如果需要配置,需要单独打开此功能 此功能一般用于单独开设虚拟主机供内网如下载文件等功能使用,其他情况下为了安全,一般不会开启此...