LNMP build; with three sites (Typecho, discuz, dedecms)

Prepare the environment for the Amazon cloud host and download the required packages

mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
nginx-1.12.1.tar.gz   php-5.6.30.tar.bz2

install msyql

decompress mysql

mysql is a binary compilation-free package, so the compilation process is omitted

Move to /usr/local/ and change its name to mysql

tar -zxvf mysql-5.6.35-linux-glibc2.5-x86_64.tar.g
mv mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql

initialization

enter the directory

cd /usr/local/mysql

Before initialization, remember to determine whether there is a data directory

./scripts/mysql_install_db --user=mysql --datadir=/data/mysql

Install the missing dependencies, otherwise the initialization cannot be successful

yum install -y perl-Data-Dumper.x86_64
yum install -y libaio

All in the mysql directory

copy configuration file

cp support-files/my-default.cnf /etc/my.cnf

Copy the startup script

cp support-files/mysql.server /etc/init.d/mysqld

change configuration file

vim /etc/my.cnf

Add under [mysqld]

datadir=/data/mysql
socket=/tmp/mysql.sock

Change startup script

vim /etc/init.d/mysqld

Find the following two items and add the path

basedir=/usr/local/mysql
datadir=/data/mysql

Check to open the service

/etc/init.d/mysqld start

screen output

Starting MySQL.Logging to '/data/mysql/ip-172-31-45-37.us-east-2.compute.internal.err'.
SUCCESS!

Add mysql to the service list

chkconfig --add mysqld

Configure the mysql service and start it at boot

chkconfig mysqld on

install php-fpm

Install dependencies

yum install -y gcc
yum install -y libxml2-devel.x86_64
yum install -y openssl-devel.x86_64
yum install -y bzip2-devel.x86_64
yum install -y libjpeg-devel
yum install -y libpng-devel
yum install -y freetype-devel
yum install -y libcurl-devel.x86_64

Install the third-party yum source//Because the Amazon host does not support the installation of extension sources, use the third-party source to install

wget http://www.atomicorp.com/installers/atomic
sh atomic
yum  install  php-mcrypt  libmcrypt  libmcrypt-devel

initialization

./configure --prefix=/usr/local/php-fpm  
--with-config-file-path=/usr/local/php-fpm/etc 
--enable-fpm 
--with-fpm-user=php-fpm 
--with-fpm-group=php-fpm 
--with-mysql=/usr/local/mysql 
--with-mysqli=/usr/local/mysql/bin/mysql_config 
--with-pdo-mysql=/usr/local/mysql 
--with-mysql-sock=/tmp/mysql.sock 
--with-libxml-dir 
--with-gd 
--with-jpeg-dir 
--with-png-dir 
--with-freetype-dir 
--with-iconv-dir 
--with-zlib-dir 
--with-mcrypt 
--enable-soap 
--enable-gd-native-ttf 
--enable-ftp 
--enable-mbstring 
--enable-exif 
--with-pear 
--with-curl 
--with-openssl 
--disable-fileinfo  //编译错误之后新加入

compile

make && make install

error

make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1

When the make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1 appears when configuring PHP, it
is because the server memory is less than 1G.
Just add --disable-fileinfo to the configuration command

Copy the main configuration file

cp php.ini-production /usr/local/php-fpm/etc/php.ini

Add configuration file

vim /usr/local/php-fpm/etc/php-fpm.con
[global]  
pid = /usr/local/php-fpm/var/run/php-fpm.pid   
error_log = /usr/local/php-fpm/var/log/php-fpm.log  
include = etc/php-fpm.d/*.conf   //可以自定义pool

Copy the startup script

cp /usr/local/src/php-5.6.30/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

Add php-fpm to the list of services

chkconfig --add php-fpm

Configure boot to start php-fpm

chkconfig php-fpm on

start the server

service php-fpm start

Check the process, whether the service is enabled

ps aux |grep php-fpm

Nginx installation

./configure --prefix=/usr/local/nginx

Create a startup script for Nginx

vim /etc/init.d/nginx
#!/bin/bash
# chkconfig: - 30 21
# description: http service.
# Source Function Library
. /etc/init.d/functions
# Nginx Settings
NGINX_SBIN="/usr/local/nginx/sbin/nginx"
NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
NGINX_PID="/usr/local/nginx/logs/nginx.pid"
RETVAL=0
prog="Nginx"
start()
{
echo -n $"Starting $prog: "
mkdir -p /dev/shm/nginx_temp
daemon $NGINX_SBIN -c $NGINX_CONF
RETVAL=$?
echo
return $RETVAL
}
stop()
{
echo -n $"Stopping $prog: "
killproc -p $NGINX_PID $NGINX_SBIN -TERM
rm -rf /dev/shm/nginx_temp
RETVAL=$?
echo
return $RETVAL
}
reload()
{
echo -n $"Reloading $prog: "
killproc -p $NGINX_PID $NGINX_SBIN -HUP
RETVAL=$?
echo
return $RETVAL
}
restart()
{
stop
start
}
configtest()
{
$NGINX_SBIN -c $NGINX_CONF -t
return 0
}
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
restart
;;
configtest)
configtest
;;
*)
echo $"Usage: $0 {start|stop|reload|restart|configtest}"
RETVAL=1
esac
exit $RETVAL

Customize the nginx.conf file

user nobody nobody;
worker_processes 2;
error_log /usr/local/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;
events
{
    use epoll;
    worker_connections 6000;
}
http
{
    include mime.types;
    default_type application/octet-stream;
    server_names_hash_bucket_size 3526;
    server_names_hash_max_size 4096;
    log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
    ' $host "$request_uri" $status'
    ' "$http_referer" "$http_user_agent"';
    sendfile on;
    tcp_nopush on;
    keepalive_timeout 30;
    client_header_timeout 3m;
    client_body_timeout 3m;
    send_timeout 3m;
    connection_pool_size 256;
    client_header_buffer_size 1k;
    large_client_header_buffers 8 4k;
    request_pool_size 4k;
    output_buffers 4 32k;
    postpone_output 1460;
    client_max_body_size 10m;
    client_body_buffer_size 256k;
    client_body_temp_path /usr/local/nginx/client_body_temp;
    proxy_temp_path /usr/local/nginx/proxy_temp;
    fastcgi_temp_path /usr/local/nginx/fastcgi_temp;
    fastcgi_intercept_errors on;
    tcp_nodelay on;
    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 8k;
    gzip_comp_level 5;
    gzip_http_version 1.1;
    gzip_types text/plain application/x-javascript text/css text/htm
    application/xml;
    include vhost/*.conf;   //新增这一行,定义默认虚拟主机的目录
}

Check for grammar problems

/usr/local/nginx/sbin/nginx -t

restart the service

/usr/local/nginx/sbin/nginx -s reload

Error:

nginx: [error] invalid PID number "" in "/usr/local/nginx/logs/nginx.pid"

Turns out the server didn't start

service nginx start 

Change profile permissions

chmod 755 /etc/init.d/nginx

Add nginx to the service list

chkconfig --add nginx

Configure to start the nginx service

chkconfig nginx on

Build blog, cms, bbs

Download the required files
, decompress them, and drop the decompressed packages to the /data/wwwroot/ directory.
To ensure access, give the directory permissions

chmod 755 /data/wwwroot/

blog 《Typecho》

configure vhost

vim /usr/local/nginx/conf/vhost/build.conf

The content is as follows:

server
{
    listen 80 ;
    server_name blog.in-86.com;
    index index.html index.htm index.php;
    root /data/wwwroot/build;

access_log /tmp/build.com.log combined_realip;   //访问日志

        if (!-e $request_filename) {
            rewrite ^(.*)$ /index.php$1 last;    
        }

location ~ \.php(\/.*)*$     
    {
         set $path_info "";
                set $real_script_name $fastcgi_script_name;
                if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
                        set $real_script_name $1;
                        set $path_info $2;
                }
                fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
                fastcgi_param SCRIPT_NAME $real_script_name;
                fastcgi_param PATH_INFO $path_info;

        include fastcgi_params;
        fastcgi_pass unix:/tmp/php-fcgi.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /data/wwwroot/build$fastcgi_script_name;
    }
}

Highlight the necessary configuration for the Typecho program. Otherwise, it will cause 404 access to the management inner page.

Create pool configuration file

vim /usr/local/php-fpm/etc/php-fpm.d/blog.conf

The content is as follows:

[blog]
listen = /tmp/php-fcgi.sock
listen.mode = 666
user = php-fpm
group = php-fpm
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024

After configuring, remember to check the syntax and reload the service

nginx

/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload

php-fpm

/usr/local/php-fpm/sbin/php-fpm -t
/etc/init.d/php-fpm reload

Turn off selinux firewall

getenforce  //检查防火墙状态
setenforce 0  //临时关闭
vim /etc/selinux/config  //改配置文件永久关闭

check iptables

iptables -F
iptables -I INPUT -p tcp --dport 80 -j ACCEP  //放行80
iptables -nvL  //查看规则

netstat -lntp  //查看nginx是否开始监听80端口

Check whether

curl -x127.0.0.1:80 blog.in-86.com -I

Error: curl returns a code of 200, which proves that
there is no problem with local access, but the browser cannot access ; After adjusting the resolved hostname, you can access it normally.



Browser install Typecho problem again. mysql cannot enter, otherwise it will enter and cannot create a database. The method operation is very simple, as follows:

# /etc/init.d/mysqld stop               //停止MySQL服务的运行
# mysqld_safe --user=mysql --skip-grant-tables --skip-networking & //跳过受权表访问
# mysql -u root mysql                  //登录mysql

The versions below mysql5.7 are as follows:

mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root' and host='127.0.0.1' or host='localhost';    //把空的用户密码都修改成非空的密码就行了。

The mysql5.7 version is as follows:

update mysql.user set authentication_string=password('newpassword') where user='root' and host='127.0.0.1' or host='localhost';
mysql> FLUSH PRIVILEGES;
mysql> quit # /etc/init.d/mysqld restart //离开并重启mysql
# mysql -uroot -p
Enter password: <输入新设的密码newpassword> 

Then you can enter normally

mysql -uroot -p //登录
create database typecho;  //创建数据库
grant all on *.* to [email protected] identified by 'newpassword'; 

Then you can successfully configure and install Typecho

Repeat the installation steps of Typecho to complete the installation of discuz and dedecms (except mysql). The database uses the root password newpassword uniformly

To install discuz, you need to give write permissions to several special directories. After decompressing all the files, I directly execute chmod 755 -R, so this step is omitted (because it is a test, the permissions are not particularly important )

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325072223&siteId=291194637