1. 程式人生 > >LNMP 環境搭建(編譯安裝)

LNMP 環境搭建(編譯安裝)

 自學編譯操作過程記錄篇。

目錄

本文示例環境

Centos7.5

MySQL5.7.24

php 7.1.23

nginx 1.14.1

Apache(未更新)

[[email protected] etc]# cat centos-release
CentOS Linux release 7.5.1804 (Core)
[[email protected] 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 引數設定。

[[email protected] php-7.1.23]# ./configure --prefix=/usr/local/php7 --enable-fpm
// 執行完成後執行make編譯
[
[email protected]
php-7.1.23]# make // 不是管理員賬戶用sudo 安裝 [[email protected] 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

  看到紅色字型如上,複製此連結地址。

  進入目錄下載。

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

 檢視此資料夾 有一個名為 mysql-5.7.24.tar.gz 的tar 包 解出來。

[[email protected] ~]# tar -zxvf mysql-5.7.24.tar.gz

  安裝部分依賴。

[[email protected] ~]# sudo yum install cmake gcc-c++ ncurses-devel perl-Data-Dumper boost boost-doc boost-devel

  進入解壓的資料夾,cmake 引數設定

  boost 設定的 資料夾為 /mydata/mysql/data,可以設定為自定義的資料夾

[[email protected] 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 進行安裝

[[email protected] mysql-5.7.24]# make
[[email protected] 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,配置使用者

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

建立MySQL日誌和資料存放目錄 ,路徑需與 my.cnf 配置保持一致

[[email protected]~]# mkdir -p/var/lib/mysql && mkdir -p /var/lib/mysql/log 
[[email protected]~]# chown -R mysql:mysql /var/lib/mysql

 初始化MySQL自身的資料庫 

# 引數user表示使用者,basedir表示mysql的安裝路徑,datadir表示資料庫檔案存放路徑
# 如果未將mysqld設定為系統命令,注意命令執行目錄
[[email protected] bin]# pwd
/usr/local/mysql/bin
[[email protected] bin]# mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/var/lib/mysql/data

 設定開機啟動

# 將mysqld 設定為系統服務
[[email protected] ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

#增加可執行許可權  
[[email protected] ~]# chmod +x /etc/init.d/mysqld 

#新增到sysV服務 
[[email protected] ~]# chkconfig --add mysqld 
[[email protected] ~]# chkconfig mysqld on

 啟動MySQL服務 

[[email protected] ~]# 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
[[email protected] ~]# service mysqld start 
Starting MySQL.. SUCCESS! 
[[email protected] ~]# 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 密碼配置 

[[email protected] ~]# 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命令
[[email protected] ~]#  firewall-cmd --list-all-zones    #檢視所有的zone資訊

[[email protected] ~]#  firewall-cmd --get-default-zone     #檢視預設zone是哪一個

[[email protected] ~]#  firewall-cmd --zone=internal --change-zone=p3p1  #臨時修改介面p3p1所屬的zone為internal

[[email protected] ~]#  firewall-cmd --add-service=http    #暫時開放http 

[[email protected] ~]#  firewall-cmd --permanent --add-service=http  #永久開放http 

[[email protected] ~]#  firewall-cmd --zone=public --add-port=80/tcp --permanent  #在public中永久開放80埠 

[[email protected] ~]#  firewall-cmd --permanent --zone=public --remove-service=ssh   #從public zone中移除服務 

[[email protected] ~]#  firewall-cmd --reload   #重新載入配置

# 開啟3306埠(因為nginx中已經設定了預設zone public,所以這裡可以直接設定,如果沒有設定,需要按nginx中那樣配置)
[[email protected] ~]#  firewall-cmd --add-port=3306/tcp --permanent

[[email protected] ~]#  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裡進行【下載、解壓縮、進入加壓後的目錄】

[[email protected] ~]# 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])

[[email protected] ~]# ls
mirror  mysql-5.7.24  mysql-5.7.24.tar.gz  nginx-1.14.1.tar.gz  php-7.1.23

[[email protected] ~]# tar -zxvf nginx-1.14.1.tar.gz 
# 完成後進入nginx 解壓縮的目錄
[[email protected] ~]# cd nginx-1.14.1/
[[email protected] nginx-1.14.1]# 

 用 configure 命令進行配置,prefix 與之前的安裝都類似指的是安裝目錄。同時安裝 pcre

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

[[email protected] 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
[[email protected] nginx-1.14.1]# make
[[email protected] nginx-1.14.1]# make install

 進入目錄 /usr/local/nginx/sbin  執行命令啟動nginx

[[email protected] sbin]# pwd
/usr/local/nginx/sbin
[[email protected] sbin]# ./nginx

 此時輸入該作業系統(伺服器/虛擬機器)的 IP,即可得到 nginx 安裝成功的介面

 後面還需要配置php-fpm ,是php和nginx 之間 通訊的直譯器。

如果直接執行php-fpm 會報錯,安裝完成以後還沒有配置php-fpm.conf

[[email protected] ~]# cd /usr/local/php7/sbin/
[[email protected] sbin]# ls
php-fpm
[[email protected] 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

# 檢視配置目錄
[[email protected] sbin]# ls /usr/local/php7/etc/
pear.conf  php-fpm.conf.default  php-fpm.d

# 進入配置目錄
[[email protected] sbin]# cd ../etc/
# 複製預設配置檔案
[[email protected] etc]# cp php-fpm.conf.default php-fpm.conf
[[email protected] etc]# ls
pear.conf  php-fpm.conf  php-fpm.conf.default  php-fpm.d
[[email protected] etc]# 

 重新啟動php-fpm,錯誤提示是,/usr/local/php7/etc/php-fpm.d/ 目錄下沒有匹配的 以conf 字尾結尾的檔案。

[[email protected] 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/
[[email protected] etc]# cd php-fpm.d/
[[email protected] php-fpm.d]# ls
www.conf.default
# 複製一份配置檔案使用
[[email protected] php-fpm.d]# cp www.conf.default  www.conf
[[email protected] php-fpm.d]# 

 重新啟動php-fpm ,檢視php-fpm 程序

[[email protected] php-fpm.d]# cd ../../sbin/
[[email protected] sbin]# ./php-fpm 
# 檢視php-fpm 程序
[[email protected] 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
[[email protected] sbin]# 

 php-fpm 啟動成功後需要配置 nginx,比較重要的一部分。

[[email protected] sbin]# cd /usr/local/nginx/conf/
[[email protected] 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
[[email protected] 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

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

 示例效果:

 如果配置不成功有可能是埠的問題

# 開啟埠 --permanent永久生效,沒有此引數重啟後失效

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

# 重新載入

firewall-cmd --reload

配置nginx根目錄

 配置一次其他開發目錄的專案測試

 建立 vhosts 資料夾

# 編輯 nginx.conf
http{
    
    ...

    include vhosts/*.conf;
}

 增加測試conf配置檔案

[[email protected] vhosts]# pwd
/usr/local/nginx/conf/vhosts
[[email protected] 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;
        }

    }

[[email protected] vhosts]# cd /home/wwwroot/test/
[[email protected] test]# ls
index.html  test.php
[[email protected] 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 檔案如上程式碼書寫。

[[email protected] test]# cd /etc/init.d/
[[email protected] init.d]# vim nginx
[[email protected] init.d]# ls
functions  mysqld  netconsole  network  nginx  php-fpm  README
# 可執行許可權
[[email protected] init.d]# chmod a+x nginx 
# 新增為服務
[[email protected] init.d]# chkconfig --add nginx 
# 開機自啟
[[email protected] init.d]# chkconfig nginx on 
[[email protected] init.d]# 

編譯安裝Apache

配置php,mysql 為全域性命令

[[email protected] ~]# 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登入操作。

相關推薦

LNMP 環境搭建(編譯安裝)

 自學編譯操作過程記錄篇。 目錄 本文示例環境 Centos7.5 MySQL5.7.24 php 7.1.23 nginx 1.14.1 Apache(未更新) [[email protected] etc]# ca

lnmp環境編譯安裝swoole擴充套件

  我這裡用的是下載壓縮包,編譯安裝的方式,php官方還提供了pecl命令,可以一鍵安裝swoole  lnmp版本用的是1.4,php用的5.538,  cd /usr/local/src/ wget http://pecl.php.net/get/swoole-1.9.

linux-一篇文章完成lnmp環境編譯安裝

lnmp環境搭建 前置條件 作業系統安裝:CentOS 6.8 64位最小化安裝。 配置好IP、DNS、閘道器、主機名 配置防火牆,開啟80、3306埠 關閉訪問牆 service iptables stop /etc/init.d/ipta

LNMP環境搭建之php安裝

LNMP php安裝 和LAMP安裝PHP方法有差別,需要開啟php-fpm服務 下載php cd /usr/local/src/ wget http://cn2.php.net/distributions/php-5.6.30.tar.gz 解壓源碼包 tar zxf php-5.6.30.t

LNMP環境搭建之nginx安裝

LNMP nginx 下載nginx cd /usr/local/src wget http://nginx.org/download/nginx-1.12.1.tar.gz 解壓 tar zxf nginx-1.12.1.tar.gz 編譯 ./configure --prefix=/usr

Linux學習總結(三十九)lnmp環境搭建1-mysql,php 安裝

lnmp mysql php php-fpm 之前我們介紹過lamp,lnmp和lamp相比就是把apache換為了nginx,nginx也是目前比較流行的一款web server,在處理高並發請求上,性能要遠勝於apache。apache將php作為一個自己的一個擴展模塊來使用,nginx則

LNMP環境搭建:Nginx安裝、測試與域名配置

Nginx作為一款優秀的Web Server軟體同時也是一款優秀的負載均衡或前端反向代理、快取服務軟體   2.編譯安裝Nginx   (1)安裝Nginx依賴函式庫pcre     pcre為“perl相容正則表示式”perl compatible regu

保姆級教程——Ubuntu16.04 Server下深度學習環境搭建安裝CUDA8.0,cuDNN6.0,Bazel0.5.4,原始碼編譯安裝TensorFlow1.4.0(GPU版)

寫在前面 本文敘述了在Ubuntu16.04 Server下安裝CUDA8.0,cuDNN6.0以及原始碼編譯安裝TensorFlow1.4.0(GPU版)的親身經歷,包括遇到的問題及解決辦法,也有一些自己的經驗,希望能對讀者有所幫助。期間參考了許多前人的文章,後文會一一附上鍊接,在此先行謝過。在下能力有限,

Windows 搭建msys2+mingw32開發環境編譯安裝vlc

官網的幫助文件:Win32CompileMSYS 介紹 這個就不說了 安裝Windows工具 我使用了nodepad++和winrar,設定如下: 顯示行尾符:檢視->顯示符號->顯示行尾符 設定為unix行尾符:編輯->

LNMP環境搭建與wordpress的安裝

剛開始一直在嘗試自己原始碼一步一步搭建LNMP環境,但是不知道為什麼,在php與nginx互動上一直出錯,前前後後也解決了好多個問題,最終訪問localhost時,出現的還是welcome to nginx 的畫面,雖然安裝環境用了三四天,也遇到了很多問題,所以在這裡向大家

lnmp環境搭建完全手冊(四)——lnmp搭建(原始碼安裝)

首先來介紹一下Nginx.Nginx是一個高效能的 HTTP 和 反向代理 伺服器,也是一個 IMAP/POP3/SMTP 代理伺服器。Nginx不僅可以作為web伺服器,也可以作為負載均衡器,之前也有文章介紹,大家可以看一下. MySQL是一款開源免費的資料軟體,My

LNMP環境搭建

linux 電子 代理服務器 master 區分大小寫 Nginx是一款輕量的異步Web 服務器/反向代理服務器及電子郵件(IMAP/POP3)代理服務器。Nginx的處理連接方式與apache的模式類似,nginx通過主進程master產生多個子進程worker,然後每個worker產生

CentOS7 LNMP+phpmyadmin環境搭建(二、LNMP環境搭建

用戶 lib 關聯 cin 特殊 get deb 分號 yum 上一篇博客我們在虛擬機上安裝了centos7,接下來,就開始安裝lnmp環境吧。 還是跟之前一樣,進入命令行後,先使用su命令切換到root權限。 首先配置防火墻 CentOS 7.0默認使用的是firewa

CentOs lnmp環境搭建wordpress博客

自動化運維之路--環境lnmp搭建LNMP代表的就是:Linux系統下Nginx+MySQL+PHP這種網站服務器架構。Linux是一類Unix計算機操作系統的統稱,是目前最流行的免費操作系統。Nginx是一個高性能的HTTP和反向代理服務器,也是一個IMAP/POP3/SMTP代理服務器。Mysql是一個小

linux環境手動編譯安裝Nginx實踐過程 附異常解決

ima 根據 目錄結構 key -a text 參數 文件中 修改 1、下載nginx源碼包並解壓      可在http://nginx.org/en/download.html下載.tar.gz的源碼包,如(nginx-1.4.7.tar.gz) 或者使用雲盤下載

超詳細LAMP環境手動編譯安裝實例

ring develop 最新版 $path 成功 prefix profile you 手動 LAMP編譯安裝實例: HTTPD編譯安裝: 下載軟件包: # wget http://mirrors.hust.edu.cn/apache//apr/apr-

centos下配置LNMP環境(源碼安裝)

hid strong 配置 依賴 post png div libjpeg curses 準備工作,安裝依賴庫 yum -y install gcc automake autoconf libtool make gcc-c++ glibc libxslt-devel l

Linux-LNMP環境搭建

Linux-LNMP環境搭建安裝mysql# cd /usr/local/src/ # wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz # tar -zxvf mysql-5.

flask系列一之環境搭建安裝

例如 rap name get 命令 關於 通過 HR pre 一,python的安裝 (1)python的安裝 (2)虛擬環境的配置 參考:http://www.cnblogs.com/bfwbfw/p/7995245.html 1,虛擬環境的建立 (1)使用pip安裝虛

LNMP環境搭建(CentOS7+Nginx1.10.1+MySQL5.6.31+PHP5.6.22)

編譯 efault libraries src inux object 根目錄 service gef 零、準備工作 安裝wget:yum install wget -y 安裝gcc及g++:yum install gcc gcc-c++ -y 後續所有源代碼都下載到/us