nginx+php+gitblog

来源:互联网 发布:java短链接 编辑:程序博客网 时间:2024/06/05 00:17

Markdown 博客搭建

nginx+php环境安装

php 安装

wget http://cn2.php.net/distributions/php-5.6.2.tar.gztar -zxvf php-5.6.2.tar.gzcd php-5.6.2./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=mysqlnd --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --disable-ipv6 --with-pear --with-curl --with-openssl

如果报错缺少包,则apt-get install 对应的包,已经发现需要安装的有:

tar zxvf libxml2-2.6.20.tar.gzcd libxml2-2.6.20./configuremakemake installtar zxvf freetype-2.4.0.tar.bz2cd freetype-2.4.0./configuremakemake installapt-get install apt-get install libjpeg-devapt-get install libpng-devapt-get install libmcrypt-dev

安装好这些依赖包之后,到php目录下

makemake install

注意:编译php的时候make不要多线程,不然可能内存不够用,如果机器内存小的话。

安装好之后就可以调用php了,如果在直接php不行,建立一个软连接

ln -s /usr/local/bin/php /usr/local/php/bin/php

nginx安装

wget http://nginx.org/download/nginx-1.6.2.tar.gztar -xvf nginx-1.6.2.tar.gzcd nginx-1.6.2cd nginx-1.6.2./configure \--prefix=/usr/local/nginx \--with-http_realip_module \--with-http_sub_module \--with-http_gzip_static_module \--with-http_stub_status_module  \--with-pcre

这一步可能会报错,报缺少pcre,安装:

 wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.gz tar -xvf pcre-8.38.tar.gz cd pcre-8.38 ./configure make make install

建立软连接:

ln -sf /usr/local/nginx/sbin/nginx  /usr/sbin/nginx

启动nginx

nginx -t

如果报错:nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory

root@instance-8alx1qc6-1:~/soft/lnmp/nginx-1.6.2# ldd $(which /usr/local/nginx/sbin/nginx)        linux-vdso.so.1 =>  (0x00007fff965fe000)        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007feb440e4000)        libcrypt.so.1 => /lib/x86_64-linux-gnu/libcrypt.so.1 (0x00007feb43eab000)        libpcre.so.1 => not found        libcrypto.so.1.0.0 => /lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007feb43ace000)        libz.so.1 => /usr/local/lib/libz.so.1 (0x00007feb438b4000)        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007feb434ee000)        /lib64/ld-linux-x86-64.so.2 (0x00007feb4430d000)        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007feb432ea000)

找到libpcre.so.1所在目录为/usr/local/lib64/
建立软连接:

ln -s /usr/local/lib/libpcre.so.1 /lib/libpcre.so.1 

测试成功输出:

root@instance-8alx1qc6-1:~/soft/lnmp/nginx-1.6.2# nginx -tnginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

启动php-fpm

cd /usr/local/php/etccp php-fpm.conf.default php-fpm.conf修改php-fpm.conf 将user和group改成root(我是用root)/usr/local/php/sbin/php-fpm -Rroot用户启动必须加-R

配置防火墙

配置防火墙开启80端口,不开启的话,有时防火墙会不让外网访问80端口我们就无法访问nginx配置的网站了。
修改防火墙配置:
输入以下命令:

vi /etc/sysconfig/iptables, 添加:iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

重启防火墙:

systemctl restart iptables

启动nginx,从浏览器访问验证。

安装gitblog

wget https://github.com/jockchou/gitblog/archive/v2.2.1.tar.gztar -xvf v2.2.1.tar.gz将目录下的内容复制到网站目录下

安装mbstring扩展,php.ini中加入:

extension=mbstring.soshort_open_tag=On

修改nginx配置

user  root; // 不然会出现js/css文件forbiden的问题server {        listen       80;        server_name  localhost;        **root /root/github/blog.checkking.com;        index index.html index.htm index.php;        location ~ \.(jpg|png|gif|js|css|swf|flv|ico)$ {            expires 12h;        }**        #charset koi8-r;        access_log  logs/host.access.log;        **location / {            if (!-e $request_filename) {                rewrite ^(.*)$ /index.php?$1 last ;                break;            }        }        location ~* ^/(doc|logs|app|sys)/ {            return 403;        }**        #error_page  404              /404.html;        # redirect server error pages to the static page /50x.html        #        error_page   500 502 503 504  /50x.html;        **location ~ .*\.(php|php5)?$ {            fastcgi_connect_timeout 300;            fastcgi_send_timeout 300;            fastcgi_read_timeout 300;            fastcgi_pass   127.0.0.1:9000;            fastcgi_index  index.php;            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;            include        fastcgi_params;        }**    }

然后reload nginx,即可访问。


[1] http://gitblogdoc.gitblog.cn/

0 0
原创粉丝点击