The construction of LNMP on redhat
1. Configure the software source warehouse
1. Select the ISO image for redhat and connect it
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
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.
4. Switch to the repos.d directory and edit redhat.repo inside it using (vim)
cd /etc/yum.repos.d/
vim rh8.repo
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
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.
6. Copy the tools we prepared in advance to the /home directory of Redhat
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
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
(2). After decompression is completed, enter the rpcsvc directory to compile.
./configure
(3). Continue to use make to compile and install
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
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
5. After the download is completed, edit the configuration file.
vim /usr/local/nginx/conf/nginx.nginx.conf
6. Change user to nginx user nginx group and remove the previous pound comment.
7. In order to be used in conjunction with the subsequent PHP, delete the comments and make the following modifications
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;
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
9. Through filtering, check whether port 80 is occupied by nginx. Here we can see that it is monitored.
netatat -ano|grep 80
10. Set up a firewall
firewall-cmd --permanent --zone=public --add-port=80/tcp
防火墙设置允许80端口被访问
firewall-cmd --reload
重启防火墙服务
firewall-cmd --zone=public --list-ports
查询端口状态
11. Open our browser and visit 192.168.231.147. You can see Welcome to nginx!
Prove that nginx has been successfully built
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*
2. Delete all directories of the source database
rm -rf /sur/local/mysql
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
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
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
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
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
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
11. Copy and save the password
12. Edit the environment variables and add mysql to the environment variables. After editing, enter: wq to save and exit.
vim ~/.bash_profile
环境变量
PATH=$PATH:$HOME/bin:/usr/local/nginx/sbin:/usr/local/mysql/bin
13. Update environment variables
source ~/.bash profile
14. Check the status of port 3306
netstat -ano|grep 3306
15. Log in to the MySQL database and change the password and operations according to the prompts.
mysql -uroot -p
4. Configure php
1. cd /home Switch to the home directory and decompress the php compressed package
tar -zxvf php-7.3.5tar.gz
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
3. Use make to continue compiling
4. Compile and download with make
make install
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
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
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
:wq save and exit
8. Start the php service
/etc/init.d/php-fpm start
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
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
4. Restart nginx service
nginx -s reload
5. Re-enter the MySQL database
mysql -uroot -p
Password: ZcZCYYdsZcZCYYdsZcZCYYds
Create a new database named wordpress
create database wordpress character set utf8
6. Enter the information on the web page and submit it
7. Click "Install Now"
cd /usr/local/nginx/html
8. You can see that a new wp-config.php was automatically created for us.
9. Return to the previous page to edit information.