返回首页

网站LNMP环境安装配置笔记

注:网站系统为CentOS 6.10。

一、准备工作:

1、升级系统

yum update -y

2、清理原有安装

yum remove mysql-libs selinux* postfix http* -y

二、测试服务器LNMP编译安装

1、安装编译工具

yum install gcc cmake gcc-c++ -y

2、安装Nginx

安装依赖

yum install pcre-devel zlib-devel -y
mkdir -p /data/source
cd /data/source
wget https://www.openssl.org/source/openssl-1.0.2t.tar.gz
tar xvf openssl-1.0.2t.tar.gz -C /data/
cd /data/openssl-1.0.2t
./config  --prefix=/data/lib shared --openssldir=/data/lib/openssl
make -j5
make install

建立组和用户并设置不能ssh登录

useradd -U -r -M -s /bin/false www

下载

cd /data/source
wget http://nginx.org/download/nginx-1.17.6.tar.gz

解压

tar xvf nginx-1.17.6.tar.gz

编译

cd nginx-1.17.6
./configure --prefix=/data/nginx --user=www --group=www --with-http_ssl_module --with-http_v2_module --with-stream_realip_module --with-openssl=/data/openssl-1.0.2t --with-http_stub_status_module
make -j5
make install

配置启动

https://www.nginx.com/resources/wiki/start/topics/examples/redhatnginxinit/

sed -i "s/\/\$nginx_version//" /data/nginx/conf/fastcgi*
sed -i "s/}/    application\/vnd.android.package-archive apk;\n}/g" /data/nginx/conf/mime.types
mv /data/nginx/conf/nginx.conf /data/nginx/conf/nginx.conf.bak
mkdir /data/nginx/conf/conf.d

cat > /data/nginx/conf/nginx.conf << "EOF"
user  www;
worker_processes  4;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    charset  utf-8;
    sendfile        on;
    client_max_body_size 40m;
    server_tokens off;
    keepalive_timeout  65;
    gzip  on;
    include  conf.d/*.conf;
}
EOF
cat > /data/nginx/conf/conf.d/www.conf << "EOF"
server {
    listen       80;
    server_name  localhost;
    root   /data/www;
    index  index.html index.htm index.php;

    error_page  404              /404.html;
    error_page   500 502 503 504  /50x.html;

    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ \.php$ {
        try_files $uri = 404;
        fastcgi_pass   127.0.0.1:9000;
        include        fastcgi.conf;
    }
}
EOF
mkdir /data/www
ln -sf /data/nginx/sbin/nginx /usr/local/bin/
sed -i "s/nginx=\"\/usr\/sbin\/nginx\"/nginx=\"\/data\/nginx\/sbin\/nginx\"/g" /etc/init.d/nginx
sed -i "s/NGINX_CONF_FILE=\"\/etc\/nginx\/nginx.conf\"/NGINX_CONF_FILE=\"\/data\/nginx\/conf\/nginx.conf\"/g" /etc/init.d/nginx

打开防火墙

iptables -I INPUT -p tcp --dport 80 -j ACCEPT
service iptables save
service iptables restart

3、安装PHP

安装依赖

yum install libxml2-devel gd-devel libcurl-devel openssl-devel -y

下载

cd /data/sourcewget http://www.php.net/distributions/php-7.3.12.tar.xz

解压

tar xvf php-7.3.12.tar.xz

编译

cd php-7.3.12
./configure --prefix=/data/php --enable-fpm --with-pear --with-fpm-user=www --with-fpm-group=www --with-config-file-path=/data/php --with-config-file-scan-dir=/data/php/lib/php/extensions --enable-opcache --disable-ipv6 --enable-mbstring --with-gettext --with-curl --enable-mysqlnd --with-mysqli --with-pdo-mysql --disable-phpdbg --with-gd --with-freetype-dir --with-png-dir --with-xpm-dir --with-jpeg-dir --with-zlib --enable-calendar --enable-exif --enable-ftp --enable-zip --without-libzip --enable-soap --enable-bcmath --enable-sockets --with-openssl --enable-pcntl
make -j5
make install
#make时出现:PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.
#make install之后,运行以下命令,再次make && make install就可以了
/data/php/bin/pear channel-update pear.php.net
ln -sf /data/php/bin/* /usr/local/bin
ln -sf /data/php/sbin/* /usr/local/bin
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
cp sapi/fpm/www.conf /data/php/etc/php-fpm.d/
cp sapi/fpm/php-fpm.conf /data/php/etc/
echo "zend_extension=opcache.so" > /data/php/lib/php/extensions/opcache.ini
cp php.ini-production /data/php/php.ini
sed -i "s/;opcache.enable=0/opcache.enable=1/" /data/php/php.ini
sed -i "s/;opcache.enable=1/opcache.enable=1/" /data/php/php.ini
sed -i "s/;opcache.enable_cli=0/opcache.enable_cli=1/" /data/php/php.ini
sed -i "s/;opcache.file_cache=/opcache.file_cache=\/tmp/" /data/php/php.ini
sed -i "s/max_execution_time = 30/max_execution_time = 60/" /data/php/php.ini
sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 20M/" /data/php/php.ini
sed -i "s/post_max_size = 8M/post_max_size = 20M/" /data/php/php.ini
sed -i "s/display_errors = Off/display_errors = On/" /data/php/php.ini
sed -i "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/" /data/php/php.ini
sed -i "s/;date.timezone =/date.timezone = Asia\/Shanghai/" /data/php/php.ini
sed -i "s/expose_php = On/expose_php = Off/" /data/php/php.ini
sed -i "s/;request_slowlog_timeout = 0/request_slowlog_timeout = 300/g" /data/php/etc/php-fpm.conf

4、安装MariaDB/Mysql数据库

创建mysql用户

useradd -U -r -M -s /bin/false mysql

安装依赖

yum install ncurses-devel bison -y

下载

wget http://mirrors.ustc.edu.cn/mariadb//mariadb-10.1.43/source/mariadb-10.1.43.tar.gz

解压

tar xvf mariadb-10.1.43.tar.gz

编译

cd mariadb-10.1.43
cmake . \
-DCMAKE_INSTALL_PREFIX=/data/mariadb \
-DMYSQL_DATADIR=/data/mariadb/data \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_SSL=system \
-DCONNECT_WITH_MYSQL=1 \
-DWITH_DEBUG=no \
-DPLUGIN_TOKUDB=NO \
-DWITH_MARIABACKUP=OFF \
-DWITH_UNIT_TESTS=OFF \
-DWITH_UNITTEST=OFF \
-DINSTALL_MYSQLTESTDIR=''

make -j5
make install
ln -sf /data/mariadb/bin/* /usr/local/bin/
chown mysql:mysql /data/mariadb/data -R
cp support-files/my-huge.cnf /data/mariadb/my.cnf
ln -sf /data/mariadb/my.cnf /etc
cp support-files/mysql.server /etc/init.d/mariadb
cd /data/mariadb
scripts/mysql_install_db --user=mysql --defaults-file=/data/mariadb/my.cnf --datadir=/data/mariadb/data/
service mariadb start
/data/mariadb/bin/mysqladmin -u root password 'password'
#更新或重新编译后:
rm -rf /data/mariadb/data/test
service mariadb restart

返回首页

版权所有 © 2016-2019 清风的个人笔记