LNMP
Nginx 安装
一、安装编译工具及库文件
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel pcre*
二、首先要安装 PCRE
PCRE 作用是让 Nginx 支持 Rewrite 功能。
1、下载 PCRE 安装包,下载地址: http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
###解压此安装包即可,不需要安装,Nginx需要指定pcre的源码不是安装后的路径,此包的功能是支持地址重写rewrite功能 pcre的依赖可以yum安装pcre和pcre-devel解决!
2、下载 Nginx,下载地址:http://nginx.org/download/nginx-1.8.0.tar.gz
wget http://nginx.org/download/nginx-1.8.0.tar.gz
3、解压软件并编译安装
tar zxvf nginx-1.6.2.tar.gz
cd nginx-1.6.2
./configure --prefix=/app/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.35
4、查看nginx版本
/app/nginx/sbin/nginx -v
5、添加ninx 运行帐号www
useradd -M -g www -s /sbin/nologin
6、配置nginx.conf
user www www; worker_processes 2; #设置值和CPU核心数一致 #日志位置和日志级别 error_log /var/logs/nginx/error.log; pid /var/run/nginx.pid;
7、添加多域名虚拟主机(可以添加多个主机,需要修改ROOT目录) ### 注意结尾 ; 分号
[root@test nginx]# vim conf.d/blog.conf
server {
listen 80;
server_name blog.test.com;
location / {
root /app/nginx/html/blog;
index index.php index.html;
}
location ~.*\.php$ {
root /app/nginx/html/blog;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
8、将虚拟目录的配置文件加入到主配置文件nginx.conf 中”http {}”部分的末尾(最好写绝对路径,相对路径有时候不识别)
http {
...
include /app/nginx/conf.d/*.conf;
}
9、启动
/app/nginx/sbin/nginx -t #检查语法错误 /app/nginx/sbin/nginx
以下包含了 Nginx 常用的几个命令:
/app/nginx/sbin/nginx -s reload # 重新载入配置文件 /app/nginx/sbin/nginx -s reopen # 重启 /app/nginx/sbin/nginx -s stop # 停止 Nginx
PHP 安装
1、安装依赖库文件
yum install -y libxml2-devel libcurl-devel libjpeg-devel libpng-devel freetype freetype-devel libmcrypt libmcrypt-devel readline readline-devel libxslt-devel perl perl-devel recode recode-devel libtidy libtidy-devel
如果失败可以下载安装libmcrypt
tar xf libmcrypt-2.5.8.tar.gz -C /usr/local/src/ cd /usr/local/src/libmcrypt-2.5.8/ ./configure --prefix=/usr/local/src/libmcrypt;make && make install
3、下载PHP程序并编译./configure --prefix=/app/php --with-config-file-path=/app/php --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --enable-xml --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --with-zlib --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap
--with-mcrypt=/usr/local/src/libmcrypt
make -j 2 && make install
php编译与配置:
2.1: httpd 模块
备注:需要事先存在httpd ,编译指定 apxs 文件位置。此处以--with-apxs2=/usr/local/httpd/bin/apxs 作为演示。
php7:
~]# ./configure --prefix=/usr/local/php7 --sysconfdir=/etc/php7 --with-config-file-path=/etc/php7 --with-apxs2=/usr/local/httpd/bin/apxs --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-mhash --with-openssl --with-zlib --with-bz2 --with-curl --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-zlib --enable-mbstring --with-mcrypt --enable-sockets --with-iconv-dir --with-xsl --enable-zip --with-pcre-dir --with-pear --enable-session --enable-gd-native-ttf --enable-xml --with-freetype-dir --enable-gd-jis-conv --enable-inline-optimization --enable-shared --enable-bcmath --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-mbregex --enable-pcntl --with-xmlrpc --with-gettext --enable-exif --with-readline --with-recode --with-tidy
php5.6:(仅增加了选项 --with-mysql=mysqlnd)
~]# ./configure --prefix=/usr/local/php5 --sysconfdir=/etc/php5 --with-config-file-path=/etc/php5 --with-apxs2=/usr/local/httpd/bin/apxs --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-mhash --with-openssl --with-zlib --with-bz2 --with-curl --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-zlib --enable-mbstring --with-mcrypt --enable-sockets --with-iconv-dir --with-xsl --enable-zip --with-pcre-dir --with-pear --enable-session --enable-gd-native-ttf --enable-xml --with-freetype-dir --enable-gd-jis-conv --enable-inline-optimization --enable-shared --enable-bcmath --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-mbregex --enable-pcntl --with-xmlrpc --with-gettext --enable-exif --with-readline --with-recode --with-tidy
2.2:fastcgi php-fpm 模式
php7:
~]# ./configure --prefix=/usr/local/php7 --sysconfdir=/etc/php7 --with-config-file-path=/etc/php7 --enable-fpm --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-mhash --with-openssl --with-zlib --with-bz2 --with-curl --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-zlib --enable-mbstring --with-mcrypt --enable-sockets --with-iconv-dir --with-xsl --enable-zip --with-pcre-dir --with-pear --enable-session --enable-gd-native-ttf --enable-xml --with-freetype-dir --enable-gd-jis-conv --enable-inline-optimization --enable-shared --enable-bcmath --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-mbregex --enable-pcntl --with-xmlrpc --with-gettext --enable-exif --with-readline --with-recode --with-tidy
php5.6:(仅增加了选项 --with-mysql=mysqlnd)
~]# ./configure --prefix=/usr/local/php5 --sysconfdir=/etc/php5 --with-config-file-path=/etc/php5 --enable-fpm --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-mhash --with-openssl --with-zlib --with-bz2 --with-curl --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-zlib --enable-mbstring --with-mcrypt --enable-sockets --with-iconv-dir --with-xsl --enable-zip --with-pcre-dir --with-pear --enable-session --enable-gd-native-ttf --enable-xml --with-freetype-dir --enable-gd-jis-conv --enable-inline-optimization --enable-shared --enable-bcmath --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-mbregex --enable-pcntl --with-xmlrpc --with-gettext --enable-exif --with-readline --with-recode --with-tidy
4、安装成功后拷贝源码包中的 php.ini-development 和 php-fpm.conf 文件到 PHP 配置文件目录
cp php.ini-production /app/php/php.ini cp etc/php-fpm.conf.default etc/php-fpm.conf
5、启动php-fpm
/app/php/sbin/php-fpm
参考网址:
http://blog.csdn.net/u010861514/article/details/51926575
https://www.cnblogs.com/Miss-mickey/p/6734831.html

浙公网安备 33010602011771号