LNMP 环境搭建(编译安装)

 自学编译操作过程记录篇。

目录

本文示例环境

编译安装PHP

编译安装mysql

编译安装nginx

配置nginx根目录

编译安装Apache

配置php,mysql 为全局命令

配置sshd 开机启动


本文示例环境

Centos7.5

MySQL5.7.24

php 7.1.23

nginx 1.14.1

Apache(未更新)

[root@cui etc]# cat centos-release
CentOS Linux release 7.5.1804 (Core)
[root@work etc]# php -v
PHP 7.1.23 (cli) (built: Nov  8 2018 01:04:13) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies

编译安装PHP

 下载php安装包,完成后会有一个mirror 的文件

wget http://hk1.php.net/get/php-7.1.23.tar.gz/from/this/mirror

 解压下载的文件,完成后会有一个PHP的文件夹

tar -zxvf mirror

 安装部分依赖

yum install gcc gcc++ libxml2-devel

安装 fastcgi 进程管理器【FPM】

首先进入PHP目录,进行 configure 参数设定。

[root@cui php-7.1.23]# ./configure --prefix=/usr/local/php7 --enable-fpm
// 运行完成后执行make编译
[root@cui php-7.1.23]# make
// 不是管理员账户用sudo 安装
[root@cui php-7.1.23]# sudo make install

就安装完成了。 

编译安装mysql

编译参数设定,如需详细了解,请点击编译参数详解深入了解

MySQL 下载地址 版本5.7.24

 

https://dev.mysql.com/downloads/mysql/5.7.html#downloads

 下载 “ Generic Linux (Architecture Independent), Compressed TAR Archive ” 点击右侧 DOWNLOAD

  No thanks, just start my download.

  看到红色字体如上,复制此链接地址。

  进入目录下载。

[root@cui ~]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24.tar.gz

 查看此文件夹 有一个名为 mysql-5.7.24.tar.gz 的tar 包 解出来。

[root@cui ~]# tar -zxvf mysql-5.7.24.tar.gz

  安装部分依赖。

[root@cui ~]# sudo yum install cmake gcc-c++ ncurses-devel perl-Data-Dumper boost boost-doc boost-devel

  进入解压的文件夹,cmake 参数设定

  boost 设定的 文件夹为 /mydata/mysql/data,可以设置为自定义的文件夹

[root@cui mysql-5.7.24]# cmake \

> -DCMAKE_INSTALL_PREFIX=/usr/local/mysql  \

> -DMYSQL_DATADIR=/mydata/mysql/data  \

> -DSYSCONFDIR=/etc  \

> -DMYSQL_USER=mysql \

> -DWITH_MYISAM_STORAGE_ENGINE=1 \

> -DWITH_INNOBASE_STORAGE_ENGINE=1 \

> -DWITH_ARCHIVE_STORAGE_ENGINE=1 \

> -DWITH_MEMORY_STORAGE_ENGINE=1 \

> -DWITH_READLINE=1 \

> -DMYSQL_UNIX_ADDR=/var/run/mysql/mysql.sock \

> -DMYSQL_TCP_PORT=3306 \

> -DENABLED_LOCAL_INFILE=1 \

> -DENABLE_DOWNLOADS=1 \

> -DWITH_PARTITION_STORAGE_ENGINE=1  \

> -DEXTRA_CHARSETS=all \

> -DDEFAULT_CHARSET=utf8 \

> -DDEFAULT_COLLATION=utf8_general_ci \

> -DWITH_DEBUT=0 \

> -DMYSQL_MATNTAINER_MODE=0 \

> -DWITH_SSL:STRING=bundled \

> -DWITH_ZLIB:STARING=bundled \

> -DDOWNLOAD_BOOST=1 \

> -DWITH_BOOST=/mydata/mysql/data # 如果下载超时可以提前将tar包下载至此文件夹

  完成之后,使用make命令进行编译。sudo make install 进行安装

[root@cui mysql-5.7.24]# make
[root@cui mysql-5.7.24]# sudo make install

 编译MySQL完成之后需修改一些配置文件,有可能会执行报错如:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

 配置如下  /etc/my.cnf

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[client]
port=3306
socket=/var/lib/mysql/mysql.sock

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
user = mysql
basedir = /usr/local/mysql
datadir = /var/lib/mysql/data
port=3306
server-id = 1
socket=/var/lib/mysql/mysql.sock

character-set-server = utf8
log-error = /var/lib/mysql/log/error.log
pid-file = /var/lib/mysql/mysql.pid
general_log = 1
skip-name-resolve
#skip-networking
back_log = 300

max_connections = 1000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 128 
max_allowed_packet = 4M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 16M

read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 28M
key_buffer_size = 4M

thread_cache_size = 8

query_cache_type = 1
query_cache_size = 8M
query_cache_limit = 2M

ft_min_word_len = 4

log_bin = mysql-bin
binlog_format = mixed
expire_logs_days = 30


performance_schema = 0
explicit_defaults_for_timestamp

#lower_case_table_names = 1



myisam_sort_buffer_size = 8M
myisam_repair_threads = 1

interactive_timeout = 28800
wait_timeout = 28800


# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M 

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,NO_AUTO_CREATE_USER,STRICT_TRANS_TABLES 

[mysqldump]
quick
max_allowed_packet = 16M

[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M

#[mysqld]
#datadir=/var/lib/mysql
#socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
#symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

#[mysqld_safe]
#log-error=/var/log/mariadb/mariadb.log
#pid-file=/var/run/mariadb/mariadb.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

 创建MySQL数据库文件存放路径 ,创建配置目录/var/lib/mysql/data,配置用户

[root@cui~]# mkdir -p/var/lib/mysql/data && chown -R root:mysql /usr/local/mysql 
[root@cui~]# chown -R mysql:mysql /var/lib/mysql/data 
[root@cui~]# chmod -R go-rwx /var/lib/mysql/data

创建MySQL日志和数据存放目录 ,路径需与 my.cnf 配置保持一致

[root@cui~]# mkdir -p/var/lib/mysql && mkdir -p /var/lib/mysql/log 
[root@cui~]# chown -R mysql:mysql /var/lib/mysql

 初始化MySQL自身的数据库 

# 参数user表示用户,basedir表示mysql的安装路径,datadir表示数据库文件存放路径
# 如果未将mysqld设置为系统命令,注意命令执行目录
[root@cui bin]# pwd
/usr/local/mysql/bin
[root@cui bin]# mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/var/lib/mysql/data

 设置开机启动

# 将mysqld 设定为系统服务
[root@cui ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

#增加可执行权限  
[root@cui ~]# chmod +x /etc/init.d/mysqld 

#添加到sysV服务 
[root@cui ~]# chkconfig --add mysqld 
[root@cui ~]# chkconfig mysqld on

 启动MySQL服务 

[root@cui ~]# mysqld_safe --user=mysql --datadir=/var/lib/mysql/data --log-error=/var/lib/mysql/log/error.log
2018-11-07T23:50:43.327986Z mysqld_safe Logging to '/var/lib/mysql/log/error.log'.
2018-11-07T23:50:43.350001Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql/data
[root@cui ~]# service mysqld start 
Starting MySQL.. SUCCESS! 
[root@cui ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.24-log Source distribution

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql> 

mysql 密码配置 

[root@cui ~]# mysql_secure_installation
Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1
Please set the password for root here.

New password: Test764552..

Re-enter new password: Test764552..
#这里的密码应包含大小写字母、数字、和标点符号,不然可能会不让通过
Estimated strength of the password: 100 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : yy^H
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : n

 ... skipping.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

配置端口3306允许外部访问

# centos 7 中使用的是firewall-cmd命令
[root@cui ~]#  firewall-cmd --list-all-zones    #查看所有的zone信息

[root@cui ~]#  firewall-cmd --get-default-zone     #查看默认zone是哪一个

[root@cui ~]#  firewall-cmd --zone=internal --change-zone=p3p1  #临时修改接口p3p1所属的zone为internal

[root@cui ~]#  firewall-cmd --add-service=http    #暂时开放http 

[root@cui ~]#  firewall-cmd --permanent --add-service=http  #永久开放http 

[root@cui ~]#  firewall-cmd --zone=public --add-port=80/tcp --permanent  #在public中永久开放80端口 

[root@cui ~]#  firewall-cmd --permanent --zone=public --remove-service=ssh   #从public zone中移除服务 

[root@cui ~]#  firewall-cmd --reload   #重新加载配置

# 打开3306端口(因为nginx中已经设置了默认zone public,所以这里可以直接设置,如果没有设置,需要按nginx中那样配置)
[root@cui ~]#  firewall-cmd --add-port=3306/tcp --permanent

[root@cui ~]#  firewall-cmd --reload   #重新加载配置

 至此,配置已基本完成。

Centos7 编译安装MySQL 5.7 期间遇到很多问题,阅读了很多资料,此步骤为最终成功版本。如果未配置成功,亦有可能是其他问题。技术提升的道路要有耐心。

 

编译安装nginx

安装前准备

1.首先检查GCC是否安装:
    
    gcc -v # 显示有相关版本信息,如果未安装执行下面的命令

    yum install -y gcc

2.PCRE库
    # Nginx的HTTP模块要用它来解析正则表达式。

    yum install -y pcre pcre-devel 

    # pcre-devel是使用PCRE做二次开发时所需要的开发库。类似的你可以想到安装LAMP时安装的php-devel。

3.zlib库
    # gzip格式的压缩会用到它。

    yum install -y zlib zlib-devel 

4.OpenSSL库

    yum install -y openssl openssl-devel 

 

打开nginx 官网地址

http://nginx.org/en/download.html

 找到稳定版本的下载地址 ,复制到xshell里进行【下载、解压缩、进入加压后的目录】

[root@cui ~]# wget http://nginx.org/download/nginx-1.14.1.tar.gz
--2018-11-09 12:57:09--  http://nginx.org/download/nginx-1.14.1.tar.gz
正在解析主机 nginx.org (nginx.org)... 95.211.80.227, 206.251.255.63
正在连接 nginx.org (nginx.org)|95.211.80.227|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:1014040 (990K) [application/octet-stream]
正在保存至: “nginx-1.14.1.tar.gz”

100%[==============================================================================================>] 1,014,040    232KB/s 用时 4.4s   

2018-11-09 12:57:14 (226 KB/s) - 已保存 “nginx-1.14.1.tar.gz” [1014040/1014040])

[root@cui ~]# ls
mirror  mysql-5.7.24  mysql-5.7.24.tar.gz  nginx-1.14.1.tar.gz  php-7.1.23

[root@cui ~]# tar -zxvf nginx-1.14.1.tar.gz 
# 完成后进入nginx 解压缩的目录
[root@cui ~]# cd nginx-1.14.1/
[root@cui nginx-1.14.1]# 

 用 configure 命令进行配置,prefix 与之前的安装都类似指的是安装目录。同时安装 pcre

# 命令执行前,提前建立好了 /var/log/nginx

[root@cui nginx-1.14.1]# ./configure --prefix=/usr/local/nginx --pid-path=/run/nginx.pid  --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log  --with-http_ssl_module --with-http_v2_module --with-http_stub_status_module --with-pcre
[root@cui nginx-1.14.1]# make
[root@cui nginx-1.14.1]# make install

 进入目录 /usr/local/nginx/sbin  执行命令启动nginx

[root@cui sbin]# pwd
/usr/local/nginx/sbin
[root@cui sbin]# ./nginx

 此时输入该操作系统(服务器/虚拟机)的 IP,即可得到 nginx 安装成功的界面

 后面还需要配置php-fpm ,是php和nginx 之间 通讯的解释器。

如果直接执行php-fpm 会报错,安装完成以后还没有配置php-fpm.conf

[root@cui ~]# cd /usr/local/php7/sbin/
[root@cui sbin]# ls
php-fpm
[root@cui sbin]# ./php-fpm 
[09-Nov-2018 13:17:33] ERROR: failed to open configuration file '/usr/local/php7/etc/php-fpm.conf': No such file or directory (2)
[09-Nov-2018 13:17:33] ERROR: failed to load configuration file '/usr/local/php7/etc/php-fpm.conf'
[09-Nov-2018 13:17:33] ERROR: FPM initialization failed

# 查看配置目录
[root@cui sbin]# ls /usr/local/php7/etc/
pear.conf  php-fpm.conf.default  php-fpm.d

# 进入配置目录
[root@cui sbin]# cd ../etc/
# 复制默认配置文件
[root@cui etc]# cp php-fpm.conf.default php-fpm.conf
[root@cui etc]# ls
pear.conf  php-fpm.conf  php-fpm.conf.default  php-fpm.d
[root@cui etc]# 

 重新启动php-fpm,错误提示是,/usr/local/php7/etc/php-fpm.d/ 目录下没有匹配的 以conf 后缀结尾的文件。

[root@cui etc]# ../sbin/php-fpm 
[09-Nov-2018 13:22:58] WARNING: Nothing matches the include pattern '/usr/local/php7/etc/php-fpm.d/*.conf' from /usr/local/php7/etc/php-fpm.conf at line 125.
[09-Nov-2018 13:22:58] ERROR: No pool defined. at least one pool section must be specified in config file
[09-Nov-2018 13:22:58] ERROR: failed to post process the configuration
[09-Nov-2018 13:22:58] ERROR: FPM initialization failed
# 打开目录 /usr/local/php7/etc/php-fpm.d/
[root@cui etc]# cd php-fpm.d/
[root@cui php-fpm.d]# ls
www.conf.default
# 复制一份配置文件使用
[root@cui php-fpm.d]# cp www.conf.default  www.conf
[root@cui php-fpm.d]# 

 重新启动php-fpm ,查看php-fpm 进程

[root@cui php-fpm.d]# cd ../../sbin/
[root@cui sbin]# ./php-fpm 
# 查看php-fpm 进程
[root@cui sbin]# ps aux | grep php-fpm 
root      23174  0.0  0.0 148768  4632 ?        Ss   13:28   0:00 php-fpm: master process (/usr/local/php7/etc/php-fpm.conf)
nobody    23175  0.0  0.0 150852  4544 ?        S    13:28   0:00 php-fpm: pool www
nobody    23176  0.0  0.0 150852  4544 ?        S    13:28   0:00 php-fpm: pool www
root      23180  0.0  0.0 112720   984 pts/1    S+   13:28   0:00 grep --color=auto php-fpm
[root@cui sbin]# 

 php-fpm 启动成功后需要配置 nginx,比较重要的一部分。

[root@cui sbin]# cd /usr/local/nginx/conf/
[root@cui conf]# ll
总用量 68
-rw-r--r--. 1 root root 1077 11月  9 13:59 fastcgi.conf
-rw-r--r--. 1 root root 1077 11月  9 13:59 fastcgi.conf.default
-rw-r--r--. 1 root root 1007 11月  9 13:59 fastcgi_params
-rw-r--r--. 1 root root 1007 11月  9 13:59 fastcgi_params.default
-rw-r--r--. 1 root root 2837 11月  9 13:59 koi-utf
-rw-r--r--. 1 root root 2223 11月  9 13:59 koi-win
-rw-r--r--. 1 root root 5170 11月  9 13:59 mime.types
-rw-r--r--. 1 root root 5170 11月  9 13:59 mime.types.default
-rw-r--r--. 1 root root 2656 11月  9 13:59 nginx.conf
-rw-r--r--. 1 root root 2656 11月  9 13:59 nginx.conf.default
-rw-r--r--. 1 root root  636 11月  9 13:59 scgi_params
-rw-r--r--. 1 root root  636 11月  9 13:59 scgi_params.default
-rw-r--r--. 1 root root  664 11月  9 13:59 uwsgi_params
-rw-r--r--. 1 root root  664 11月  9 13:59 uwsgi_params.default
-rw-r--r--. 1 root root 3610 11月  9 13:59 win-utf
[root@cui conf]# vim nginx.conf

 增加配置根目录php 的配置

# user  www;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;
        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }
        # 增加部分 开始
        location ~ \.php$
        {
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_split_path_info ^(.+?\.php)(/.*)$;     
                fastcgi_param PATH_INFO $fastcgi_path_info;    
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include        fastcgi_params;
        }
        # 增加部分 结束
        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

 测试一个php文件,httt.php

[root@cui conf]# /usr/local/nginx/sbin/nginx -s stop
[root@cui conf]# /usr/local/nginx/sbin/nginx
[root@cui conf]# cd ../html/
[root@cui html]# ls
50x.html  httt.php  index.html
[root@cui html]# 

 

 示例效果:

 如果配置不成功有可能是端口的问题

# 打开端口 --permanent永久生效,没有此参数重启后失效

firewall-cmd --zone=public --add-port=80/tcp --permanent

# 重新载入

firewall-cmd --reload

配置nginx根目录

 配置一次其他开发目录的项目测试

 创建 vhosts 文件夹

# 编辑 nginx.conf
http{
    
    ...

    include vhosts/*.conf;
}

 增加测试conf配置文件

[root@cui vhosts]# pwd
/usr/local/nginx/conf/vhosts
[root@cui vhosts]# vim first.conf

    server {
        listen       80;
        server_name  localtest.com;

        location / {
            root   /home/wwwroot/test/;
            index  index.html index.htm;
        }
        location ~ \.php$
        {
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_split_path_info ^(.+?\.php)(/.*)$;     
                fastcgi_param PATH_INFO $fastcgi_path_info;    
                # fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                fastcgi_param  SCRIPT_FILENAME  /home/wwwroot/test$fastcgi_script_name;
                include        fastcgi_params;
        }
        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

    }

[root@cui vhosts]# cd /home/wwwroot/test/
[root@cui test]# ls
index.html  test.php
[root@work test]# 

如果要执行根目录下的php文件测试,需要将目录配置$document_root改成指定目录

fastcgi_param  SCRIPT_FILENAME  /home/wwwroot/test$fastcgi_script_name;

 

下图为配置后的两个文件的展示效果:

localtest.com 该处自动执行的 index.html

localtest.com/test.php

我本地测试时是虚拟机,如果虚拟机配合本地需要在 hosts 文件里设置好 【本地域名】 对应 【本地虚拟机IP】。

如果是在线上服务器,是不需要hosts 文件配置的。上面图中显示的 172 的IP 也是本地的虚拟机的IP。

 未将nginx 设置为系统服务或系统命令时使用:

/usr/local/nginx/sbin/nginx           #默认启动方式 start
/usr/local/nginx/sbin/nginx -t        #测试配置信息
/usr/local/nginx/sbin/nginx -v        #显示版本信息,-V(大V)显示编译时的参数
/usr/local/nginx/sbin/nginx -s stop  #快速停止服务
/usr/local/nginx/sbin/nginx -s quit   #正常停止服务
/usr/local/nginx/sbin/nginx -s reload                            #重启

 

nginx配置成服务及开机自启

#! /bin/bash
# chkconfig: - 85 15
PATH=/usr/local/nginx
DESC="nginx daemon"
NAME=nginx
DAEMON=$PATH/sbin/$NAME
CONFIGFILE=$PATH/conf/$NAME.conf
PIDFILE=$PATH/logs/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
set -e
[ -x "$DAEMON" ] || exit 0
do_start() {
$DAEMON -c $CONFIGFILE || echo -n "nginx already running"
}
do_stop() {
$DAEMON -s stop || echo -n "nginx not running"
}
do_reload() {
$DAEMON -s reload || echo -n "nginx can't reload"
}
case "$1" in
start)
echo -n "Starting $DESC: $NAME"
do_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
do_stop
echo "."
;;
reload|graceful)
echo -n "Reloading $DESC configuration..."
do_reload
echo "."
;;
restart)
echo -n "Restarting $DESC: $NAME"
do_stop
do_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2
exit 3
;;
esac
exit 0

 nginx 文件如上代码书写。

[root@cui test]# cd /etc/init.d/
[root@cui init.d]# vim nginx
[root@cui init.d]# ls
functions  mysqld  netconsole  network  nginx  php-fpm  README
# 可执行权限
[root@cui init.d]# chmod a+x nginx 
# 添加为服务
[root@cui init.d]# chkconfig --add nginx 
# 开机自启
[root@cui init.d]# chkconfig nginx on 
[root@cui init.d]# 

编译安装Apache

配置php,mysql 为全局命令

[root@cui ~]# vim .bash_profile

 设置命令的路径。

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/mysql/bin:/usr/local/php7/bin

export PATH

 

 

配置sshd 开机启动

yum 安装sshd 较简单未做详细记录。

sshd安装完成后可以使用xshell登录操作。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值