Author: JackTian wechat public ID: Jake_Internet
This is the sixth day of my participation in Gwen Challenge
Nginx+Keepalived high availability Nginx+Keepalived high availability Nginx+Keepalived high availability Today, I will take you hand in hand to build LNMP architecture and deploy sky Network movie Web application system through LNMP platform.
1. Install Nginx
First of all, need to prepare a Linux server, and then install Nginx service, here but more write to install Nginx steps, specific can see the article “the Nginx series (a) | taught you how to setup Nginx services under Linux environment, if the installation process, have what problem, Welcome to communicate with me.
2. Install MySQL database
Check whether the MySQL database has been installed in the system. If the MySQL database has been installed, uninstall it first to avoid port or program conflicts.
# rpm -q mysql-server mysql
Copy the code
Note: All versions of MySQL above 5.5 require cmake compilation. Instead of. / configure
/configure # gmake && gmake install / # yum -y install cmakeCopy the code
Create MySQL user
# groupadd mysql
# useradd -M -s /sbin/nologin -g mysql mysql
Copy the code
Decompress, compile, install
# tar xf mysql-5.5.22.tar.gz
# cd mysql-5.5.22
# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all
# make && make install
Copy the code
The meanings of the above parameters:
-DCMAKE_INSTALL_PREFIX: specifies the database installation directory
-dsysconfDIR =/etc: specifies the configuration file directory
-DDEFAULT_CHARSET: specifies the default character set encoding. Such as utf8
-ddefault_collation = UTf8_general_CI: Sets default collation rules (UTF8_general_CI fast/UTF8_unicoDE_CI accurate)
-dextra_charsets =all: Enable additional character set types (default: all)
The following figure shows the completion of compilation
Permission to adjust
# chown -R mysql:mysql /usr/local/mysql
Copy the code
Setting up a Configuration File
CNF # CD mysql-5.5.22 # cp support-files/my-medium. CNF /etc/my.cnf # cp support-files/my-mediumCopy the code
Initializing the database
# cd /usr/local/mysql
# scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
Copy the code
The database is successfully initialized. Procedure
Setting the Soft Connection
In order to use MySQL commands in any directory, you can create a soft connection.
# ln -s /usr/local/mysql/bin/* /usr/local/bin/
Copy the code
Add MySQL as a system service
# CD mysql.server /etc/init.d/mysqld # chmod +x /etc/init.d/mysqld # chkconfig --add mysqldCopy the code
Start the MySQL service
# service mysqld start # Starting MySQL.. [OK] # netstat anpt | grep mysqld TCP 0 0 0.0.0.0:0.0.0.0:3306 * 2849 / mysqld LISTENCopy the code
Login verification to check whether the MySQL database is set up
3. Install PHP
FPM (FastCGI Process Manager) module, used to manage PHP parsing instances, optimize parsing efficiency. Single-server LNMP architectures typically use this approach, so add –enable-fpm to enable this module when configuring PHP compilation options.
Unpack the
# tar xf php-5.3.28.tar.gz
# cd php-5.3.28
# ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --enable-fpm --enable-sockets --enable-sysvshm --with-mysql=/usr/local/mysql/bin/mysql_config --enable-xml --with-config-file-path=/etc
# make && make install
Copy the code
If the following error is reported for PHP compilation
configure: error: Cannot find libmysqlclient under /usr.
Copy the code
Solutions:
# ln -s /usr/lib64/mysql/libmysqlclient.so.16 /usr/lib/libmysqlclient.so
Copy the code
Configure Nginx to support the PHP environment by enabling the php-fpm configuration file
Nginx can parse PHP web pages in two ways:
- When mediating: forwarding Web requests to PHP pages to other servers for processing;
- Call the native PHP environment by using PHP’s FPM module;
If FPM is used, you need to start the php-fpm process to listen for PHP resolution requests. In the php-fpm. Conf configuration file, the PID configuration line indicates the location of the PID information.
# cd /usr/local/php/etc/ # cp php-fpm.conf.default php-fpm.conf # useradd -M -s /sbin/nologin php # vi php-fpm.conf 25 Pid = run/php-fpm.pid // Check the pid file location 140 user = nobody // Running user 141 group = nobody // Running group 188 pm.max_children = 50 // Min_spare_servers = 5 // Minimum number of idle processes 195 pm. max_spare_Servers = 35Copy the code
Start the FPM
# cd /usr/local/php/sbin/
# ./php-fpm
Copy the code
Start-up success
# netstat antp | grep PHP - FPM TCP 0 0 127.0.0.1:9000 0.0.0.0: * LISTEN/PHP - 3007 FPM TCP 1 0 192.168.1.11:40560 192.168.1.11:3306 CLOSE_WAIT 3008/php-fpm TCP 1 0 192.168.1.11:40562 192.168.1.11:3306 CLOSE_WAIT 3009/php-fpmCopy the code
Combine PHP with Nginx and modify the configuration file
Whether the PHP page is sent to the LNMP server for parsing, the local PHP-FPM process will be called for parsing, and the localtion configuration should be added in the server {} configuration section to specify any operation to be taken when accessing the. PHP web page. The necessary macro configuration is already contained in the fastcgi.conf file in the conf/ directory and can be added through the include statement.
vim /usr/local/nginx/conf/nginx.conf 35 server { 36 listen 80; 37 server_name www.jacktian.com; 38 39 #charset koi8-r; 40 41 #access_log logs/host.access.log main; 42 43 location / { 44 root html; // PHP page root directory 45 index index.html index.htm index.php; 46 location ~ \.php${// access the.php page configuration segment 47 fastcgi_pass 127.0.0.1:9000; // PHP - FPM () fastcgi_index (); $document_root$fastcgi_script_name; 50 include fastcgi_params; // Include fastcgi.conf sample configuration 51} 52 53}Copy the code
Create a PHP file
Using phP-fPM parsing as an example, create a test web page file in the PHP document root.
# cd /usr/local/nginx/html/ v# im index.php <? php phpinfo(); ? >Copy the code
Restart the Nginx service
# ./nginx -s stop
# ./nginx
Copy the code
validation
In the local browser address bar, type http://192.168.1.11/index.php test, PHP is combined with Nginx success here.
4. Deploy the Web application system on LNMP platform
LNMP and LAMP platforms are very similar, mainly in the difference of Web services software, which has nothing to do with Web applications developed using PHP. PHP applications are also deployed in a similar way, taking SKYUC Sky Webmovie system as an example.
SKYUC is a SET of PHP video on demand system, supporting various P2P streaming media software, suitable for movie portal, multimedia center, Internet bar, hotel, education and other industries to use.
Download and deploy the program code
Unzip the SKYUC program, locate the wwwroot folder, and place it in the root directory of the LNMP server. Then adjust the permissions to allow Nginx and PHP-Fpm programs to have the necessary write permissions.
. # # yum -y install unzip unzip SKYUC v3.4.2. SOURCE. Zip. # CD SKYUC v3.4.2. SOURCE # below mv/usr/local/nginx/HTML/SKYUC # chmod -R 777 skyucCopy the code
Creating a database
To reduce database risk for Web applications, you can set up a dedicated database and authorized users.
mysql> create database skyucdb;
mysql> grant all on skyucdb.* to 'runskyuc'@'%' identified by '123.com';
Copy the code
Login authentication
Installing Web Applications
Local access http://192.168.1.11/skyuc/install/index.php, will open SKYUC installer, based on the page request, only three steps to install successfully.
Ensure that the system environment, directory permissions, and cache writability pass the check. Otherwise, the installation cannot continue.
In the next step of configuring the system, in addition to correctly configuring the database connection, there is a point that needs to be emphasized with everyone, the type should be selected: MySQL, but also set up a good management account, password and other information, after the installation, you can delete the install directory to reduce security risks.
Nginx 403 forbidden (13: Permission denied) Nginx 403 forbidden (13: Permission denied)
Step 1: Change the nginx.conf user to be the same as the startup user
# vim /usr/local/nginx/conf/nginx.conf
2 user root;
3 worker_processes 1;
Copy the code
HTML or index.php file is missing. The specified index.php file is missing in line 45 of the configuration file.
43 location / { 44 root html; 45 index index.html index.htm index.php; 46 location ~ \.php${47 fastcgi_pass 127.0.0.1:9000; 48 fastcgi_index index.php; 49 fastcgi_param SCRIPT_FILENAME /$document_root$fastcgi_script_name; 50 include fastcgi_params; 51}Copy the code
Step 3: SELinux is set to Enabled, which needs to be changed to Disabled.
# vi /etc/selinux/config
7 SELINUX=disabled
Copy the code
Step 4: Restart the Nginx service.
# cd /usr/local/nginx/sbin/
# ./nginx -s stop
# ./nginx
Copy the code
Access the Web application system
Through the local access http://192.168.1.11/skyuc/, you can see the sky network film system home page.
Through local visit http://192.168.1.11/skyuc/admincp/, enter just the configured administrator account password to log in to the background management interface.
Environment Package Download
Public number: Jie Ge’s IT journey, background reply: LNMP can get the installation package in the article.
Recommended reading
Nginx series (a) | taught you how to setup Nginx services under Linux environment
Nginx series (2) | article take you read Nginx forward and reverse proxy
Nginx series (3) | show you read Nginx load balancing
Nginx series (4) | show you read Nginx noise separation
Original is not easy, if you think this article is useful to you, please kindly like, comment or forward this article, because this will be my power to output more high-quality articles, thank you!
See you next time!