前言
前置条件
首先要有一台linux 服务器,阿里云、腾讯云等等都行
由于我之前买的是腾讯云的服务器,本文就以腾讯云服务器为例
操作环境
LNMP(Linux+Nginx+Mysql+PHP)
-
linux 版本
-
nginx 版本
-
Mysql版本
-
Xshell版本
-
php版本
php-7.3.4
安装步骤
Mysql 以及Nginx的安装请参考博主的另一篇文章
https://blog.csdn.net/gao36951/article/details/73321345
PHP 环境准备(php-7.3.4.tar.gz)
下载地址:https://www.php.net/downloads.php
cd /root/php/
tar -zxvf php-7.3.4.tar.gz
cd php-7.3.4
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-png-dir=/usr/local/libpng --with-jpeg-dir=/usr/local/jpeg --with-freetype-dir=/usr/local/freetype --with-zlib-dir=/usr/local/zlib --with-libxml-dir=/usr/local/libxml2/ --with-iconv-dir=/usr/local/libiconv --enable-libxml --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-opcache --enable-mbregex --enable-fpm --enable-mbstring=all --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-curl --enable-ctype --enable-shared --with-gd
- 执行上面的可能报一下错误,解决方案已经附上
执行报错:
configure: error: in `/root/php/php-7.3.4':
configure: error: no acceptable C compiler found in $PATH
解决方案:
yum install gcc
执行报错:
checking whether to use system default cipher list instead of hardcoded value... no
checking for RAND_egd... no
checking for pkg-config... /usr/bin/pkg-config
configure: error: Cannot find OpenSSL's <evp.h>
解决方案:
yum install openssl openssl-devel
ln -s /usr/lib64/libssl.so /usr/lib/
执行报错:
checking pcre install prefix... no
checking libzip... yes
checking for the location of zlib... /usr
checking for pkg-config... (cached) /usr/bin/pkg-config
checking for libzip... configure: error: system libzip must be upgraded to version >= 0.11
解决方案:
yum remove libzip -y
wget https://nih.at/libzip/libzip-1.2.0.tar.gz
tar -zxvf libzip-1.2.0.tar.gz
cd libzip-1.2.0
./configure
make && make install
- 解决完上述问题后继续
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-png-dir=/usr/local/libpng --with-jpeg-dir=/usr/local/jpeg --with-freetype-dir=/usr/local/freetype --with-zlib-dir=/usr/local/zlib --with-libxml-dir=/usr/local/libxml2/ --with-iconv-dir=/usr/local/libiconv --enable-libxml --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-opcache --enable-mbregex --enable-fpm --enable-mbstring=all --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-curl --enable-ctype --enable-shared --with-gd --with-fpm-user=nginx --with-fpm-group=nginx
- 成功如下图所示
- 编译安装
make && make install
执行报错:
In file included from /root/php/php-7.3.4/ext/zip/php_zip.h:31:0,
from /root/php/php-7.3.4/ext/zip/php_zip.c:36:
/usr/local/include/zip.h:59:21: fatal error: zipconf.h: No such file or directory
#include <zipconf.h>
^
compilation terminated.
make: *** [ext/zip/php_zip.lo] Error 1
解决方案:
cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h
- 解决完错误后继续编译安装
make && make install
- 编译安装成功后如下图:
- 配置与启动PHP
cp php.ini-production /usr/local/php/etc/php.ini
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
- 配置php-fpm.conf文件
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
- 在php.sh中添加环境变量
vim /etc/profile.d/php.sh
export PATH=$PATH:/usr/local/php/bin/:/usr/local/php/sbin/
- 使环境变量生效
source /etc/profile.d/php.sh
- 启动PHP服务php-fpm
service php-fpm start
- 检查启动进程与侦听端口号
ps -ef | grep php-fpm
netstat -lntup | grep 9000
LNMP环境测试
- 配置nginx
vim /etc/nginx/nginx.conf
server {
listen 80;
server_name localhost;
include /etc/nginx/default.d/*.conf;
location / {
root /project/php;
}
location /favicon.ico {
root /project/php;
}
location ~ \.php$ {
root /project/php;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
- 重新加载配置文件启动nginx
nginx -s reload
- 测试LNMP环境是否生效
cd /project/php
touch test.php
echo "<?php phpinfo(); ?>" > test.php
- 在浏览器输入地址http://{IP或者域名}/test.php 出现下面的页面说明成功
参考:
https://blog.csdn.net/mangojo/article/details/86475554
http://www.kwx.gd/PHPEnvironment/CetnOS-libzip.html
https://blog.csdn.net/alexdream/article/details/7408561
https://blog.csdn.net/duguduchong/article/details/8699774
https://blog.csdn.net/weixin_42579642/article/details/85290670
http://www.kuitao8.com/20180429/4689.shtml