CentOS 7編譯安裝Tengine+PHP+MariaDB全程筆記

  安裝環境:CentOS7 3.10.0-693.5.2.el7.x86_64php

  準備源碼包:css

    pcre-8.41.tar.gzhtml

    openssl-1.0.1h.tar.gzmysql

    zlib-1.2.11.tar.gznginx

    jemalloc-4.5.0.tar.bz2c++

    tengine-2.1.0.tar.gzsql

    libmcrypt-2.5.8.tar.gzshell

    php-7.1.11.tar.gzjson

  首先安裝nginx

  安裝基礎依賴:vim

#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的安裝信息。

相關文章
相關標籤/搜索