Table of contents
3. Compile and install Nginx source package
4. Optimize the path for easy use
1. Install the Mysql environment dependency package
4. Modify the mysql configuration file
5. Change the owner and group of the mysql installation directory and configuration files
6. Set the path environment variable for easy use
9. Modify the login password of mysql
10. Authorize the root user to log in remotely
1. Install environment dependent packages
3. Optimize the path for easy use
4. Adjust the php configuration file
6. Configure Nginx to support PHP parsing
7. Add the inex.php file to test whether the php service is effective
8. Verify that the database is working properly
4. Use the LNMP architecture to build a bbs forum
LNMP architecture refers to Linux+Nginx+Mysql+PHP (Perl, Python)
First prepare the Linux host, turn off the firewall and selinux
Relevant source code packages need to be obtained
For the meaning of the configuration fields, please refer to the actual operation of the LAMP architecture_Evens7xxX Blog-CSDN Blog
architecture diagram
edit
Differences from LAMP
In the LNMP architecture, nginx handles static page requests, and fastCGI forwards dynamic page requests to the php-fpm module, and then passes through wrapper screening, and finally parses them for php. Data related to the database will open the database connection interface to obtain the data.
1. Install Nginx service
1. Install dependent packages
yum -y install pcre-devel zlib-devel gcc gcc-c++ make
2. Create Nginx running user
useradd -M -s /sbin/nologin nginx
3. Compile and install Nginx source package
#解压源码包
cd /opt
tar zxvf nginx-1.12.0.tar.gz -C /opt/
#自定义安装
cd nginx-1.12.0/
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module
#编译安装
make && make install
4. Optimize the path for easy use
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
5. Add Nginx system service
#自定义service文件
vim /lib/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
#设置权限,使文件生效
chmod 754 /lib/systemd/system/nginx.service
systemctl start nginx.service
systemctl enable nginx.service
Two, install Mysql service
1. Install the Mysql environment dependency package
yum -y install \
ncurses \
ncurses-devel \
bison \
cmake
2. Create Mysql running user
useradd -M -s /sbin/nologin mysql
3. Compile and install
#解压源码包
cd /opt
tar zxvf mysql-boost-5.7.20.tar.gz
#自定义安装
cd /opt/mysql-5.7.20/
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DSYSCONFDIR=/etc \
-DSYSTEMD_PID_DIR=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_BOOST=boost \
-DWITH_SYSTEMD=1
#编译安装
make && make install
4. Modify the mysql configuration file
vim /etc/my.cnf
[client]
port = 3306
socket=/usr/local/mysql/mysql.sock
[mysql]
port = 3306
socket = /usr/local/mysql/mysql.sock
auto-rehash
[mysqld]
user = mysql
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port = 3306
character-set-server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket=/usr/local/mysql/mysql.sock
bind-address = 0.0.0.0
skip-name-resolve
max_connections=2048
default-storage-engine=INNODB
max_allowed_packet=16M
server-id = 1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES
5. Change the owner and group of the mysql installation directory and configuration files
chown -R mysql:mysql /usr/local/mysql/
chown mysql:mysql /etc/my.cnf
6. Set the path environment variable for easy use
echo 'export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
source /etc/profile
7. Initialize the database
cd /usr/local/mysql/bin/
./mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data
8. Add mysqld system service
cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
systemctl daemon-reload
systemctl start mysqld.service
systemctl enable mysqld
9. Modify the login password of mysql
mysqladmin -u root -p password "abc123"
10. Authorize the root user to log in remotely
mysql -u root -p
Enter password to log in
3. Install PHP service
1. Install environment dependent packages
yum -y install gd \
libjpeg libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
libxml2 libxml2-devel \
zlib zlib-devel \
curl curl-devel \
openssl openssl-devel
2. Compile and install
#解压源码包
cd /opt
tar jxvf php-7.1.10.tar.bz2
#自定义安装
cd php-7.1.10
./configure \
--prefix=/usr/local/php \
--with-mysql-sock=/usr/local/mysql/mysql.sock \
--with-mysqli \
--with-zlib \
--with-curl \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-openssl \
--enable-fpm \
--enable-mbstring \
--enable-xml \
--enable-session \
--enable-ftp \
--enable-pdo \
--enable-tokenizer \
--enable-zip
#编译安装
make && make install
3. Optimize the path for easy use
ln -s /usr/local/php/bin/* /usr/local/bin/ ln -s /usr/local/php/sbin/* /usr/local/sbin/
4. Adjust the php configuration file
/usr/local/php/lib/php.ini | main configuration file |
---|---|
/usr/local/php/etc/php-fpm.conf | Process service configuration file (the default is only a template file, which needs to be copied and renamed to php-fpm.conf) |
/usr/local/php/etc/php-fpm.d/www.conf | Extended configuration file (the default is only a template file, which needs to be copied and renamed) |
(1) Modify php.ini
#复制模板并修改
cp /opt/php-7.1.10/php.ini-development /usr/local/php/lib/php.ini
vim /usr/local/php/lib/php.ini
#939行,取消注释,修改
date.timezone = Asia/Shanghai
#1170行,修改
mysqli.default_socket = /usr/local/mysql/mysql.sock
#验证安装的模块
php -m
(2) Modify php-fpm.conf
#复制模板文件
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf
#修改进程服务配置文件
vim php-fpm.conf
#17行,去掉";"注释
pid = run/php-fpm.pid
The last line represents loading all conf files under /usr/local/php/etc/php-fpm.d/
(3) Modify www.conf
cd /usr/local/php/etc/php-fpm.d/ cp www.conf.default www.conf vim www.conf
Modify the listening address (by default, the specified ip is the local machine. If the host that provides nginx service and php service is not the same, it needs to be modified to provide the ip address of the nginx server)
The owner and group can be modified to nginx
5. Start php-fpm
#进入软件包目录,复制并启用service文件
cd /opt/php-7.1.10/sapi/fpm
cp php-fpm.service /usr/lib/systemd/system/php-fpm.service
#重载并开启服务
systemctl daemon-reload
systemctl restart php-fpm.service
Check found that the service is enabled
6. Configure Nginx to support PHP parsing
vim /usr/local/nginx/conf/nginx.conf
#65行,取消注释,修改
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 restart nginx.service
Change /scripts to $document_root to represent the value specified in the root command of the current request (web root directory)
7. Add the inex.php file to test whether the php service is effective
First, you need to add the specified homepage file index.php in /usr/local/nginx/conf/nginx.conf
Reload the service to make the configuration take effect
systemctl reload nginx.service
Add index.php file for access test
#在root指定的根目录下创建index.php文件,并添加内容
vim /usr/local/nginx/html/index.php
<?php
phpinfo();
?>
8. Verify that the database is working properly
Add authorization, write test page
edit
edit
4. Use the LNMP architecture to build a bbs forum
Unzip the forum zip file
Enter the forum file and copy the page to the root directory of the bbs web page
database authorization
visit page
Correct the error reporting part, change the owner and permissions
Continue to the next step after refreshing the page
edit
Choose clean install
Set the database and password just now, and then set an administrator and password
Visit after successful installation
You can log in to the administrator in the upper right corner
So far, using LNMP to publish a website is complete