云服务器环境:
CentOS release 6.5 (Final)
Linux #servername# 2.6.32-431.23.3.el6.x86_64 x86_64 x86_64 x86_64 GNU/Linux
在以下地址新建文件:/etc/yum.repos.d/nginx.repo
保存以下内容
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
其中$releasever的值表示当前系统的发行版本,可以通过rpm -qi centos-release命令查看
$basearch是我们的系统硬件架构(CPU指令集),使用命令arch得到
保存文件后接着执行如下指令即可自动安装好Nginx:
yum install nginx -y (-y, --assumeyes answer yes for all questions, 自动选择y,全自动)
下面直接就可以启动Nginx了:/etc/init.d/nginx start
Nginx的命令以及配置文件位置:
/etc/init.d/nginx start # 启动Nginx服务
/etc/init.d/nginx stop # 停止Nginx服务
/etc/nginx/nginx.conf # Nginx配置文件位置
chkconfig nginx on #设为开机启动
安装PHP:
从PHP官网下载最新版本的php,此处为7.2.3,下载完成后解压,cd进入解压后的目录,
先使用以下命令安装或升级以下库:
yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel
然后使用以下命令配置php编译参数
./configure --prefix=/usr/local/php --with-config-file-path=/etc --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-soap --with-libxml-dir --with-xmlrpc --with-openssl --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-jis-conv --with-gettext --with-gmp --with-mhash --enable-json --enable-mbstring --enable-mbregex --enable-mbregex-backtrack --with-libmbfl --with-onig --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --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 --enable-opcache
提示以下错误,此时把这两个编译项从配置中删除即可(上述命令中已删除)
configure: WARNING: unrecognized options: --with-mcrypt, --enable-gd-native-ttf
安装完成后
You may want to add: /usr/local/php/lib/php to your php.ini include_path
将php添加到环境变量中,编辑/etc/profile文件,添加如下内容到文件最后,保存后执行source /etc/profile 使设置即时生效
PATH=$PATH:/usr/local/php/bin
export PATH
nginx设置可以参考 Nginx官网设置全解析
接下来要启动php-fpm(FastCGI Process Manager), 用于将nginx转发的web请求转发到php语言处理
/etc/init.d/php-fpm start
启动时的配置基于php-fpm.conf文件
在nginx中配置转发规则
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
php-fpm重启命令:/etc/init.d/php-fpm restart
参考资料:
linux下Yum的$releasever和$basearch的取值
linux环境php7.2编译安装时,提示unrecognized options: –with-mcrypt, –enable-gd-native-ttf