搭建LNMP
2017-06-07 本文已影响20人
eima
安装PHP
在官网下载PHP源文件并解压。
tar zxf php-7.1.5.tar.gz
cd php-7.1.5
编译安装
./configure --prefix=/usr/local/php71u --enable-fpm ## 指定安装目录并且安装fpm
配置过程中可能会因为依赖问题而出错:
sudo apt-get install libxml2 libxml2-dev
继续编译
make ##时间较长
编译最后一步——安装
sudo make install
使用
sudo /usr/local/php71u/sbin/php-fpm
安装MySQL
sudo apt-get install mysql-server mysql-client libmysqlclient-dev
安装NGINX
- 先安装pcre
$ wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz
$ tar -zxvf pcre-8.39.tar.gz
$ cd pcre-8.39
$ ./configure --prefix=/usr/local/pcre-8.39
$ make
$ sudo make install
- 安装NGINX
下载安装包
wget http://nginx.org/download/nginx-1.12.0.tar.gz
解压缩
tar -zxvf nginx-1.12.0.tar.gz
编译安装
cd nginx-1.12.0
./configure --prefix=/usr/local/nginx --with-pcre=../pcre-8.39
#该路径为未安装的代码包路径
make
sudo make install
- 使用
sudo /usr/local/sbin/nginx (启动)
/usr/local/sbin/nginx -s stop (停止)
/usr/local/sbin/nginx -s reload (重启)
- 检查
ps aux | grep nginx
或
直接访问 127.0.0.1
协调php和nginx
- 修改nginx.conf
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index /index.php;
include /usr/local/nginx/conf/fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
- 重启nginx
- 在/usr/local/nginx/html下新建test.php,并访问127.0.0.1/test.php