Build LNMP architecture in Linux in detail

Source: Internet
Author: User
Tags configuration php fpm gmp install php openssl nginx server

Environment description

IP programs that need to be installed
192.168.209.12 Nginx MySQL PHP
  *LNMP The installation of the schema *① install Nginx② install Mysql③ install Php④ last configure Nginx and create PHP test program ⑤ Verify *******************① installation nginx************* 1.//Creating System User Nginx [[email protected] ~]# useradd-r-m-s/sbin/nologin nginx//installation dependent environment [[email  Protected] ~]# yum-y install pcre-devel OpenSSL openssl-devel gd-devel[[email protected] ~]# yum install-y gd-devel -2.0.35-26.el7.x86_64.rpm [[email protected] ~]# yum-y groups Mark install ' Development Tools '//create log storage directory [[email& Nbsp;protected] ~]# mkdir-p/var/log/nginx[[email protected] ~]# chown-r nginx.nginx/var/log/nginx//Download nginx[[ Email protected] ~]# cd/usr/src/[[email protected] src]# wgethttp://nginx.org/download/  nginx-1.14.0.tar.gz//compile and install [[email protected] src]# tar XF nginx-1.14.0.tar.gz[[email protected] src]# CD nginx-1.14.0  

[[email protected] nginx-1.14.0]#./configure--prefix=/usr/local/nginx--user=nginx--group=nginx-- With-debug--with-http_ssl_module--with-http_realip_module--with-http_image_filter_module--with-http_gunzip_ Module--with-http_gzip_static_module--with-http_stub_status_module--http-log-path=/var/log/nginx/access.log-- Error-log-path=/var/log/nginx/error.log

 [[email protected] nginx-1.14.0]# make-j $ (grep ' processor '/proc/cpuinfo | wc-l) && make install 2. Nginx post-installation configuration//configuration environment variables [[[email protected] ~]# echo ' export path=/usr/local/nginx/sbin: $PATH ' >/etc/profile.d/ngi nx.sh [[email protected] ~]# source/etc/profile.d/nginx.sh [[email protected] ~]# nginx [[Email protec] Ted] ~]# ss-antl State recv-q send-q Local address:port Peer address:port L Isten 0 *:80 *:* LISTEN 0 12 8 *:22 *:* LISTEN 0 100 127.0 .0.1:25 *:* LISTEN 0 128::: 22 :::* LISTEN 0:: 1:25:::* 
 ***********************②安装mysql************************** //安装依赖 包[[email protected] ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel//创建用户和组[[email protected] ~]# cd /usr/src/[[email protected] src]# groupadd -r -g 306 mysql[[email protected] src]# useradd -M -s /sbin/nologin -g 306 -u 306 mysql//下载二进制格式的mysql软件包

[Email protected] src]# wget https://downloads.mysql.com/archives/get/file/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz

Unzip the software to/usr/local[[email protected] src]# tar XF mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz-c/usr/local/[[ Email protected] src]# cd/usr/local///Create soft connection [[email protected] local]# LN-SV mysql-5.7.22-linux-glibc2.12-x86_64/mysql//modifying the genus/usr/local/mysql of the directory [[email protected] local]# chown-r Mysql.mysql/usr/local/mysql[[email protected] local]# ll/usr/local/mysql//Add environment variable [[email protected] ~]# Ls/usr/local/mysql[[email protected] ~]# echo ' export path=/usr/local/mysql/bin: $PATH ' >/etc/profile.d/ Mysql.sh[[email protected] ~]# source/etc/profile.d/mysql.sh[[email protected] ~]# echo $PATH//Set up data storage directory [[ Email protected] ~]# mkdir/opt/data[[email protected] ~]# chown-r mysql.mysql/opt/data/[[email  Protected] ~]# ll/opt/total dosage 0drwxr-xr-x. 2 MySQL MySQL 6 August 13:20 data//Initialize database Note This command will generate a temporary password to remember jd?ajfrky4pq[[email protected] ~]#/usr/local/mysql/bin/ Mysqld--initialize--user=mysql--datadir=/opt/data///configuration mysql//Soft Connection [[email protected] ~]# ln-sv/usr/local/mysql/include//usr/local/include/mysql[[email protected] ~]# Echo ' /usr/local/mysql/lib ' >/etc/ld.so.conf.d/mysql.conf[[email protected] ~]# ldconfig-v//generate configuration file [[email  Protected] ~]# cat >/etc/my.cnf << eof> [mysqld]> basedir =/usr/local/mysql> DataDir =/opt/data> s Ocket =/tmp/mysql.sock> Port = 3306> Pid-file =/opt/data/mysql.pid> user = mysql> skip-name-resolve> EOF/ /config service startup script [[email protected] ~]# cp-a/usr/local/mysql/support-files/mysql.server/etc/init.d/mysqld[[email  protected] ~]# Sed-ri ' s#^ (basedir=). *#\1/usr/local/mysql#g '/etc/init.d/mysqld[[email protected] ~]# sed -ri ' s#^ (datadir=). *#\1/opt/data#g '/etc/init.d/mysqld//start mysql[[email protected] ~]# service mysqld start[[ Email protected] ~]# ps-ef |grep mysql[[email protected] ~]# ss-antl State recv-q Send-Q Local A        Ddress:port Peer Address:port      LISTEN 0 *:80 *:* LISTEN 0 *:22 *:* LISTEN 0 100 12 7.0.0.1:25 *:* LISTEN 0 128::                                 :::* LISTEN 0 100:: 1:25         :::* LISTEN 0::: 3306:::* Change Password use temporary password login [[email protected] ~]# MYSQL-UROOT-PJD?AJFRKY4PQ This is the temporary password for the above steps mysql> set password = password (' Lanzhiyong ');
****************************③安装php*************************3.安装php//配置yum源[[email protected] ~]# cd /etc/yum.repos.d/[[email protected] yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo [[email protected] ~]# sed -i ‘s/\$releasever/7/g‘ /etc/yum.repos.d/CentOS7-Base-163.repo[[email protected] ~]# sed -i ‘s/^enabled=.*/enabled=1/g‘ /etc/yum.repos.d/CentOS7-Base-163.repo[[email protected] ~]# yum install -y epel-release

Install dependent packages
[Email protected] ~]# yum-y install libxml2 libxml2-devel OpenSSL openssl-devel bzip2 bzip2-devel libcurl libcurl-devel Libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel GMP gmp-devel libmcrypt libmcrypt-devel readline Readli Ne-devel libxslt libxslt-devel Mhash mhash-devel

Download php[[email protected] ~]# cd/usr/src/[[email protected] src]# wget http://cn.php.net/distributions/ php-7.2.8.tar.xz//compile and install PHP [[email protected] src]# tar XF php-7.2.8.tar.xz[[email protected] src]# CD Php-7.2.8[[email protected] php-7.2.8]#./configure--prefix=/usr/local/php7--with-curl--with-freetype-dir-- WITH-GD--with-gettext--with-iconv-dir--with-kerberos--with-libdir=lib64--with-libxml-dir=/usr--with-mysqli=/ Usr/local/mysql/bin/mysql_config--with-openssl--with-pcre-regex--with-pdo-mysql--with-pdo-sqlite--with-pear-- With-jpeg-dir--with-png-dir--with-xmlrpc--with-xsl--with-zlib--with-config-file-path=/etc-- WITH-CONFIG-FILE-SCAN-DIR=/ETC/PHP.D--with-bz2--enable-fpm--enable-bcmath--enable-libxml-- Enable-inline-optimization--enable-mbregex--enable-mbstring--enable-opcache--enable-pcntl--enable-shmop-- Enable-soap--enable-sockets--enable-sysvsem--enable-xml--enable-zip[[email protected] php-7.2.8]# make-j $ ( Cat/proC/cpuinfo |grep processor |wc-l) [[email protected] php-7.2.8]# make install//post-installation configuration [[email protected] ~]# Echo ' Export path=/usr/local/php7/bin: $PATH ' >/etc/profile.d/php7.sh[[email protected] ~]# source/etc/ Profile.d/php7.sh[[email protected] ~]# cd/usr/src/php-7.2.8[[email protected] php-7.2.8]# which php/usr/ Local/php7/bin/php[[email protected] php-7.2.8]# php-v//configuration php-fpm[[email protected] php-7.2.8]# CP Php.ini-production/etc/php.ini[[email protected] php-7.2.8]# CP sapi/fpm/init.d.php-fpm/etc/init.d/php-fpm[[ Email protected] php-7.2.8]# chmod +x/etc/rc.d/init.d/php-fpm[[email protected] php-7.2.8]# cp/usr/local/ Php7/etc/php-fpm.conf.default/usr/local/php7/etc/php-fpm.conf

[[email protected] php-7.2.8]# cp/usr/local/php7/etc/php-fpm.d/www.conf.default/usr/local/php7/etc/ php-fpm.d/www.conf

The relevant options for configuring FPM are the values you need: [[email protected] ~]# vim/usr/local/php7/etc/php-fpm.conf***** add content to the last side of the configuration file Pm.max_ Children = 50pm.start_servers = 5pm.min_spare_servers = 2pm.max_spare_servers = 8[[email protected] ~]# tail/usr/lo cal/php7/etc/php-fpm.conf//start php-fpm[[email protected] ~]# service php-fpm startstarting php-fpm done[[email       protected] ~]# ss-antl State recv-q send-q Local address:port Peer address:port LISTEN                     0 *:80 *:* LISTEN 0 128                            *:22 *:* LISTEN 0 100 127.0.0.1:25                   *:* LISTEN 0 127.0.0.1:9000 *:* LISTEN 0::: +:::* LIS   TEN 0 100:: 1:25                             :::* LISTEN 0 80::: 3306 :::* [[email protected] ~]# ps-ef |grep php
*******************④最后配置nginx和创建php测试程序****************************

Nginx Config file/usr/local/nginx/conf/nginx.conf, modify the location block as long as you modify the contents of the server{} configuration block in the configuration file, Append index.php let Nginx server default support index.php home page

[[email protected] ~]# vim /usr/local/nginx/conf/nginx.conf…………………………………………server {listen 80;server_name localhost;#charset koi8-r;#access_log logs/host.access.log main;location / {root html;index index.html index.htm//后面添加 index.php;}…… ……………………………………#pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000location ~ \.php$ {root           html;fastcgi_pass   127.0.0.1:9000;fastcgi_index  index.php;#fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;#主要修改的就是fastcgi_param中的/scripts为$document_rootfastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include        fastcgi_params;}#deny access to .htaccess files, if Apache‘s document root//修改配置文件后重新加载nginx[[email protected] ~]# /usr/local/nginx/sbin/nginx -s reload//创建测试php程序,在/usr/local/nginx/html/test.php,打印一下php配置[[email protected] ~]# cat > /usr/local/nginx/html/test.php << EOF> ?php> phpinfo();> ?>> EOF
  ***********************⑤验证******************************最后打开浏览器输入 192.168.209.12/test.php 看到输出的页面,说明nginx和php都配置成功了

Build LNMP architecture in Linux in detail

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.