search
HomeBackend DevelopmentPHP TutorialThe process of LNMP environment construction using source code (details)

The content of this article is about the process of LNMP recording the environment construction in the form of source code (details). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

LNMP refers to the environment for building websites using PHP MYSQL NGIX under Linux.

Nginx is a high-performance HTTP and reverse proxy server, as well as an IMAP/POP3/SMTP proxy server. Nginx can not only be used as a web server, but also as a load balancer.

MySQL is an open source and free data software. MySQL is a small relational database management system. It is small in size, fast in speed and low in total cost of ownership. Especially because of its characteristics of open source, many small and medium-sized websites In order to reduce the total cost of website ownership, MySQL was chosen as the website database.

PHP is the abbreviation of the English hypertext preprocessing language Hypertext Preprocessor. PHP is an HTML embedded language. It is a scripting language that is executed on the server side and embedded in HTML documents. Its source code is written in C language, so the style is similar to C language and is widely used in construction. Small website.

The following is a record of the establishment process of the LNMP environment. The Linux environment of the subject is a CentOs virtual image.

[Nginx Installation]

The latest stable version of Nginx is 1.14.0. The website address is http://nginx.org/en/download.html. You can download it directly on Windows. rz is uploaded to Linux, or it can be downloaded directly using wget. The download method listed below is the latter.

cd /usr/src          #一般将源码放在此目录下
wget http://nginx.org/download/nginx-1.14.0.tar.gz  #安装

Note: The installation of nginx depends on the zlib-devel pcre-devel openssl-devel packages, so we need to install these packages before installing nginx. To avoid errors during the installation process.

yum -y install zlib-devel pcre-devel openssl-devel

...

##General source code installation is divided into 4 steps ,

Unzip(tar command)Precompile(Execute configure under the source package),Compile(make),Compile and install(make install).

1. Unzip

tar -zxvf nginx-1.14.0.tar.gz   #这里解释下加压参数,z代表gzip(也就是后面的.gz文件)x代表加压,v表示显示详细信息,-f使用档案文件或设备(必选参数)


2. Precompile

When we precompile, we usually bring some The parameters have achieved the effect we want to install, such as enabling a certain function or disabling a certain function:

Enter the source package directory for pre-compilation:

cd nginx-1.14.0
 ./configure --prefix=/data/webserver/nginx\   # 指定安装目录为/usr/local/nginx
--with-openssl=/usr/include/openssl\  # 启用ssl
--with-pcre\                          # 启用正规表达式
--with-http_stub_status_module        # 安装可以查看nginx状态的程序

        …. .. 

3. Compile

./configure refers to executing the

configure file in the current directory. After the pre-compilation is completed, we Can be compiled and installed:

make   #编译

....

4. Installation

make install #安装

.....

After the installation is complete, we can go to the corresponding directory to view the installed files:


ls /data/webserver/nginx

Then you can start nginx:

/data/webserver/nginx/sbin/nginx   #启动nginx

/data/webserver/nginx/sbin/nginx -s stop #停止nginx

/data/webserver/nginx/sbin/nginx -s relaod #重启nginx


#As you can see from the picture, nginx has been started


netstat -antlp ¦ grep 80  #nginx占用TCP的80端口由图也可知nginx已启动

[MySQL installation]

At this point, nginx has been installed and started. Then we install MySQL. Similarly, we still need to install MySQL dependency packages first. :

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

..........

Then we download the source code:

wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-boost-8.0.11.tar.gz

.. .....

Create mysql user:

 groupadd mysql
 useradd -r -g mysql -s /bin/false mysql

Create installation directory and data directory:

mkdir -p /usr/local/mysql
mkdir -p /data/mysql

Unzip the source code package:

 tar -zxf mysql-boost-8.0.11.tar.gz -C /usr/local

编译&安装:

cd /usr/local/mysql-8.0.11
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql 
-DMYSQL_DATADIR=/usr/local/mysql/data 
-DSYSCONFDIR=/etc 
-DMYSQL_TCP_PORT=3306 
-DWITH_BOOST=/usr/local/mysql-8.0.11/boost 
make  && make install

安装成功后我们可启动mysql:

cd /usr/local/mysql
bin/mysqld_safe --user=mysql

启动成功,连接mysql

bin/mysql -uroot -p

此时要求输入连接密码,比较旧的版本的mysql安装时默认密码为空,但该5.7之后的版本有默认的密码,由于我们不知道,因此关闭mysql服务后(可直接查询进程根据进程号kill掉或/etc/init.d/mysql stop ),改用跳过密码的方式重新开启mysql服务。

bin/mysqld_safe --user=mysql & skip-grant-tables

重新连接

bin/mysql -uroot

连接成功后修改密码

mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
mysql> FLUSH PRIVILEGES;

此时重启mysql服务,便可以账号密码方式连接mysql。

【PHP安装】

先安装php依赖包,否则在编译安装php7的过程当中会出现各种报错,安装完成后即可进入下一个环节。

安装扩展包并更新系统内核:

yum install epel-release -y
yum update

安装php依赖组件(包含Nginx依赖),前面nginx以及mysql安装过的可以忽略,也可以直接复制运行,会跳过已安装的依赖:

yum -y install wget vim pcre pcre-devel openssl openssl-devel libicu-devel gcc gcc-c++ autoconf libjpeg libjpeg-devel 
libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel 
ncurses ncurses-devel curl curl-devel krb5-devel libidn libidn-devel openldap openldap-devel nss_ldap jemalloc-devel 
cmake boost-devel bison automake libevent libevent-devel gd gd-devel libtool* libmcrypt libmcrypt-devel mcrypt mhash 
libxslt libxslt-devel readline readline-devel gmp gmp-devel libcurl libcurl-devel openjpeg-devel


........

创建用户和组,并下载php安装包解压:

cd /tmp
groupadd www
useradd -g www www
wget http://cn2.php.net/distributions/php-7.2.0.tar.gz
tar xvf php-7.2.1.tar.gz
cd php-7.2.0

设置变量并开始源码编译:

cp -frp /usr/lib64/libldap* /usr/lib/
./configure --prefix=/data/webserver/php \
--with-config-file-path=/data/webserver/php/etc \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--enable-mysqlnd-compression-support \
--with-iconv-dir \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-mbstring \
--enable-intl \
--with-mcrypt \
--with-libmbfl \
--enable-ftp \
--with-gd \
--enable-gd-jis-conv \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--with-gettext \
--disable-fileinfo \
--enable-opcache \
--with-pear \
--enable-maintainer-zts \
--with-ldap=shared \
--without-gdbm \

开始安装

make -j 4 && make install

完成安装后配置php.ini文件:

cp php.ini-development /data/webserver/php/etc/php.ini
cp /data/webserver/php/etc/php-fpm.conf.default /data/webserver/php/etc/php-fpm.conf
cp /data/webserver/php/etc/php-fpm.d/www.conf.default /data/webserver/php/etc/php-fpm.d/www.conf

修改 php.ini 相关参数:

vim /data/webserver/php/etc/php.ini

expose_php = Off
short_open_tag = ON
max_execution_time = 300
max_input_time = 300
memory_limit = 128M
post_max_size = 32M
date.timezone = Asia/Shanghai
mbstring.func_overload=2

重启PHP,至此LNMP环境已搭建完成。

相关文章推荐:

Nginx配置fastcgi cache的方法介绍

docker安装php环境的实际操作步骤

The above is the detailed content of The process of LNMP environment construction using source code (details). For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP's Purpose: Building Dynamic WebsitesPHP's Purpose: Building Dynamic WebsitesApr 15, 2025 am 12:18 AM

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

PHP: Handling Databases and Server-Side LogicPHP: Handling Databases and Server-Side LogicApr 15, 2025 am 12:15 AM

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

How do you prevent SQL Injection in PHP? (Prepared statements, PDO)How do you prevent SQL Injection in PHP? (Prepared statements, PDO)Apr 15, 2025 am 12:15 AM

Using preprocessing statements and PDO in PHP can effectively prevent SQL injection attacks. 1) Use PDO to connect to the database and set the error mode. 2) Create preprocessing statements through the prepare method and pass data using placeholders and execute methods. 3) Process query results and ensure the security and performance of the code.

PHP and Python: Code Examples and ComparisonPHP and Python: Code Examples and ComparisonApr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP in Action: Real-World Examples and ApplicationsPHP in Action: Real-World Examples and ApplicationsApr 14, 2025 am 12:19 AM

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: Creating Interactive Web Content with EasePHP: Creating Interactive Web Content with EaseApr 14, 2025 am 12:15 AM

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: Comparing Two Popular Programming LanguagesPHP and Python: Comparing Two Popular Programming LanguagesApr 14, 2025 am 12:13 AM

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.

The Enduring Relevance of PHP: Is It Still Alive?The Enduring Relevance of PHP: Is It Still Alive?Apr 14, 2025 am 12:12 AM

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.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools