Construction of LNMP environment

The construction of LNMP on redhat

1. Configure the software source warehouse

1. Select the ISO image for redhat and connect it

image-20230518172727925

2. (1) Open the FinalShell we use, connect our redhat via ssh, and create a cdrom directory in the root directory

mkdir -p /media/cdrom

(2) Go to the directory we just created and mount it

mount /dev/cdrom /media/cdrom

image-20230518172949395

3. After the mounting is completed, exit cdrom and re-enter the directory. Once you see that there are files in the directory, it is successful.

image-20230518173047481

4. Switch to the repos.d directory and edit redhat.repo inside it using (vim)

cd /etc/yum.repos.d/
vim rh8.repo

image-20230518173331106

After entering the following code: wq save and exit

[BaseOS]
name=BaseOS
baseurl=file:///media/cdrom/BaseOS
enabled=1
gpgcheck=0
[AppStream]
name=AppStream
baseurl=file:///media/cdrom/AppStream
enabled=1
gpgcheck=0 

image-20230518173836004

5. Download http

yum install httpd -y

When yum installs a package, -y is an option parameter, which means to ignore the confirmation prompt when installing the package, that is, automatically answer "yes" (yes) to confirm the installation without interrupting the installation process. This speeds up the process of installing packages, especially when a large number of packages need to be installed.
If the -y option is not added, the yum command will prompt the user to confirm whether to install the software package when installing the software package, and you need to manually enter "yes" to continue the installation. Adding the -y option can avoid manual confirmation, automate the installation and improve efficiency. However, you also need to use this option with caution to avoid unrecoverable problems caused by misoperation.

image-20230518174026113

6. Copy the tools we prepared in advance to the /home directory of Redhat

image-20230518175754042

7. Install dependent environment

Use "dnf" to install dependent environments

The installation tool in Linux will have multiple dependent packages, such as installing MySQL-----If you install manually, you need to install multiple dependent packages first, and finally you can successfully install MySQL. However, using "yum" and "dnf" will automatically install these required dependent packages. Go to the resource library to find and install them automatically.

dnf  -y install apr* autoconf automake numactl bison bzip2-devel cpp curl-devel fontconfig-devel freetype-devel gcc gcc-c++ gd-devel gettext-devel kernel-headers keyutils-libs-devel krb5-devel libcom_err-devel libpng-devel libjpeg* libsepol-devel libselinux-devel libstdc++-devel libtool* libxml2-devel libXpm* libxml* libXaw-devel libXmu-devel libtiff* make openssl-devel patch pcre-devel perl php-common php-gd telnet zlib-devel libtirpc-devel gtk*  bison* lrzsz cmake ncurses-devel libzip-devel libxslt-devel gdbm-devel readline-devel gmp-devel

image-20230518191007762

image-20230518191500962

8. Install rpcsvc

The file support package for the rcpsvc protocol can be called during subsequent mysql and nginx service deployment processes

(1). Unzip the rpcsvc compressed package

tar -xvf rpcsvc-proto-1.4.tar.gz

-x: Unzip the compressed file
-v: Display the process
-f: Specify the file

image-20230518192126574

(2). After decompression is completed, enter the rpcsvc directory to compile.

./configure 

image-20230518192725833

(3). Continue to use make to compile and install

image-20230518193013242

image-20230518193216808

image-20230518193331056

2. Configure nginx

1. Add nginx user, set nologin, and do not create a home directory.

nginx only needs to manage the nginx service, no login or home directory is required.

useradd nginx -s /sbin/nologin -M

2. We see the nginx compressed package in the home directory and decompress the compressed package.

tar -xvf nginx-1.16.0.tar.gz

image-20230518193753107

3. After decompression is completed, add parameters to facilitate subsequent management.

4. Enter the nginx directory and use the encryption module for https encryption.

./config --prefix-/usr/nginx --with-http_ssl_module

image-20230518194146437

image-20230518194837680

image-20230518194953566

5. After the download is completed, edit the configuration file.

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

image-20230518195128039

6. Change user to nginx user nginx group and remove the previous pound comment.

image-20230518195419948

image-20230518195720107

7. In order to be used in conjunction with the subsequent PHP, delete the comments and make the following modifications

image-20230518195837415

Modify the path so that you can parse PHP files when docking with PHP later. After editing is completed: wq save and exit.

fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;

image-20230518200021574

8. Call nginx to take a look. It shows that the command is not found, so we need to edit the environment variable file.

vim ~/ .bash_profile

image-20230518200343468

image-20230518234309726

image-20230518200546761

image-20230518200706967

9. Through filtering, check whether port 80 is occupied by nginx. Here we can see that it is monitored.

netatat -ano|grep 80

image-20230518200853626

10. Set up a firewall

firewall-cmd --permanent --zone=public --add-port=80/tcp
防火墙设置允许80端口被访问
firewall-cmd --reload
重启防火墙服务
firewall-cmd --zone=public --list-ports
查询端口状态

image-20230518235302231

11. Open our browser and visit 192.168.231.147. You can see Welcome to nginx!

Prove that nginx has been successfully built

image-20230518235530210

3. Configure Mysql

1. To prevent conflicts between two databases, you need to uninstall the original database that comes with the system first.

dnf remove mariadb*

image-20230518202057826

2. Delete all directories of the source database

rm -rf /sur/local/mysql

image-20230518202220352

3. Add a MySQL user. It is impossible to log in and the home directory is not created.

useradd mysql -M -s /sbin/nologin

4. We saw the mysql compressed package in the home directory and decompressed it.

tar -xvf mysql-8.0.18.tar.xz

image-20230518202416120

5. The decompression is completed. Because the original name of MySQL is too long and difficult to operate, change its name to mysql.

mv mysql-8.0.18-linux.glbc2.12-x86_64/ mysql

image-20230518202631164

6. Move the MySQL directory to /usr/local, enter this path, and create a new data directory in it to store the specific content of the database.

mv mysql /usr/local
mkdir data

image-20230518203121907

7. We return to the previous level and view the permissions of the MySQL database

ls -l

8. Set the MySQL subdirectory to inherit its properties

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

image-20230518203803709

9. Add a soft link and point libtinfo.so.5 to libtinfo.6.1

ln -s /usr/lib64/libtinfo.so.6.1 /usr/lib64/libtinfo.so.5

image-20230518204610245

10. Enter the /usr/local/mysql/bin directory, use the mysql user, and place the data files in the /usr/local/.ysql/data directory based on the /usr/local/mysql folder

./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

image-20230518204958912

11. Copy and save the password

image-20230518211112372

image-20230518212720699

12. Edit the environment variables and add mysql to the environment variables. After editing, enter: wq to save and exit.

vim ~/.bash_profile

image-20230518211940234

环境变量
PATH=$PATH:$HOME/bin:/usr/local/nginx/sbin:/usr/local/mysql/bin

image-20230518212120281

13. Update environment variables

source ~/.bash profile

image-20230518212244812

image-20230518212558038

14. Check the status of port 3306

netstat -ano|grep 3306

image-20230518213525864

15. Log in to the MySQL database and change the password and operations according to the prompts.

mysql -uroot -p

image-20230518213725431

image-20230518214047066

image-20230518214340922

image-20230518214614461

image-20230518214714270

4. Configure php

1. cd /home Switch to the home directory and decompress the php compressed package

tar -zxvf php-7.3.5tar.gz

image-20230518214811718

2. Go to the php directory

cd php-7.3.5/

Compile php

./configure --prefix=/usr/local/php --enable-fpm --with-mysqli --with-curl --with-pdo_mysql --with-pdo_sqlite --enable-mysqlnd --enable-mbstring --with-gd

image-20230518215005103

3. Use make to continue compiling

image-20230518215203360

4. Compile and download with make

make install

image-20230518215259916

5. Copy the file to the /usr/local/php/lib/php.ini path, and enter the etc directory, change the name of php-fpm.conf.default in the directory to php-fpm/conf, and change the php -The file www.conf.default under -fpm.d is moved to php-fpm.d and renamed to www.conf. Enter the home directory and then enter the php-7.3.5 file and copy the file

cp php.ini-development /usr/local/php/lib/php.ini

cd /usr/local/php/etc/

mv php-fpm.conf.default php-fpm.conf

mv php- fpm.d/www.conf,default php- fpm.d/www.conf

cd /home
ls
cd php-7.3.5

cp sapi/fpm/initd.php-fpm /etc/init.d/php-fpm

image-20230518220356355

6. Give the file we copied permission 755 and edit the php configuration file

chmod 755 /etc/init.d/php-fpm

vim /usr/local/php/lib/php.ini

image-20230518220453425

7. Disable unnecessary dangerous PHP functions after disable_functions for reinforcement.

passthru,exec,system,chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,popen,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server

image-20230518220547486

:wq save and exit

image-20230518220655441

8. Start the php service

/etc/init.d/php-fpm start

image-20230518220750084

The above are all the processes completed in setting up the LNMP environment.

Five, build a blog (wordpress)

1. Enter home to record

cd /home
ls   查看

2. Decompress wordpress.tar.gz

tar -zxvf wordpress.tar.gz

-z: Use GZIP to compress or decompress
-v: Display the process
-f: Specify the file

image-20230518221014040

3. Move all files in the wordpress directory to the web root directory /usr/local/nginx/html

mv wordpress/* /usr/local/nginx/htmi/

Set the user and user group of the web page root directory

chown -Rf nginx:nginx /usr/local/nginx/html

Give the root directory of the web page the highest permissions

chmod -Rf 777 /usr/local/nginx/html

image-20230518221626253

4. Restart nginx service

nginx -s reload

image-20230518221724895

5. Re-enter the MySQL database

mysql -uroot -p

Password: ZcZCYYdsZcZCYYdsZcZCYYds

Create a new database named wordpress

create database wordpress character set utf8

image-20230518222128357

6. Enter the information on the web page and submit it

image-20230518222214901

7. Click "Install Now"

image-20230518222313508

cd /usr/local/nginx/html

8. You can see that a new wp-config.php was automatically created for us.

image-20230519095309683

9. Return to the previous page to edit information.

image-20230518222405094

image-20230518222413953

image-20230518222422861

image-20230518222441745

Guess you like

Origin blog.csdn.net/X2965901955/article/details/131145717