This article brings you relevant knowledge about PHP. It mainly introduces how to use source code to build an LNMP environment. It is very detailed. Friends who are interested can take a look below. I hope it will be helpful to everyone.
Build LNMP environment using source code
1. Install RedHat8
Centos8, Or anything else. The virtual machine is VMware. There are installation tutorials online, so I won’t go into details here.
2. Configure the local software warehouse
// 把系统镜像挂载到/media/cdrom目录。 mkdir -p /media/cdrom mount /dev/cdrom /media/cdrom // mount: /media/cdrom: WARNING: device write-protected, mounted read-only. // 创建软件仓库的配置文件 ~]# vi /etc/yum.repos.d/rhel8.repo [BaseOS] name=BaseOS baseurl=file:///media/cdrom/BaseOS enabled=1 gpgcheck=0 [AppStream] name=AppStream baseurl=file:///media/cdrom/AppStream enabled=1 gpgcheck=0
Test and install vim, wget
dnf install vim wget -y
3. Install the tools required for compilation
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* ntpstat na* bison* lrzsz cmake ncurses-devel libzip-devel libxslt-devel gdbm-devel readline-devel gmp-devel
4. Download the required software source code package
and save it in the /lnmp directory.
mkdir /lnmp cd /lnmp wget https://www.linuxprobe.com/Software/rpcsvc-proto-1.4.tar.gz wget https://www.linuxprobe.com/Software/nginx-1.16.0.tar.gz wget https://www.linuxprobe.com/Software/mysql-8.0.18.tar.xz wget https://www.linuxprobe.com/Software/php-7.3.5.tar.gz wget https://www.linuxprobe.com/Software/wordpress.tar.gz
5. Install rpcsvc-proto
rpcsvc-proto is the name of a software package that contains rcpsvc protocol file support. The rcpsvc protocol will be used in subsequent Nginx and MySQL service programs. needs to be called during the deployment process.
tar xzvf rpcsvc-proto-1.4.tar.gz cd rpcsvc-proto-1.4/ ./configure make make install cd ..
6. Install Nginx
Create an account for the operation of Nginx
The program is run by one user. For security reasons, of course it cannot It's root.
And it does not require a home directory or login, it is just used to run Nginx.
useradd nginx -M -s /sbin/nologin // -M 不创建家目录,-s 指定 shell id nginx // 查询是否创建成功了 uid=1000(nginx) gid=1000(nginx) 组=1000(nginx)
Install Nginx
lnmp]# tar zxvf nginx-1.16.0.tar.gz lnmp]# cd nginx-1.16.0/ nginx-1.16.0]# ./configure --prefix=/usr/local/nginx --with-http_ssl_module // --prefix指定安装目录, --with-开启http_ssl_module模块 nginx-1.16.0]# make nginx-1.16.0]# make install nginx-1.16.0]# cd ..
Configure Nginx
Use the prefix parameter to specify the installation path, then the Nginx configuration file is under /usr/local/nginx.
Provide the owner of the user who runs the program, and the owner of the group.
vim /usr/local/nginx/conf/nginx.conf // 打开文件后,我们在英文模式下,按下 shift + 冒号,输入2,回车,定位到第2行。 // 连按两次 ESC,取消当前使用模式 // 再次 shift + 冒号,输入 set nu,回车,我们可以显示行号 1 2 user nginx nginx; // 第二行,修改为这样
In line 45, add index.php to the index configuration (the file that can be used as the default home page).
43 location / { 44 root html; 45 index index.php index.html index.htm; 46 }
Delete the comment character # in front of lines 65 to 71 to enable the virtual host function, and then change the corresponding website root directory after line 69 to /usr/local/nginx/html, where fastcgi_script_name The parameter is used to refer to the script name, which is the URL requested by the user. Only when the information is filled in correctly can Nginx correctly parse the user request. Otherwise, the page visited will prompt a "404 Not Found" error.
63 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 64 # 65 location ~ \.php$ { 66 root html; 67 fastcgi_pass 127.0.0.1:9000; 68 fastcgi_index index.php; 69 fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name; 70 include fastcgi_params; 71 }
The software compiled and installed from the source code cannot be managed by systemctl by default. We can directly use its own /usr/local/nginx/sbin/nginx to manage it. It is recommended to add the /usr/local/nginx/sbin path to the PATH environment variable, so that we can directly enter nginx without adding a path.
Then use the source command to make this modification take effect immediately.
lnmp]# vim ~/.bash_profile # .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/bin:/usr/local/nginx/sbin // 这里加上 Nginx 的 sbin 路径 export PATH lnmp]# source ~/.bash_profile // 让修改立即生效 lnmp]# nginx // 启动 nginx 服务
Open the browser to access 192.168.89.128 (my virtual machine address), the access failed
Close the firewall
systemctl status firewalld.service // 查看是否在运行 systemctl stop firewalld.service // 临时停止 systemctl disable firewalld.service // 永久关闭
Visit again and find that it works.
7. Install MySQL
Create a mysql user responsible for running the MySQL database. This user also does not need to log in.
lnmp]# useradd mysql -M -s /sbin/nologin
Installation
// 解压MySQL安装软件包 lnmp]# tar xvf mysql-8.0.18.tar.xz // 将解压出的程序目录改名并移动到/usr/local目录下 lnmp]# mv mysql-8.0.18-linux-glibc2.12-x86_64 mysql lnmp]# mv mysql /usr/local
/usr/local/mysql is the path to save the MySQL program file, /usr/local/mysql/data is the place where the data is stored, and each database is under it a directory. We also need to create it manually.
lnmp]# cd /usr/local/mysql mysql]# mkdir data
Initialize MySQL, authorize the directory, and ensure that the data can be accessed by the mysql user. Before initialization, use the mysqld command to confirm the user name for managing the MySQL service, the data storage directory, and the encoding information. After the information is correct, start initialization. After initialization, the system will assign an initial temporary password to the user. Remember to save it.
The password assigned in the example below is qfroRs,Ei4Ls.
[root@linuxprobe mysql]# chown -R mysql:mysql /usr/local/mysql [root@linuxprobe mysql]# cd bin [root@linuxprobe bin]# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data 2021-05-06T07:07:06.243270Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.18) initializing of server in progress as process 7606 2021-05-06T07:07:08.116268Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: qfroRs,Ei4Ls
Similar to nginx, some binary executable commands of MySQL are stored in /usr/local/mysql/bin in its own program directory. We can also add them to the PATH environment variable for easy access.
[root@linuxprobe bin]# vim ~/.bash_profile # .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/bin:/usr/local/nginx/sbin:/usr/local/mysql/bin export PATH [root@linuxprobe bin]# source ~/.bash_profile
Put the startup script mysql.server into /etc/init.d so that the database can be automatically started every time the server is restarted. and grant executable permissions.
The libtinfo.so.5 file is an important function library file newly added after MySQL 8.0, but it does not exist by default. You need to copy the libtinfo.so.6.1 file or use it as a link file to start normally:
[root@linuxprobe bin]# cd /usr/local/mysql [root@linuxprobe mysql]# cp -a support-files/mysql.server /etc/init.d/ [root@linuxprobe mysql]# chmod a+x /etc/init.d/mysql.server [root@linuxprobe mysql]# ln -s /usr/lib64/libtinfo.so.6.1 /usr/lib64/libtinfo.so.5
Execute the MySQL database service startup file and perform initialization work. For security reasons, MySQL no longer allows users to use temporary passwords to manage database content since version 8.0, nor can it be remotely controlled. Users must change the initialization password before they can use the MySQL database. As the database is an important component service of the system, it is recommended that the number of passwords be no less than 20 characters. For example, the following changes the password to "PObejCBeDzTRCncXwgBy".
[root@linuxprobe mysql]# /etc/init.d/mysql.server start Starting MySQL.Logging to '/usr/local/mysql/data/linuxprobe.com.err'. . SUCCESS! [root@linuxprobe mysql]# mysql -u root -p Enter password: 输入初始化时给的原始密码 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.18 Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> alter user 'root'@'localhost' identified by 'PObejCBeDzTRCncXwgBy'; Query OK, 0 rows affected (0.01 sec) mysql>
But this still doesn’t work. You still need to switch to the mysql database and modify the password value of the user form. This is also a new security requirement since MySQL database version 8.0.
mysql> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> show tables; +---------------------------+ | Tables_in_mysql | +---------------------------+ | columns_priv | | tables_priv | | time_zone | | time_zone_leap_second | | time_zone_name | | time_zone_transition | | time_zone_transition_type | | user | | …………省略部分输出信息………… | +---------------------------+ 33 rows in set (0.00 sec) mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'PObejCBeDzTRCncXwgBy'; Query OK, 0 rows affected (0.01 sec) // 创建一个数据库 create database linuxcool;
8. Install PHP
Unzip the php source code package, compile and install
[root@linuxprobe mysql]# cd /lnmp [root@linuxprobe lnmp]# tar xvf php-7.3.5.tar.gz [root@linuxprobe lnmp]# cd php-7.3.5/ [root@linuxprobe php-7.3.5]# ./configure --prefix=/usr/local/php --enable-fpm --with-mysqli --with-curl --with-pdo_mysql --with-pdo_sqlite --enable-mysqlnd --enable-mbstring --with-gd [root@linuxprobe php-7.3.5]# make [root@linuxprobe php-7.3.5]# make install
Copy the generated php.ini configuration file to the installation directory (/usr/local/php/) to make it take effect. Now that the main configuration file is available, the php-fpm configuration file is also needed. Fortunately, it is also provided in the /usr/local/php/etc/ directory. You only need to copy the template:
[root@linuxprobe php-7.3.5]# cp php.ini-development /usr/local/php/lib/php.ini [root@linuxprobe php-7.3.5]# cd /usr/local/php/etc/ [root@linuxprobe etc]# mv php-fpm.conf.default php-fpm.conf // 复制一个模板文件到php-fpm.d的目录中,用于后续控制网站的连接性能: [root@linuxprobe etc]# mv php-fpm.d/www.conf.default php-fpm.d/www.conf
The php service is added to the startup item so that it will still take effect after restarting
[root@linuxprobe etc]# cd /lnmp/php-7.3.5 [root@linuxprobe php-7.3.5]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm [root@linuxprobe php-7.3.5]# chmod 755 /etc/init.d/php-fpm
Disable some functions
[root@linuxprobe php-7.3.5]# vim /usr/local/php/lib/php.ini 307 ; This directive allows you to disable certain functions for security reasons. 308 ; It receives a comma-delimited list of function names. 309 ; http://php.net/disable-functions 310 disable_functions = 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
Start the php-fpm process
[root@linuxprobe php-7.3.5]# /etc/init.d/php-fpm start Starting php-fpm done
We are in /usr/local/ Create an index.php file under nginx/html and test it
<?php phpinfo();
浏览器访问地址即可。
9、搭建一个 WordPress
把 Nginx 服务程序根目录的内容清空后,将 WordPress 解压后的网站文件复制进去:
[root@linuxprobe php-7.3.5]# cd .. [root@linuxprobe lnmp]# rm -f /usr/local/nginx/html/* [root@linuxprobe lnmp]# tar xzvf wordpress.tar.gz [root@linuxprobe lnmp]# mv wordpress/* /usr/local/nginx/html/
为了能够让网站文件被 Nginx 服务程序顺利读取,应设置目录所有权的身份及可读写的权限:
[root@linuxprobe lnmp]# chown -Rf nginx:nginx /usr/local/nginx/html [root@linuxprobe lnmp]# chmod -Rf 777 /usr/local/nginx/html
输入虚拟机 IP 地址访问 WordPress 网站的首页面。
后面按说明一步步操作下去即可。
The above is the detailed content of Super detailed! Build LNMP environment using source code. For more information, please follow other related articles on the PHP Chinese website!

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP makes it easy to create interactive web content. 1) Dynamically generate content by embedding HTML and display it in real time based on user input or database data. 2) Process form submission and generate dynamic output to ensure that htmlspecialchars is used to prevent XSS. 3) Use MySQL to create a user registration system, and use password_hash and preprocessing statements to enhance security. Mastering these techniques will improve the efficiency of web development.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP remains important in modern web development, especially in content management and e-commerce platforms. 1) PHP has a rich ecosystem and strong framework support, such as Laravel and Symfony. 2) Performance optimization can be achieved through OPcache and Nginx. 3) PHP8.0 introduces JIT compiler to improve performance. 4) Cloud-native applications are deployed through Docker and Kubernetes to improve flexibility and scalability.

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP and Python each have their own advantages and are suitable for different scenarios. 1.PHP is suitable for web development and provides built-in web servers and rich function libraries. 2. Python is suitable for data science and machine learning, with concise syntax and a powerful standard library. When choosing, it should be decided based on project requirements.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Chinese version
Chinese version, very easy to use

Dreamweaver Mac version
Visual web development tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software