环境是CentOS 7 64bit,Updated 9 July 2014。512M内存虚拟机。
先更新下系统:
-
[root@linuxidc ~]# yum update -y
安装必要软件:
-
[root@linuxidc ~]# yum install gcc automake autoconf libtool make gcc-c++ zlib-devel openssl-devel vim which bzip2 -y
编译安装pcre:
-
[root@linuxidc ~]# cd /usr/local/src/
-
[root@linuxidc src]# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.35.tar.gz
-
[root@linuxidc src]# tar zvxf pcre-8.35.tar.gz
-
[root@linuxidc src]# cd pcre-8.35
-
[root@linuxidc pcre-8.35]#./configure
-
[root@linuxidc pcre-8.35]# make && make install
编译安装openssl:
-
[root@linuxidc pcre-8.35]# cd /usr/local/src/
-
[root@linuxidc src]# wget http://
-
[root@linuxidc src]# tar zvxf openssl-1.0.1h.tar.gz
-
[root@linuxidc src]# cd openssl-1.0.1h
-
[root@linuxidc openssl-1.0.1h]#./config
-
[root@linuxidc openssl-1.0.1h]# make && make install
编译安装zlib
-
[root@linuxidc openssl-1.0.1h]# cd /usr/local/src/
-
[root@linuxidc src]# wget http://zlib.net/zlib-1.2.8.tar.gz
-
[root@linuxidc src]# tar zvxf zlib-1.2.8.tar.gz
-
[root@linuxidc src]# cd zlib-1.2.8
-
[root@linuxidc zlib-1.2.8]#./configure
-
[root@linuxidc zlib-1.2.8]# make && make install
编译安装jemalloc:
-
[root@linuxidc zlib-1.2.8]# cd /usr/local/src/
-
[root@linuxidc src]# wget http://
-
[root@linuxidc src]# tar jxvf jemalloc-3.6.0.tar.bz2
-
[root@linuxidc src]# cd jemalloc-3.6.0
-
[root@linuxidc jemalloc-3.6.0]#./configure
-
[root@linuxidc jemalloc-3.6.0]# make && make install
-
[root@linuxidc jemalloc-3.6.0]# echo '/usr/local/lib'>/etc/ld.so.conf.d/local.conf
-
[root@linuxidc jemalloc-3.6.0]# ldconfig
-
建立www用户组和用户,禁止www登陆shell:
-
[root@linuxidc jemalloc-3.6.0]# groupadd www
-
[root@linuxidc jemalloc-3.6.0]# useradd -g www www
-
[root@linuxidc jemalloc-3.6.0]# usermod -s /sbin/nologin www
创建虚拟主机使用目录,并赋予相应权限:
-
[root@linuxidc jemalloc-3.6.0]# mkdir -p /usr/www/example.com/{public_html,logs}
-
[root@linuxidc jemalloc-3.6.0]# chmod -R +w /usr/www/
-
[root@linuxidc jemalloc-3.6.0]# chown -R www:www /usr/www/
编译安装Tengine:
-
[root@linuxidc jemalloc-3.6.0]# cd /usr/local/src/
-
[root@linuxidc src]# wget http://tengine.taobao.org/download/tengine-2.0.3.tar.gz
-
[root@linuxidc src]# tar zvxf tengine-2.0.3.tar.gz
-
[root@linuxidc src]# cd tengine-2.0.3
-
[root@linuxidc tengine-2.0.3]#./configure --prefix=/usr/local/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.8
-
--with-pcre=/usr/local/src/pcre-8.35
-
--with-jemalloc
-
[root@linuxidc tengine-2.0.3]# make && make install
修改nginx.conf文件:
-
[root@linuxidc tengine-2.0.3]# mkdir /usr/local/nginx/conf/domains
-
[root@linuxidc tengine-2.0.3]# vim /usr/local/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;
:wq保存
测试Nginx:
-
[root@linuxidc tengine-2.0.3]# cd /usr/local/nginx
-
[root@linuxidc nginx]# ldconfig
-
[root@linuxidc nginx]#./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到开机自动启动:
-
[root@linuxidc 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
:wq保存
-
[root@linuxidc nginx]# systemctl enable nginx
关闭默认防火墙:
-
[root@linuxidc nginx]# systemctl stop firewalld.service
-
[root@linuxidc nginx]# systemctl disable firewalld.service
安装iptables并开启80端口
-
[root@linuxidc nginx]# yum install iptables-services -y
-
[root@linuxidc nginx]# vim /etc/sysconfig/iptables
增加
-
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80-j ACCEPT
因为这台VPS的SSH端口为60000,修改
-
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22-j ACCEPT
为
-
-A INPUT -p tcp -m state --state NEW -m tcp --dport 60000-j ACCEPT
:wq保存
重启iptables并设定开机自动启动:
-
[root@linuxidc nginx]# systemctl restart iptables.service
-
[root@linuxidc nginx]# systemctl enable iptables.service
安装MariaDB:
-
[root@linuxidc nginx]# cd /etc/yum.repos.d/
-
[root@linuxidc yum.repos.d]# vim MariaDB.repo
输入
-
# MariaDB 10.0 CentOS repository list - created 2014-09-30 09:33 UTC
-
#
-
[mariadb]
-
name =MariaDB
-
baseurl = http://yum.mariadb.org/10.0/centos7-amd64
-
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
-
gpgcheck=1
:wq保存
-
[root@linuxidc yum.repos.d]# yum install MariaDB-server MariaDB-client -y
报错,存在冲突包,删除之
-
[root@linuxidc yum.repos.d]# rpm -ev net-snmp-1:5.7.2-18.el7.x86_64
-
[root@linuxidc yum.repos.d]# rpm -ev mariadb-libs-1:5.5.37-1.el7_0.x86_64
再安装
-
[root@linuxidc yum.repos.d]# yum install MariaDB-server MariaDB-client -y
成功
启动MariaDB服务并添加开机自动启动:
-
[root@linuxidc yum.repos.d]# service start mysql
-
[root@linuxidc yum.repos.d]# chkconfig mysql on
安装编译PHP的必要应用:
-
[root@linuxidc yum.repos.d]# 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:
-
[root@linuxidc yum.repos.d]# cd /usr/local/src/
-
[root@linuxidc src]# wget https://vps.googlecode.com/files/libmcrypt-2.5.8.tar.gz
-
[root@linuxidc src]# tar zxvf libmcrypt-2.5.8.tar.gz
-
[root@linuxidc src]# cd libmcrypt-2.5.8
-
[root@linuxidc libmcrypt-2.5.8]#./configure
-
[root@linuxidc libmcrypt-2.5.8]# make && make install
编译安装PHP:
-
[root@linuxidc libmcrypt-2.5.8]# cd /usr/local/src/
-
[root@linuxidc src]# wget http://cn2.php.net/distributions/php-5.6.0.tar.gz
-
[root@linuxidc src]# tar zxvf php-5.6.0.tar.gz
-
[root@linuxidc src]# cd php-5.6.0
-
[root@linuxidc php-5.6.0]#./configure --prefix=/usr/local/php-5.6.0
-
--with-mysql --with-mysql-sock
-
--with-mysqli --enable-fpm --enable-soap
-
--with-libxml-dir --with-openssl --with-mcrypt
-
--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 --with-pear --disable-fileinfo
因为只有512M内存所以加了--disable-fileinfo,不然编译会报错
-
[root@linuxidc php-5.6.0]# make && make install
复制配置文件:
-
[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
-
[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
-
[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
修改配置文件:
-
[root@linuxidc php-5.6.0]# vim /usr/local/php-5.6.0/etc/php-fpm.conf
找到这些值修改
-
pm.max_children =50
-
pm.start_servers =20
-
pm.min_spare_servers =5
-
pm.max_spare_servers =35
去掉
-
;pm.max_requests =500
的注释,然后
:wq保存
设置php-fpm开机自动启动
-
[root@linuxidc php-5.6.0]# chmod a+x /etc/init.d/php-fpm
-
[root@linuxidc php-5.6.0]# chkconfig php-fpm on
将PHP的bin目录加入环境变量:
-
[root@linuxidc php-5.6.0]# chmod +x /etc/profile
-
[root@linuxidc php-5.6.0]# vim /etc/profile.d/php.sh
加入
-
PATH=$PATH:/usr/local/php5.6.0/bin
-
export PATH
:wq保存
-
[root@linuxidc php-5.6.0]# chmod +x /etc/profile.d/php.sh
-
[root@linuxidc php-5.6.0]# source /etc/profile
-
[root@linuxidc php-5.6.0]# ln -s /usr/local/php-5.6.0/sbin/php-fpm /bin/php-fpm
创建网站配置文件:
-
[root@linuxidc php-5.6.0]# vim /usr/local/nginx/conf/domains/example.com.conf
输入
-
server {
-
server_name example.com;
-
listen 80;
-
root /usr/www/example.com/public_html;
-
access_log /usr/www/example.com/logs/access.log;
-
error_log /usr/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;
-
}
-
}
:wq保存
重启VPS:
-
[root@linuxidc php-5.6.0]# reboot
相关阅读:
CentOS 6.3用ICC编译PHP5.4.8+Percona5.5.27+Tengine1.4.1
Tengine 的详细介绍:请点这里
Tengine 的下载地址:请点这里