LNMP / LAMP

LNMP / LAMP

surroundings:

name Linux Nginx MySQL PHP Apache
version Centos7 nginx-1.14.1 mysql-5.6.25 php-5.6.36 Apache/2.4.6

Required for the installation-dependent nginx

  • gcc installed

    We need to first install nginx official website to download the source code is compiled, and the compiler environment depend on gcc, gcc environment if not, you need to install:

    yum install -y gcc-c++

  • Installation PCRE pcre-devel

    PCRE (Perl Compatible Regular Expressions) is a Perl library, including perl-compatible regular expression library. The module uses nginx http pcre regular expressions to parse, so it is necessary to install pcre library on linux, pcre-devel pcre developed using a secondary development library. nginx also need this library. command:

    yum install -y pcre pcre-devel

  • zlib installation

    zlib library provides a variety of compression and decompression using zlib nginx way for the contents of the package are http gzip, so you need to install on Centos zlib library

    yum install -y zlib zlib-devel

  • Install OpenSSL

    OpenSSL is a powerful Secure Sockets Layer cryptographic library cryptographic algorithms include major, commonly used key and certificate management and SSL protocol encapsulation, and provides a wealth of applications for testing or other purposes.
    nginx not only supports the http protocol, also supports https (http over ssl ie transmission protocol), so you need to install the OpenSSL library in Centos.

    yum install -y openssl openssl-devel

Initialization nginx (configuration)

  1. After the extraction is completed into the extracted directory

    cd /app/tool/nginx-1.14.1

  2. Configuration
    fact, nginx-1.14.0 version you do not need to configure the relevant things, the default on it. Of course, if you want your own configuration directory is also possible.

    • The default configuration (recommended)

      Compile

      ./configure

Compile and install

  1. carried out

    make && make install

  2. Output the last line:

    make[1]: Leaving directory `/app/tool/nginx-1.14.1'
  3. Finding the installation path

    whereis nginx

    Output:

    nginx: /usr/local/nginx

    Start and restart

  4. start up

    • Enter sbin directory

      cd /usr/local/nginx/sbin

    • start up

      ./nginx

  5. stop

    • Nginx first find out the process id and then use the kill command to force kill the process

      ./nginx -s stop

    • Stop: Wait nginx process is complete stopping processing tasks

      ./nginx -s quit

  6. Restart

    Stop and then start

    ./nginx -s quit

    ./nginx

  7. Reload the configuration file

    When the configuration file nginx.conf modify ngin x, to want a profile take effect need to restart nginx, use -s reload without first stopping ngin x nginx restart to take effect in nginx configuration information as follows:

    ./nginx -s reload

Compile and install php

yum install libxml2-devel
./configure --enable-fpm --with-mysql --with-mysqli --with-pdo-mysql  --enable-mbstring
make
make install
cp php.ini-development /usr/local/php/php.ini
cp /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.conf
cp sapi/fpm/php-fpm /usr/local/bin
vim /usr/local/php/php.ini
# 编辑配置文件
cgi.fix_pathinfo=0
# 保存退出
# 启动fpm
/usr/local/bin/php-fpm
# 编辑配置文件
# index 添加 index.php
 location / {
            root   html;
            index  index.php index.html index.htm;
        }
# 取消注释 修改为 $document_root$fastcgi_script_name
 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;
        }
# 保存退出
# 测试php
vim html/index.php
<?php
        phpinfo();
?>
# 保存退出
# 重新加载配置文件
./nginx -s reload
# 访问 172.16.0.6/index.php可以看到php相关信息

Compile and install mysql

 yum install -y ncurses-devel automake autoconf bison libtool-ltdl-devel
 yum install cmake
 groupadd mysql
 useradd -s /sbin/nologin -g mysql -M mysql
 mkdir -p /opt/mysql/data
 mkdir -p /opt/mysql/tmp
 cd /opt/mysql-5.6.25
      cmake -DCMAKE_INSTALL_PREFIX=/opt/mysql -DMYSQL_DATADIR=/opt/mysql/data -DMYSQL_UNIX_ADDR=/opt/mysql/tmp/mysql.sock -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_ZLIB=bundled -DWITH_SSL=bundled -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 -DENABLE_DOWNLOADS=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DMYSQL_TCP_PORT=3306 -DWITH_DEBUG=0      
      make && make install
      /opt/mysql/scripts/mysql_install_db --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql/data --user=mysql
      #授权
      chown -R mysql:mysql /opt/mysql/
      cp -f /opt/mysql/support-files/my*.cnf /etc/my.cnf
      cp /opt/mysql/support-files/mysql.server /etc/init.d/mysqld
      # 加权限
      chmod +x /etc/init.d/mysqld
    # 自启
      chkconfig --add mysqld
      chkconfig mysqld on
      #添加环境
      echo "export PATH=$PATH:/opt/mysql/bin/" >>/etc/profile
      source /etc/profile
# 启动mysql服务
/etc/init.d/mysqld start   
# 连接
mysql -uroot -p
(回车)
#修改密码
mysql> use mysql; 
mysql> update user set password=password('ci123vm') where user='root' and host='localhost'; 
mysql> flush privileges; 
# 远程连接授权
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
# 配置远程连接密码
set password for root@'%' = password('ci1233vm');

phpMyAdmin installation configuration

Extract to nginx / html directory:

xz -d phpMyAdmin-4.9.0.1-all-languages.tar.xz
tar -xvf phpMyAdmin-4.9.0.1-all-languages.tar 
mv phpMyAdmin-4.9.0.1-all-languages/ /usr/local/nginx/html/

Into the extracted directory, configure:

cp config.sample.inc.php config.inc.php

Edit the following configuration:

img

log in:

http://172.16.0.6/phpMyAdmin-4.9.0.1-all-languages/index.php

supplement:

php module deletion may be performed at the corresponding module ext / source directory with the command phpize:

/usr/local/bin/phpize
./configure --with-php-config=/usr/local/bin/php-config
或:
./configure --with-php-config=/usr/local/bin/php-config --with-jpeg-dir --with-png-dir --with-freetype-dir --with-zlib-dir --with-gd
make && make install

After executing the above command, the module will be compiled into a directory under the expanded configuration files defined profile path and expansion path related information are available through phpinfo () function to see on the screen:

<?php 
    phpinfo();
?>

httpd configuration to integrate PHP :

# 加载php模块 整合php-fpm
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

# 开启虚拟主机模块
LoadModule vhost_alias_module modules/mod_vhost_alias.so
# 加载虚拟主机配置文件
Include conf/extra/httpd-vhosts.conf
# 最后加一个
<FilesMatch \.php$>
SetHandler "proxy:fcgi://127.0.0.1:9000"
</FilesMatch>                  

httpd-vhosts.conf Example:

<VirtualHost *:80>
        ServerAdmin [email protected]
        #ServerAdmin 192.168.3.227
        DocumentRoot /opt/news
        ServerName news.ci123.com
        #ServerName 192.168.3.227

        ErrorLog logs/news.xxx.com-error_log
        #CustomLog "|/usr/local/sbin/cronolog /opt/apache/logs/news.opt.com-access.%Y-%m-%d" combined_log env=!donotlog
        <Directory /opt/news>
                Options FollowSymLinks
                allowoverride None
                Require all granted

                RewriteEngine On
                RewriteBase /
                RewriteRule ^index\.php$ - [L]
                RewriteCond %{REQUEST_FILENAME} !-f
                RewriteCond %{REQUEST_FILENAME} !-d
                RewriteRule . /index.php [L]
                RewriteRule ^/article/[0-9]+\.html$ /article.php?id=$1 [L]
        </Directory>

        Alias /social /opt/news/social
        <Directory /opt/news/social>
                RewriteEngine On
                RewriteBase /social

                RewriteRule ^index\.php$ - [L]
                RewriteCond %{REQUEST_FILENAME} !-f
                RewriteCond %{REQUEST_FILENAME} !-d
                RewriteRule . /social/index.php [L]
        </Directory>
</VirtualHost>

Recently found that the use of a Golanguage development Webserver Caddy. Its configuration is more compact, and can automatically apply and configure SSL certificates (recommended).

Guess you like

Origin www.cnblogs.com/yanshaoshuai/p/12103536.html