環(huán)境是CentOS 7 64bit
成都創(chuàng)新互聯(lián)長(zhǎng)期為上千多家客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對(duì)不同對(duì)象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺(tái),與合作伙伴共同營(yíng)造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為尼勒克企業(yè)提供專業(yè)的成都網(wǎng)站制作、網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè),尼勒克網(wǎng)站改版等技術(shù)服務(wù)。擁有十多年豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開發(fā)。先更新下系統(tǒng):
yum update -y
安裝必要軟件:
yum install gcc automake autoconf libtool make gcc-c++ zlib-devel openssl-devel vim which bzip2 -y
編譯安裝pcre:
cd /usr/local/src/
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.37.tar.gz
tar zvxf pcre-8.37.tar.gz
cd pcre-8.37
./configure
make && make install
編譯安裝openssl:
cd /usr/local/src/
wget http://www.openssl.org/source/openssl-1.0.1h.tar.gz
tar zvxf openssl-1.0.1h.tar.gz
cd openssl-1.0.1h
./config
make && make install
編譯安裝zlib:
cd /usr/local/src/
wget http://zlib.net/zlib-1.2.8.tar.gz
tar zvxf zlib-1.2.8.tar.gz
cd zlib-1.2.8
./configure
make && make install
建立www用戶組和用戶,禁止www登錄shell:
groupadd www
useradd -g www www
usermod -s /sbin/nologin www
創(chuàng)建虛擬主機(jī)使用目錄,并賦予相應(yīng)權(quán)限:
mkdir -p /usr/www/example.com/{public_html,logs}
chmod -R +w /usr/www/
chown -R www:www /usr/www/
編譯安裝Tengine:
cd /usr/local/src/
wget http://tengine.taobao.org/download/tengine-2.1.2.tar.gz
tar zvxf tengine-2.1.2.tar.gz
cd tengine-2.1.2
./configure –prefix=/usr/local/nginx –user=www –group=www–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.37
在這一步,如果發(fā)生錯(cuò)誤,請(qǐng) ./configure –help 查看一下哪些模塊已經(jīng)默認(rèn)是支持的
make && make install
修改nginx.conf文件:
mkdir /usr/local/nginx/conf/domains
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保存
測(cè)試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
測(cè)試成功
添加Nginx到開機(jī)自動(dòng)啟動(dòng):
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保存
systemctl enable nginx
關(guān)閉默認(rèn)防火墻:
systemctl stop firewalld.service
systemctl disable firewalld.service
安裝iptables并開啟80端口
yum install iptables-services -y
vim /etc/sysconfig/iptables
增加一行:
-A INPUT -p tcp -m state –state NEW -m tcp –dport 80 -j ACCEPT
:wq保存
重啟iptables并設(shè)定開機(jī)自動(dòng)啟動(dòng):
systemctl restart iptables.service
systemctl enable iptables.service
安裝安裝MariaDB(MySQL的替代),請(qǐng)參考http://www.fuwu360.com/technology/linux/centos7-mariadb.html
安裝編譯PHP的必要應(yīng)用:
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:
cd /usr/local/src/
wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
tar zxvf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
./configure
make && make install
編譯安裝PHP:
我安裝的是PHP5.6.0版本,如果你要安裝低版本,下載其它版本即可
cd /usr/local/src/
wget http://cn2.php.net/distributions/php-5.6.0.tar.gz
tar zxvf php-5.6.0.tar.gz
cd 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
內(nèi)存較低,所以加了–disable-fileinfo,不然編譯會(huì)報(bào)錯(cuò)
make && make install
復(fù)制配置文件:
cp /usr/local/php-5.6.0/etc/php-fpm.conf.default /usr/local/php-5.6.0/etc/php-fpm.conf
cp /usr/local/src/php-5.6.0/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
cp /usr/local/src/php-5.6.0/php.ini-production /usr/local/php-5.6.0/lib/php.ini
修改配置文件:
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保存
設(shè)置php-fpm開機(jī)自動(dòng)啟動(dòng)
chmod a+x /etc/init.d/php-fpm
chkconfig php-fpm on
將PHP的bin目錄加入環(huán)境變量:
chmod +x /etc/profile
vim /etc/profile.d/php.sh
加入
PATH=$PATH:/usr/local/php5.6.0/bin
export PATH
:wq保存
chmod +x /etc/profile.d/php.sh
source /etc/profile
ln -s /usr/local/php-5.6.0/sbin/php-fpm /bin/php-fpm
創(chuàng)建網(wǎng)站配置文件:
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保存
重啟系統(tǒng) :
reboot