centos7.5 安装LNMP
安装PHP
下载nginx
下载官网:https://www.php.net/downloads.php
直接下载(注意版本,可先访问官网查看,复制下载地址连接进行下载)
直接下载已中断,推荐浏览器下载上传。
wget wget https://www.php.net/distributions/php-7.4.8.tar.gz
解压
tar -zxvf php-7.4.8.tar.gz
移动文件到/use/local/下
mv php-7.4.8 /usr/local/
安装依赖包
yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel curl curl-devel openssl openssl-devel
yum -y install gcc
yum -y install gcc-c++
yum -y install libxslt-devel*
yum -y install mod_ssl
yum -y install libtool-ltdl*
yum -y install perl*
yum -y install autoconf
# 解决报错configure: error: Package requirements (sqlite3 」 3.7.4) were not met:
yum -y install sqlite-devel
切换目录
cd /usr/local/php-7.4.8/
配置
./configure --prefix=/usr/local/php7 --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-jpeg-dir --with-freetype-dir --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-xmlrpc --with-xsl --with-zlib --enable-fpm --enable-bcmath -enable-inline-optimization --disable-mbregex --enable-mbstring --disable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-zip --enable-pcntl --with-curl --with-fpm-user=nginx --enable-ftp --enable-session --enable-xml --without-pear --disable-phar
常见安装报错解决办法
https://df-l.com/230.html
解决configure: error: Package requirements (oniguruma) were not met: No package ‘oniguruma’ found
https://www.cnblogs.com/cndavidwang/p/12343847.html
编译安装
安装过程中遇mbregex与opcache 报错,未编译,不知道后续是否有问题
make && make install
报错“ext/date/php_date.lo is not a valid libtool object。”
解决办法:
make clean
make && make install
添加环境变量
#打开环境变量配置文件
vim /etc/profile
#最后添加
PATH=$PATH:/usr/local/php7/bin
export PATH
#生效配置
source /etc/profile
查看PHP版本
php -v
生成必要配置文件
cp php.ini-production /usr/local/php7/etc/php.ini
cp sapi/fpm/php-fpm /etc/init.d/php-fpm
cp sapi/fpm/php-fpm /usr/local/php7/etc/php-fpm
cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
编辑配置文件
vim /usr/local/php7/etc/php.ini
date.timezone = PRC //设置时区
file_uploads = On //是否允许上传
upload_tmp_dir = /tmp //上传临时目录
max_file_uploads = 20 //单个请求最多上传数量
upload_max_filesize = 10M //允许上传文件大小
post_max_size = 20M //允许post传输最大值(这个必须比upload_max_filezise大)
memory_limit = 128M //设置脚本最大使用内存
error_reporting=E_ALL //输出错误信息
error_log = /var/log/php.log //错误日志路径
创建日志文件
touch /var/log/php.log
chmod 755 /var/log/php.log
利用源码自带启动脚本设置开机自启
进入到你到php源码包
cp /usr/src/php-*/sapi/fpm/init.d.php-fpm /ect/init.d/php-fpm
chmod 755 /etc/init.d/php-fpm #分配权限
service php-fpm start #启动
chkconfig php-fpm on #开机启动
chkconfig --list | grep php-fpm #查看自启开启情况
安装nginx
下载地址
http://nginx.org/en/download.html
Mainline version 开发版
Stable version 稳定版
Legacy versions 历史版
鼠标移动到你要选择的版本超链接上点右键 复制链接地址
wget http://nginx.org/download/nginx-1.18.0.tar.gz
解压到/usr/local/
tar -xf nginx-1.18.0.tar.gz -C /usr/local/
安装pcre库,不安装会造成nginx配置文件重新报错
yum -y install pcre-devel
切换目录
cd /usr/local/nginx-1.18.0/
配置
./configure --with-http_stub_status_module --with-http_ssl_module
安装
make && make install
修改配置文件
以下配置文件可直接复制替换
(除解除注释外,还需将其中的/scripts 修改为 $document_root)
[root@miwifi-r3l-srv nginx-1.18.0]# cat /usr/local/nginx/conf/nginx.conf
user nobody;
worker_processes 1;
error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
if (!-e $request_filename) {
rewrite ^/index.php(.*)$ /index.php?s=$1 last;
rewrite ^(.*)$ /index.php?s=$1 last;
}
index index.html index.htm index.php;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
修改php-fpm配置文件
#改为nobody 或者是系统中存在的用户
vim /usr/local/php7/etc/php-fpm.d/www.conf
23 user = nobody
24 group = nobody
启动php-fpm,载入php.ini
/usr/local/php7/sbin/php-fpm -c /usr/local/php7/etc/php.ini
注意 如果修改了php.ini则每次需要杀掉php-fpm进程再重新启动php-fpm,PHP的解析执行靠的是这家伙,不靠nginx。
ps -ef | grep php-fpm
kill -9 上一条命令查到的PID
nginx服务脚本
vim /etc/init.d/nginx
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
# It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /usr/local/nginx/logs/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/usr/local/nginx/logs/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "${NETWORKING}" = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo "nginx already running...."
exit 1
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /usr/local/nginx/logs/nginx.pid
}
# reload nginx service functions.
reload() {
echo -n $"Reloading $prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"
exit 1
esac
exit $RETVAL
修改启动脚本权限
chmod 755 /etc/init.d/nginx
vim /etc/rc.local
/usr/local/nginx/sbin/nginx
启动服务,加入开机自启
#启动nginx服务
/etc/init.d/nginx start
#添加开机自启
chkconfig nginx on
centos 7.x 可使用以下命令进行管理nginx
#查看状态
systemctl status nginx
#启动服务
systemctl start nginx
#停止服务
systemctl stop nginx
#平滑重启服务
systemctl reload nginx
#重启服务
systemctl restart nginx
nginx启动异常
vim /lib/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
#添加开机自启
systemctl enable nginx
#启动nginx服务
systemctl start nginx
#查看nginx服务状态
systemctl status nginx
安装MySQL
安装mysql源
yum localinstall -y https://repo.mysql.com//mysql80-community-release-el8-3.noarch.rpm
安装MySQL
yum install mysql-server
启动mysql,添加开机自启
systemctl start mysqld
systemctl enable mysqld
获取初始密码
grep 'temporary password' /var/log/mysqld.log
安装完成设置新密码
https://blog.csdn.net/weixin_33766805/article/details/89627939
mysql_secure_installation
修改无密码登录
https://blog.csdn.net/generalfyx/article/details/96321601?utm_term=mysql8%E6%97%A0%E9%9C%80%E5%AF%86%E7%A0%81%E7%99%BB%E5%BD%95&utm_medium=distribute.pc_aggpage_search_result.none-task-blog-2allsobaiduweb~default-1-96321601&spm=3001.4430
SET PASSWORD = 'Pwd@123456789';
密码必须复杂 需包含大小写特殊符号,否则无法修改成功
开放远程连接
use mysql;
update user set host = '%' where user = 'root';
安装私有云盘
进入网页目录
#进入网页目录
cd /usr/local/nginx/html/
#创建网盘文件夹
mkdir yunpan
#安装可道云
wget http://static.kodcloud.com/update/download/kodbox.1.1.zip
unzip kodbox.1.1.zip && chmod -Rf 777 ./*
#访问:IP/网盘目录/
#配置即可
PHP5与PHP7连接MySQL数据库区别
php5连接数据库使用mysql,php7使用mysqli;两者的参数位置对换。
示例如下:
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>语文</title>
<link rel="stylesheet" type="text/css" href="semantic.css">
</head>
<body>
<table class="ui celled table">
<thead>
<tr>
<th>id</th>
<th>字</th>
<th>拼音</th>
<th>组词</th>
</tr>
<?php
require "dbconfig.php";
$link = @mysql_connect(HOST,USER,PASS) or die("提示:数据库连接失败!");
mysql_select_db(DBNAME,$link);
mysql_set_charset('utf8',$link);
$sql ="select id,zhi from zhis ORDER BY id DESC";
$result = mysql_query($sql,$link);
$newsNum=mysql_num_rows($result);
for($i=0; $i<$newsNum; $i++){
$row = mysql_fetch_assoc($result);
echo "<tr>";
echo "<td>{$row['id']}</td>";
echo "<td>{$row['zhi']}</td>";
echo "<td><a href='https://hanyu.baidu.com/s?wd={$row['zhi']}&ptype=zici'>拼音</a></td>";
echo "<td><a href='https://hanyu.baidu.com/s?wd={$row['zhi']}&cf=zuci&ptype=term'>组词</a></td>";
echo "</tr>";
}
mysql_free_result($result);
mysql_close($link);
?>
</table>
</body>
</html>
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>语文</title>
<link rel="stylesheet" type="text/css" href="semantic.css">
</head>
<body>
<table class="ui celled table">
<thead>
<tr>
<th>id</th>
<th>字</th>
<th>拼音</th>
<th>组词</th>
</tr>
<?php
require "dbconfig.php";
$link = @mysqli_connect(HOST,USER,PASS) or die("提示:数据库连接失败!");
mysqli_select_db($link,DBNAME);
mysqli_set_charset($link,'utf8');
$sql ="select id,zhi from zhis ORDER BY id DESC";
$result = mysqli_query($link,$sql);
$newsNum=mysqli_num_rows($result);
for($i=0; $i<$newsNum; $i++){
$row = mysqli_fetch_assoc($result);
echo "<tr>";
echo "<td>{$row['id']}</td>";
echo "<td>{$row['zhi']}</td>";
echo "<td><a href='https://hanyu.baidu.com/s?wd={$row['zhi']}&ptype=zici'>拼音</a></td>";
echo "<td><a href='https://hanyu.baidu.com/s?wd={$row['zhi']}组词&cf=zuci&ptype=term'>组词</a></td>";
echo "</tr>";
}
mysqli_free_result($result);
mysqli_close($link);
?>
</table>
</body>
</html>
PHP上传文件大小限制解除
上传文件报500,检查php是否开启文件上传功能
1
在网页目录下编写php文件
<?php
phpinfo();
?>
2
通过浏览器访问此页面
查看Configuration File (php.ini) Path参数
3
进入此目录,修改php.ini文件如无此文件,将php.ini文件复制到此目录进行修改
4
修改php.ini内容
file_uploads = on ;是否允许通过HTTP上传文件的开关。默认为ON即是开
upload_tmp_dir ;文件上传至服务器上存储临时文件的地方
upload_max_filesize = 8m ;允许上传文件大小的最大值。默认为2M
post_max_size = 8m ;表单POST给PHP的所能接收的最大值,包括表单里的所有值 默认为8M
根据网上的资料,如果上传大于8M的文件,还要改一下时间的设置:
max_execution_time = 600 ;每个PHP页面运行的最大时间值(秒),默认30秒
max_input_time = 600 ;每个PHP页面接收数据所需的最大时间,默认60秒
memory_limit = 8m ;每个PHP页面所吃掉的最大内存,默认8M
5
在nginx配置文件http下添加最大上传文件参数,默认1M
client_max_body_size 512M;
6
在上传文件HTML页面要使用POST,enctype="multipart/form-data是必备的,可以解除页面限制
<form action="upload2.php" method="POST" enctype="multipart/form-data">
<input type='hidden' name='MAX_FILE_SIZE' value='2048000000' />
<input type="file" name="file" id="file" placeholder="请选择确认书图片"></div>