目录
在/www/env/nginx/html下创建index.php文件:
编译安装 nginx-1.22.1
安装依赖
sudo apt install libgd-dev
解压nginx
tar -zvxf nginx-1.22.1.tar.gz
编译安装
cd nginx-1.22.1
编译并指定安装位置,执行安装之后会创建指定文件夹/www/env/nginx
问题1:
./configure: error: the HTTP rewrite module requires the PCRE library. You can either disable the module by using --without-http_rewrite_module option, or install the PCRE library into the system, or build the PCRE library statically from the source with nginx by using --with-pcre= option. PCRE库
PCRE库支持正则表达式。如果我们在配置文件nginx.conf中使用了正则表达式,那么在编译Nginx时就必须把PCRE库编译进Nginx,因为Nginx的HTTP模块需要靠它来解析正则表达式。另外,pcre-devel是使用PCRE做二次开发时所需要的开发库,包括头文件等,这也是编译Nginx所必须使用的。可以这样安装:
sudo apt update sudo apt install libpcre3 libpcre3-dev 问题2:
./configure: error: SSL modules require the OpenSSL library. You can either do not enable the modules, or install the OpenSSL library into the system, or build the OpenSSL library statically from the source with nginx by using --with-openssl= option OpenSSL库
如果服务器不只是要支持HTTP,还需要在更安全的SSL协议上传输HTTP,那么需要拥有OpenSSL。另外,如果我们想使用MD5、SHA1等散列函数,那么也需要安装它。可以这样安装:
sudo apt-get install openssl libssl-dev 执行编译并安装
make && make install
安装 PHP 7.4,配合 Nginx
安装 PHP 和 PHP FPM 软件包:
apt install php-fpm
检查服务状态,运行:
systemctl status php7.4-fpm
修改权限
chmod 777 /run/php/php7.2-fpm.sock
配置php-fpm
修改配置监听9000端口来处理nginx的请求(这种方法一般在windows上使用),
打开 /etc/php/7.2/fpm/pool.d/www.conf 文件找到如下位置注释第一行添加第二行
;listen = /run/php/php7.2-fpm.sock
listen = 127.0.0.1:9000
修改Nginx配置文件
找到下面这部分代码取消注释,修改配置
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi.conf;
}
测试:
在/www/env/nginx/html下创建index.php文件:
root@ubuntu:/www/env/nginx/html# cat index.php
<?php
phpinfo()
?>
打开浏览器:
MySQL安装
下载一个支持
apt-get install php-mysql
安装
apt-get install mysql-server mysql-client
更改密码
输入mysqladmin -u root -p password
回车,
出现“Enter password:”,直接回车,未设置密码时默认没有密码,
接着出现“New password:”输入新的密码,回车,
接着出现“Confirm new password:”确认密码,回车即可。
重启 MySQL 服务
service mysql restart
创建security数据库
create database security;
在security中执行下列语句
SET NAMES utf8;
SET FOREIGN_KEY_CHECKS = 0;
DROP TABLE IF EXISTS `flags`;
CREATE TABLE `flags` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`flag` varchar(256) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4;
DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`username` varchar(256) NOT NULL,
`password` varchar(32) NOT NULL,
`email` varchar(256) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8mb4;
SET FOREIGN_KEY_CHECKS = 1;