LNMP represents the web server architecture of Nginx+MySQL+PHP under Linux system.
Linux is a kind of Unix computer operating system, which is the most popular free operating system. Representative versions include debian, centos, ubuntu, fedora, gentoo, etc.
Nginx is a high-performance HTTP and reverse proxy server, and also an IMAP/POP3/SMTP proxy server.
Mysql is a small relational database management system.
PHP is a script language that embeds HTML documents on the server side.
These four kinds of software are free and open-source software, which are combined to become a free, efficient and extensible website service system
In this chapter, I will take you to compile LNMP manually.
There are four steps in the experiment
Install nginx service
Install mysql service
Install and configure PHP parsing environment
Deploy discuz Community Forum web application
Experimental environment: centos7.5 ﹣ nginx-1.12 ﹣ mysql-boot-5.7 ﹣ php-7.1
Experiment begins
[install nginx service]
1. Installation environment depends on installation package:
[root@localhost ~]# yum -y install pcre-devel zlib-devel gcc gcc-c++
2. Create running users and groups
[root@localhost ~]# useradd -M -s /sbin/nologin nginx
3. Unzip the installation package
tar zxvf nginx-1.12.2.tar.gz -C /opt/
4. Compilation, installation and configuration optimization
cd nginx-1.12.2/ ./configure \ --prefix=/usr/local/nginx \ --user=nginx \ --group=nginx \ --with-http_stub_status_module make && make install //Compile and install nginx ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ //Creating a soft connection for a command systemctl stop firewalld.service //Turn off firewall setenforce 0 nginx -t //Check the configuration file for problems //Convenient to manage nginx service, edit nginx service script and add it to system CTL 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=/usr/bin/kill -s HUP $MAINPID ExecStop=/usr/bin/ki11 -s QUIT $MATNPID PrivateTmp=true [Install] WantedBy=multi-user.target chmod 754 nginx.service //Give execution permission
[install mysql service]
1. Install compilation tools
yum -y install \ ncurses \ ncurses-devel \ bison \ cmake\ make
2. Decompress the package
tar zxvf mysql-boost-5.7.20.tar.gz -C /opt
3. Customized configuration
cd /opt/my 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_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 //This parameter must be added in version 5.7
4. Compile and install
make && make install
5. Add program user and relevant permission settings
useradd -s /sbin/nologin mysql chown -R mysql:mysql /usr/local/mysql/ //Set the main genus group
6. Modify the configuration file (delete the original content and copy the following content)
vi /etc/my.cnf
[client] port = 3306 default-character-set=utf8 socket = /usr/local/mysql/mysql.sock [mysql] port = 3306 default-character-set=utf8 socket = /usr/local/mysql/mysql.sock [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 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
7. Setting environment variables
echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile echo 'export PATH' >> /etc/profile source /etc/profile
8. Initialize database
cd /usr/local/mysql/ bin/mysqld \ --initialize-insecure \ --user=mysql \ --basedir=/usr/local/mysql \ --datadir=/usr/local/mysql/data cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
9. Start, close and status of database
systemctl enable mysqld systemctl start mysqld systemctl stop mysqld netstat -natp | grep 3306
10. Set password
mysqladmin -uroot -p password mysql -u root -p //Enter database
[install PHP service]
1. Installation environment dependency package
yum install -y \ libjpeg \ libjpeg-devel \ libpng libpng-devel \ freetype freetype-devel \ libxml2 \ libxml2-devel \ zlib zlib-devel \ curl curl-devel \ openssl openssl-devel
2. Unzip the installation package
tar jxvf php-7.1.10.tar.bz -C /opt
3. Customized configuration
cd /opt/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
4. Modify the configuration file
//php has three configuration files:
php.ini / / core profile
php-fpm.conf / / process service configuration file
www.conf / / extended profile
cp php.ini-development /usr/local/php/lib/php.ini //Configure core modules vim /usr/local/php/lib/php.ini mysqli.default_socket = /usr/local/mysql/mysql.sock date.timezone = Asia/Shanghai //Set path, timely area /usr/local/php/bin/php -m //Verify installation module
Configure and optimize fpm module
cd /usr/local/php/etc/ cp php-fpm.conf.default php-fpm.conf vim php-fpm.conf pid = run/php-fpm.pid //Remove; note pid on cd /usr/local/php/etc/php-fpm.d/ cp www.conf.default www.conf /usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini //Open PHP FPM module netstat -natp | grep 9000 ln -s /usr/local/php/bin/* /usr/local/bin/ //Create a soft connection. System identification command ln -s /usr/local/php/bin/* /usr/local/bin/ //Create a soft connection. System identification command
Make nginx support php function
vim /usr/local/nginx/conf/nginx.conf //There is in the configuration file, just remove the comment and modify the path location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name; include fastcgi_params; }
5. Configure service home page information
killall -1 nginx //Restart nginx service cd /usr/local/nginx/html/ mv index.html index.php vim index.php <?php phpinfo(); ?> //Original content change 192.168.109.137/index.php //Access home page
6. Test whether the database works normally
mysql -uroot -p CREATE DATABASE bbs; GRANT all ON bbs.* TO 'bbsuser' @'%' IDENTIFIED BY 'admin123'; GRANT all ON bbs.* TO 'bbsuser' @'localhost' IDENTIFIED BY 'admin123'; flush privileges; #Enter / / configure account file show databases; /view the database
7. Test connectivity
vi /usr/local/nginx/html/index. php ##The content of the original test page is changed as follows <?php $link=mysqli_connect('192.168.109.137',' bbsadm' ,'admin123') ; if($link) echo "<h1>Success!!</h1>"; else echo "Fail!!" ; ?> systemctl restart nginx //Test "http://192.168.109.137/index.php" on the web page“
[deploy the discuz Community Forum web application]
unzip Discuz_X3.4_SC_UTF8.zip -d /opt ##Unzip the installation package cd /tmp/dir_SC_UTF8/ cp -r upload/ /usr/local/nginx/html/bbs ##Add permissions so that the service can be installed cd /usr/local/nginx/html/bbs/ chown -R root:nginx ./config/ chown -R root:nginx ./data/ chown -R root:nginx ./uc_client/ chown -R root:nginx ./uc_server/ chmod -R 777 ./config/ chmod -R 777 ./data/ chmod -R 777 ./uc_client/ chmod -R 777 ./uc_server/ 192.168.109.137/bbs/install/index.php //After setting permissions, install 192.168.109.137/bbs/index.php //Installation completed, log in to use
The manual compilation of LNMP is completed. Other services about nginx can be viewed on my homepage