LNMP环境搭建并配置wordpress

LNMP环境搭建并配置wordpress

安装nginx

基础安装

yum install -y gcc gcc-c++ make pcre pcre-devel zlib zlib-devel openssl openssl-devel

cd /usr/local/src/

wget http://nginx.org/download/nginx-1.24.0.tar.gz

tar -xzvf nginx-1.24.0.tar.gz

cd nginx-1.24.0

./configure \

输入:

--prefix=/usr/local/nginx \

--with-http_ssl_module \

--with-http_stub_status_module \

--with-stream \

--with-stream_ssl_module

make -j 4 && make -j 4 install

配置nginx环境变量

vim /etc/profile

尾行添加变量:export PATH=$PATH:/usr/local/nginx/sbin

source /etc/profile

nginx -v

systemctl管理nginx

vim /usr/lib/systemd/system/nginx.service

添加:

[Unit]

Description=nginx

After=network.target remote-fs.target nss-lookup.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 stop

[Install]

WantedBy=multi-user.target

启动nginx

systemctl start nginx

systemctl enable nginx

systemctl status nginx

安装PHP

基础安装

yum install -y libxml2-devel sqlite-devel libcurl-devel libpng-devel freetype-devel openssl-devel curl-devel oniguruma-devel

cd /usr/local/src/

wget https://www.php.net/distributions/php-8.2.14.tar.gz

tar -xzvf php-8.2.14.tar.gz

cd php-8.2.14

./configure \

添加:

--prefix=/usr/local/php \

--with-config-file-path=/usr/local/php/etc \

--with-mysqli=mysqlnd \

--with-pdo-mysql=mysqlnd \

--with-zlib \

--with-curl \

--with-openssl \

--with-mhash \

--with-gettext \

--with-exif \

--with-fileinfo \

--with-gd \

--without-pear \

--enable-xml \

--enable-bcmath \

--enable-shmop \

--enable-sysvsem \

--enable-mbregex \

--enable-mbstring \

--enable-ftp \

--enable-pcntl \

--enable-sockets \

--enable-soap \

--enable-fpm \

--disable-rpath \

--disable-fileinfo

make -j 4 && make -j 4 install

cp php.ini-production /usr/local/php/etc/php.ini

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环境变量

vim /etc/profile

尾行添加变量: export PATH=$PATH:/usr/local/php/bin:/usr/local/php/sbin

source /etc/profile

php-fpm -v

systemctl管理php-fpm

vim /usr/lib/systemd/system/php-fpm.service

添加

[Unit]
Description=php-fpm
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/php/sbin/php-fpm
ExecStop=pkill -9 php-fpm
[Install]
WantedBy=multi-user.target

启动PHP

systemctl start php-fpm

systemctl enable php-fpm

systemctl status php-fpm

测试PHP

vim /usr/local/nginx/html/test.php

编写

<?php

  phpinfo();

?>

配置nginx解析php

vim /usr/local/nginx/conf/nginx.conf

45行,添加配置index index.html index.htm index.php;

65~71行,修改配置

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;
   }

systemctl reload nginx

测试访问http://110.40.131.104/test.php

安装mysql

基础安装

yum install -y gcc gcc-c++ openssl openssl-devel libaio libaio-devel ncurses ncurses-devel

cd /usr/local/src/

wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.34-linux-glibc2.12-x86_64.tar.xz

tar -xJvf mysql-8.0.34-linux-glibc2.12-x86_64.tar.xz

mv mysql-8.0.34-linux-glibc2.12-x86_64 /usr/local/mysql

添加环境变量

vim /etc/profile

尾行添加变量: export PATH=$PATH:/usr/local/mysql/bin

source /etc/profile

mysql -V

更改启动脚本

vim /usr/local/mysql/support-files/mysql.server

# 46~47行,修改配置

basedir=/usr/local/mysql
datadir=/data/mysql

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

修改mysql配置

vim /etc/my.cnf

修改为

[mysqld]
bind-address=127.0.0.1
port=3306
datadir=/data/mysql
user=mysql
skip-name-resolve
slow_query_log=on
long_query_time=1
slow_query_log_file=/data/mysql/mysql-slow.log
innodb-file-per-table=1
innodb_flush_log_at_trx_commit=2
max_allowed_packet=512M
connect_timeout=60
net_read_timeout=120
[mysqld_safe]
log-error=/data/mysql/mysqld.log
pid-file=/data/mysql/mysqld.pid

初始化mysql

useradd mysql -s /sbin/nologin

mkdir -p /data/mysql

chown -R mysql:mysql /data/mysql/ /usr/local/mysql/

mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql &> /usr/local/mysql/passwd

systemctl管理mysql

vim /usr/lib/systemd/system/mysqld.service

添加

[Unit]
Description=mysqld
After=network.target
[Service]
Type=forking
ExecStart=/etc/init.d/mysqld start
[Install]
WantedBy=multi-user.target

启动mysql

systemctl start mysqld

systemctl enable mysqld

systemctl status mysqld

登录mysql并修改密码

grep 'password' /usr/local/mysql/passwd

-- 2024-03-08T03:51:09.327973Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: #fJeV!ltm7xy

mysql -uroot -p'#fJeV!ltm7xy' -A

mysql> alter user 'root'@'localhost' identified by '123456';

Query OK, 0 rows affected (0.01 sec)

mysql> create user 'wordpress'@'127.0.0.1' identified with mysql_native_password by 'wordpress';

Query OK, 0 rows affected (0.00 sec)

mysql> grant all privileges on *.* to 'wordpress'@'127.0.0.1' with grant option;

Query OK, 0 rows affected (0.01 sec)

mysql> quit

编写php连接mysql脚本

vim /usr/local/nginx/html/lnmp.php

<?php
  $link=mysqli_connect("127.0.0.1","wordpress","wordpress");
  if(!$link){
    echo '<h1>MySQL Connect Fail</h1>';
  }else{
    echo '<h1>MySQL Connect Success</h1>';
  }
?>

测试访问:http://110.40.131.104/lnmp.php

安装wordpress

基础安装

cd /usr/local/src/

wget https://cn.wordpress.org/wordpress-6.4.3-zh_CN.tar.gz

tar -xzvf wordpress-6.4.3-zh_CN.tar.gz

mv wordpress /usr/local/nginx/html/

修改配置文件

cd /usr/local/nginx/html/wordpress/

chmod 777 wp-content/

cp wp-config-sample.php wp-config.php

vim wp-config.php

# 23行,修改配置define( 'DB_NAME', 'wordpress' )

# 26行,修改配置define( 'DB_USER', 'wordpress' )

# 29行,修改配置define( 'DB_PASSWORD', 'wordpress' )

# 32行,修改配置 define( 'DB_HOST', '127.0.0.1' )

创建wordpress数据库

mysql -uwordpress -h127.0.0.1 -pwordpress

mysql> create database wordpress;
Query OK, 1 row affected (0.00 sec)
mysql> quit

浏览器访问:http://110.40.131.104/wordpress/

  • 5
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值