2、linux安装nginx:1.20
(1)、Nginx:1.20下载地址:wget http://nginx.org/download/nginx-1.20.2.tar.gz
(2)、安装nginx
vim /etc/yum.repos.d/local.repo #编写yum仓库
[cdrom]
name=benet
baseurl=file:///media/cdrom
enabled=1
gpgcheck=0
media/cdrom/ #挂载光盘
yum -y install gcc gcc-c++ autoconf automake make pcre pcre-devel zlib zlib-devel pcre pcre-devel zlib zlib-devel openssl openssl-devel #安装nginx相关的环境包
解释:yum -y install gcc gcc-c++ autoconf automake make # c编译器
yum install -y pcre pcre-devel # 解析正则的pcre库
yum install -y zlib zlib-devel # 添加对gzip的支持
yum -y install pcre pcre-devel zlib zlib-devel openssl openssl-devel # SSL
(3)、解压nginx并编译安装
tar xf nginx-1.20.2.tar.gz
cd nginx-1.20.2
./configure –prefix=/usr/local/nginx –with-http_stub_status_module –with-http_ssl_module #编译安装nginx相应的模块功能
make && make install
(4)、给nginx创建软连接并启动nginx
(5)、添加防火墙规则运行80端口
访问:http://172.16.1.105
3、linux安装mysql(数据库)
(1)、下载mysql
rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm #下载mysql5.7的yum源
yum -y install mysql-community-server –nogpgcheck #yum安装mysql服务
(2)、启动mysql,并设置为开机自启
systemctl start mysqld #启动mysqld
systemctl enable mysqld #s设置开启自启
systemctl daemon-reload #重新加载某个服务的配置文件
4、安装PHP7.3.28
(1)、安装支持PHP环境需要的依赖包
yum install -y 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 sqlite-devel oniguruma-devel
(2)、下载PHP7.3.28,并解压编译安装
wget https://www.php.net/distributions/php-7.3.28.tar.gz #下载php源码包
mkdir -p /usr/local/php7.3 #创建目录
tar xf php-7.3.28.tar.gz #解压
cd php-7.3.28/ #切换到php目录
./configure -prefix=/usr/local/php7.3 -with-zlib-dir -enable-mbstring -enable-soap -enable-calendar -with-curl -disable-rpath -enable-inline-optimization -with-bz2 -with-zlib -enable-sockets -enable-sysvsem -enable-sysvshm -enable-pcntl -enable-mbregex -enable-exif -enable-bcmath -with-mhash -with-pdo-mysql -with-mysqli -with-openssl -with-fpm-user=nobody -with-fpm-group=nobody -enable-ftp -with-gettext -with-xmlrpc -with-xsl -enable-opcache -enable-fpm -with-iconv
#配置变量
make all install #编译安装(时间很长耐心等待)
make test #检查编译结果(时间很长耐心等待)
cp /usr/local/php7.3/etc/php-fpm.conf.default /usr/local/php7.3/etc/php-fpm.conf
cp /usr/local/php7.3/etc/php-fpm.d/www.conf.default /usr/local/php7.3/etc/php-fpm.d/www.conf
#拷贝配置文件
#创建用户 nginx
useradd nginx -s /usr/sbin/nologin
#启动php-fpm
/usr/local/php7.3/sbin/php-fpm
查看服务php-fpm
5、配置nginx
第35行至77行配置
server {listen 80;server_namelocalhost;#access_log /usr/local/nginx/logs/wordpress/access2.log main;#error_log /usr/local/nginx/logs/wordpress/error2.log;root /wordpress/wordpress/blog/;error_page 500 502 503 504 /50x.html;location test/ {rewrite ^test(.*)$ wp-admin$1 last;}#access_loglogs/host.access.logmain;location / {root /wordpress/wordpress/blog/;indexindex.php index.htm index.html;}#error_page404/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;}rewrite /wp-admin$ $scheme://$host$uri/ permanent;# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000#location ~ \.php$ {root /wordpress/wordpress/blog/;fastcgi_pass 127.0.0.1:9000;#fastcgi_pass 127.0.0.1:9001; # 配置一个php不需要这一行fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}
检查配置文件有无错误nginx -t
Nginx -t
重新加载nginx配置
nginx -s reload
6、配置mysql(数据库)
(1)、获取root的初始密码
grep ‘temporary password’ /var/log/mysqld.log
(2)、初始化数据库
mysql_secure_installation
(3)、登录mysql并创建数据库和账户并赋予权限 (我的密码是Abc!123,)
mysql -uroot -p #登录数据库
create database wordpress; #创建数据库wordpress
create user admin@“%” identified by “Abc!123,”; #创建用户admin,密码:Abc!123,
grant all privileges on wordpress.* to admin@“%” identified by “Abc!123,”; #给admin授权
flush privileges; #刷新权限
quit #退出
7、下载wordpress并解压
(1)、下载wordpress 到/ wordpress/
wget -P /wordpress https://cn.wordpress.org/wordpress-6.0-zh_CN.zip
(2)、解压并将内容移动到wordpress/blog/
cd /wordpress
unzip wordpress-6.0-zh_CN.zip
mkdir -p ./wordpress/blog
mv ./wordpress/* ./wordpress/blog/
(3)、访问页面http://172.16.1.105/wordpress