PHP完整環境搭建


Linux(CentOS 7)+ Nginx(1.10.2)+ Mysql(5.7.16)+ PHP(7.0.12)

首先安裝Linux系統,我以虛擬機安裝來做示例,先去下載 VitualBox,這是一款開源的虛擬機軟件,https://www.virtualbox.org 官網地址。或者是VMware,www.vmware.com,不過這個軟件是收費的。當然同時還要去下載一個Linux鏡像,我下載是CentOS 7系統,https://www.centos.org/download

下載好了之后打開虛擬機,我用的是VMware,選擇創建自定義虛擬機:

 

繼續下一步:

 

點擊完成。

看到這個界面后,點擊CD/DVD(IDE):

點擊選擇光盤鏡像,把下載好的Centos 7 系統放進去:

 

接着回到上個頁面,點擊啟動磁盤:

 

 選擇CD/DVD,然后點擊重新啟動:

 可以看到已經載入鏡像文件,選擇第一個安裝:

 

選擇語言,繼續,

 

 這玩意得先點進去,然后保存下,

要上網的同志不要忘記開啟網絡了:

這個時候就開始安裝了,安裝的同時把root密碼和用戶賬號密碼設置下:

 

 設置完成后,我們就可以耐心的等待了……

OK,重啟系統,登錄root賬戶,也可以登錄你自己設置好的用戶賬戶,是不是很酷炫。

先看下網絡有沒有問題,輸入ping www.baidu.com,看到網絡可以正常訪問:

如果不能正常訪問網絡,修改ifcfg文件,把ONBOOT="no" 改為 "yes",保存即可。

 

[root@172 ~]# vi /etc/sysconfig/network-scripts/ifcfg-eno16777736 

 

 

重啟下網絡:

systemctl restart network.service

查看ip地址,輸入ip addr,紅色部分可以直接在瀏覽器里訪問到,如下圖:

 

 

ok,沒有問題,接下來你就可以安裝各種軟件了……當然,我們先做正事,開始安裝PHP,先去PHP官網上下載壓縮包:

選擇一個版本,然后復制鏈接地址,在命令行輸入:

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

提示找不到wget命令,先下載wget:

yum install wget

安裝完成后在執行:

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

看到已經下載好到目錄下了:

接下來再解壓,輸入:

tar -zxvf mirror

解壓好后再進入到 http://php.net/manual/zh/install.fpm.php 來安裝php-fpm,因為現在的php還不能和nginx一起工作,只能和Apache工作,php-fpm是nginx和php的一個橋梁,所以

 我們繼續安裝php-fpm。

先安裝需要的編譯工具 gcc,gcc++,libxml2-devel:

yum install gcc gcc-c++ libxml2-devel

進入到php目錄下進行編譯和安裝:

復制代碼
cd php-7.0.12/  //進入php目錄下
./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7 --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config  --with-pdo-mysql=/usr/local/mysql --enable-fpm --enable-libxml   //這里選擇要安裝的php目錄,后面參數是開啟php-fpm,支持mysql等
make   //進行編譯
make install  //進行安裝
復制代碼

安裝完成后進入到安裝目錄下:

cd /usr/local/php7/lib/php

php安裝完成。

mysql的安裝

首先創建一個名為mysql且沒有登錄權限的用戶和一個名為mysql的用戶組:

groupadd -r mysql && useradd -r -g mysql -s /bin/false -M mysql
wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.16.tar.gz

安裝mysql需要的編譯工具:

yum -y install cmake gcc-c++ ncurses-devel perl-Data-Dumper boost boost-doc boost-devel

進入到mysql目錄下進行編譯和安裝:

復制代碼
cd /mysql-5.7.16
cmake -DCMAKE_STALL_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_BLACKHOLE_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 -DENABLED_DOWNLOADS=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8  -DDEFAULT_COLLATION=utf8_general_ci -DWITH_DEBUG=0 -DMYSQL_MAINTAINER_MODE=0 -DWITH_SSL:STRING=bundled -DWITH_ZLIB:STRING=bundled 
復制代碼

 

 執行上面的配置命令的結果如下圖所示:

 

 

測試發現編譯MySQL5.7以及更高的版本時,都需要下載並引用或者直接安裝boost庫,否則在執行cmake命令時會報如下錯誤:

 

復制代碼
-- Running cmake version 2.8.11
-- Configuring with MAX_INDEXES = 64U
-- SIZEOF_VOIDP 8
-- MySQL 5.7.16          [MySQL版本]
-- Packaging as: mysql-5.7.16-Linux-x86_64
-- Looked for boost/version.hpp in  and 
-- BOOST_INCLUDE_DIR BOOST_INCLUDE_DIR-NOTFOUND
-- LOCAL_BOOST_DIR 
-- LOCAL_BOOST_ZIP 
-- Could not find (the correct version of) boost.       [關鍵錯誤信息]
-- MySQL currently requires boost_1_59_0                    [解決辦法]

CMake Error at cmake/boost.cmake:76 (MESSAGE):          [具體錯誤和解決方法]
  You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=<directory>

  This CMake script will look for boost in <directory>.  If it is not there,
  it will download and unpack it (in that directory) for you.

  If you are inside a firewall, you may need to use an http proxy:

  export http_proxy=http://example.com:80

Call Stack (most recent call first):
  cmake/boost.cmake:228 (COULD_NOT_FIND_BOOST)
  CMakeLists.txt:452 (INCLUDE)


-- Configuring incomplete, errors occurred!
See also "/mydata/mysql-5.7.16/CMakeFiles/CMakeOutput.log".
復制代碼

只要將http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz下載下來,上傳到/usr/local/boost,在執行命令:

cmake -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost
編譯和安裝:
make && make install

 

 查看編譯成功后的MySQL安裝目錄:

使用cd命令查看MySQL的安裝目錄/usr/local/mysql/下面是否生成了相關目錄文件(最重要的當然是bin、sbin和lib目錄)。如果lib目錄下面沒有生成如圖所示的.so動態庫文件和.a靜態庫文件,那么說明安裝不成功,需要重新編譯安裝。(即使成功了也可能會導致php進程無法找到mysql的相關庫文件)。

然后把編譯生成的my.cnf文件備份:

cp /etc/my.cnf /etc/my.cnf.bak

再修改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/run/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 = /mydata/mysql/data
port=3306
server-id = 1
socket=/var/run/mysql/mysql.sock

character-set-server = utf8
log-error = /var/log/mysql/error.log
pid-file = /var/log/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
復制代碼

將MySQL編譯生成的bin目錄添加到當前Linux系統的環境變量中:

echo -e '\n\nexport PATH=/usr/local/mysql/bin:$PATH\n' >> /etc/profile && source /etc/profile
創建MySQL數據庫文件的存放路徑以及相關安全配置

在Linux主機上創建一個目錄/mydata/mysql/data,用於存放MySQL的數據庫文件。同時設置其用戶和用戶組為之前創建的mysql,權限為777。這樣其它用戶是無法進行讀寫的,盡量保證數據庫的安全。

mkdir -p /mydata/mysql/data && chown -R root:mysql /usr/local/mysql
chown -R mysql:mysql /mydata/mysql/data
chmod -R go-rwx /mydata/mysql/data
初始化MySQL自身的數據庫

在MySQL安裝目錄的\bin\路徑下,執行mysqld命令,初始化MySQL自身的數據庫。

cd /usr/local/mysql/bin
mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/mydata/mysql/data

執行完后,通過 ls -lrt /mydata/mysql/data/ 命令查看是否生成了MySQL自身的數據庫文件。

創建MySQL日志存放目錄以及設置開機啟動

下面配置的MySQL日志存放目錄以及權限都是根據前面my.cnf文件寫的,也就是兩者需要保持一致。

 
復制代碼
mkdir -p /var/run/mysql && mkdir -p /var/log/mysql
chown -R mysql:mysql /var/log/mysql && chown -R mysql:mysql /var/run/mysql        #配置開機自啟動
cp /usr/local/mysql/support-files/mysql.server  /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld     #增加可執行權限
chkconfig --add mysqld      #添加到sysV服務
chkconfig mysqld on
復制代碼

在完成上面的操作后,就可以正式使用MySQL服務了。啟動MySQL進程服務的命令如下:

復制代碼
[root@172 ~]# mysqld_safe --user=mysql --datadir=/mydata/mysql/data --log-error=/var/log/mysql/error.log &
[1] 19077
[root@172 ~]# 2016-10-23T04:21:19.530315Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2016-10-23T04:21:19.563588Z mysqld_safe Starting mysqld daemon with databases from /mydata/mysql/data

######上面這條命令會在后台繼續執行,所以直接回車並執行下面這條命令
[root@172 ~]# service mysqld start
Starting MySQL SUCCESS! 
復制代碼

使用 ps -ef | grep mysql 查看MYSQL服務端進程和端口監聽情況:

復制代碼
[root@172 ~]# ps -ef | grep mysql
root      19077  18966  0 12:21 pts/0    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --user=mysql --datadir=/mydata/mysql/data --log-error=/var/log/mysql/error.log
mysql     19685  19077  0 12:21 pts/0    00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/mydata/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/log/mysql/error.log --open-files-limit=65535 --pid-file=/var/log/mysql/mysql.pid --socket=/var/run/mysql/mysql.sock --port=3306
root      20318  18966  0 12:22 pts/0    00:00:00 grep --color=auto mysql
復制代碼
初始化MySQL數據庫的root用戶密碼

和Oracle數據庫一樣,MySQL數據庫也默認自帶了一個root用戶(這個和當前Linux主機上的root用戶是完全不搭邊的),我們在設置好MySQL數據庫的安全配置后初始化root用戶的密碼。配置過程中,一路輸入y就行了。這里只說明下MySQL5.7.16版本中,用戶密碼策略分成低級LOW、中等MEDIUM和超強STRONG三種,推薦使用中等MEDIUM級別!

復制代碼
[root@172 ~]# 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         【只需要長度大於或等於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: y
復制代碼
將MySQL數據庫的動態鏈接庫共享至系統鏈接庫

一般MySQL數據庫還會被類似於PHP等服務調用,所以我們需要將MySQL編譯后的lib庫文件添加至當前Linux主機鏈接庫/etc/ld.so.conf.d/下,這樣MySQL服務就可以被其它服務調用了。

復制代碼
[root@172 ~]# echo "/usr/local/mysql/lib" > /etc/ld.so.conf.d/mysql.conf
[root@172 ~]# ldconfig
[root@172 ~]# ldconfig -v |grep mysql
ldconfig: 無法對 /libx32 進行 stat 操作: 沒有那個文件或目錄
ldconfig: 多次給出路徑“/usr/lib”
ldconfig: 多次給出路徑“/usr/lib64”
ldconfig: 無法對 /usr/libx32 進行 stat 操作: 沒有那個文件或目錄
/usr/local/mysql/lib:
    libmysqlclient.so.20 -> libmysqlclient.so.20.3.3
復制代碼
創建其它MySQL數據庫用戶

使用MySQL數據庫root管理員用戶登錄MySQL數據庫后,可以管理數據庫和其他用戶了。這里演示創建一個名為evai的MySQL用戶(密碼為@Typeusers2016.com)和一個名為typeusers的數據庫。

復制代碼
[root@172 ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 5.7.16-log Source distribution

Copyright (c) 2000, 2016, 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.
######登錄成功后,創建typecodes數據庫,並設置字符集
mysql> CREATE DATABASE `typeusers` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; Query OK, 1 row affected (0.01 sec)
######創建名為typecodes用戶,並讓它擁有typecodes數據庫所有的權限
mysql> grant all privileges on typeusers.* to evai@localhost identified by '@Typeusers2016.com'; Query OK, 0 rows affected, 2 warnings (0.01 sec)

  mysql> exit

  Bye

復制代碼

ok,退出,然后用剛創建的用戶登錄到mysql:

復制代碼
[root@172 ~]# mysql -uevai -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 17
Server version: 5.7.16-log Source distribution

Copyright (c) 2000, 2016, 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> 
復制代碼

 

安裝nginx

去官網 http://nginx.org 下載最新的穩定版本,復制鏈接:

 

下載並解壓:

復制代碼
[root@172 ~]# wget http://nginx.org/download/nginx-1.10.2.tar.gz
--2016-10-23 13:22:15--  http://nginx.org/download/nginx-1.10.2.tar.gz
正在解析主機 nginx.org (nginx.org)... 206.251.255.63, 95.211.80.227, 95.211.80.227
正在連接 nginx.org (nginx.org)|206.251.255.63|:80... 已連接。
已發出 HTTP 請求,正在等待回應... 200 OK
長度:910812 (889K) [application/octet-stream]
正在保存至: “nginx-1.10.2.tar.gz”

100%[=================================================>] 910,812     43.0KB/s 用時 18s    

2016-10-23 13:22:35 (49.4 KB/s) - 已保存 “nginx-1.10.2.tar.gz” [910812/910812])

 [root@172 ~]# tar -zxvf nginx-1.10.2.tar.gz     #解壓

復制代碼

在下載一個叫pcre的東東,PCRE 簡介:PCRE(Perl Compatible Regular Expressions)是一個Perl庫,包括 perl 兼容的正則表達式庫。這些在執行正規表達式模式匹配時用與Perl 5同樣的語法和語義是很有用的。Boost太龐大了,使用boost regex后,程序的編譯速度明顯變慢。測試了一下,同樣一個程序,使用boost::regex編譯時需要3秒,而使用pcre不到1秒。因此改用pcre來解決C語言中使用正則表達式的問題,簡單來說可以進行URL重寫,我們下載過來並解壓

[root@172 ~]# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz
[root@172 ~]# tar -zxvf pcre-8.39.tar.gz

進入到nginx文件夾目錄下,編譯安裝:

./configure --prefix=/usr/local/nginx  --with-pcre=../pcre-8.39     #回車
make && make install

安裝完成后進入 /usr/local/nginx 目錄下,可以看到已經安裝完畢:

復制代碼
[root@172 nginx-1.10.2]# cd /usr/local/nginx/
[root@172 nginx]# ll
總用量 4
drwxr-xr-x. 2 root root 4096 10月 23 13:43 conf
drwxr-xr-x. 2 root root   38 10月 23 13:43 html
drwxr-xr-x. 2 root root    6 10月 23 13:43 logs
drwxr-xr-x. 2 root root   18 10月 23 13:43 sbin
復制代碼

接下來啟動nginx,看到nginx已經啟動:

復制代碼
[root@172 nginx]# cd sbin/
[root@172 sbin]# ./nginx 
[root@172 sbin]# ps -aux |grep nginx
root      32128  0.0  0.0  18112   592 ?        Ss   13:46   0:00 nginx: master process ./nginx
nobody    32129  0.0  0.1  18532  1308 ?        S    13:46   0:00 nginx: worker process
root      32131  0.0  0.0 112664   984 pts/0    R+   13:46   0:00 grep --color=auto nginx
[root@172 sbin]# 
復制代碼

我們用curl http:/127.0.0.1 測試下是否已經可以看到信息:

復制代碼
[root@172 nginx]# curl http://127.0.0.1
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
復制代碼

沒有問題,打開瀏覽器輸入ip地址訪問:

 

 也是成功的,不過有些小伙伴會打不開,原因是防火牆開啟了導致訪問失敗,CentOS 7默認使用的是firewall作為防火牆,我們輸入 systemctl stop firewalld.service 把它關閉,再次訪問瀏覽器就可以看到了。附上防火牆的命令:

systemctl start firewalld.service    #啟動firewall
systemctl stop firewalld.service     #停止firewall
systemctl disable firewalld.service  #禁止firewall開機啟動

這個時候我們還不能訪問php文件的網頁的,因為nginx還無法解析它,這個時候該php-fpm大展身手了:

復制代碼
[root@172 nginx]# cd /usr/local/php7/sbin/
[root@172 sbin]# ll
總用量 28168
-rwxr-xr-x. 1 root root 28839999 10月 22 23:43 php-fpm
[root@172 sbin]# ./php-fpm 
[23-Oct-2016 14:14:51] ERROR: failed to open configuration file '/usr/local/php7/etc/php-fpm.conf': No such file or directory (2)
[23-Oct-2016 14:14:51] ERROR: failed to load configuration file '/usr/local/php7/etc/php-fpm.conf'
[23-Oct-2016 14:14:51] ERROR: FPM initialization failed
復制代碼

提示找不到php-fpm.conf文件,進入到 /usr/local/php7/etc 查看,發現只有default文件,把它copy一份到當前目錄下命名為php-fpm.conf

復制代碼
[root@172 sbin]# cd /usr/local/php7/etc
[root@172 etc]# ll
總用量 12
-rw-r--r--. 1 root root 1239 10月 22 23:43 pear.conf
-rw-r--r--. 1 root root 4465 10月 22 23:43 php-fpm.conf.default
drwxr-xr-x. 2 root root   29 10月 22 23:43 php-fpm.d

  [root@172 etc]# cp php-fpm.conf.default php-fpm.conf

復制代碼

再次啟動還是報錯,發現conf.d目錄下沒有.conf后綴的文件,一樣copy一份到該目錄下改為www.conf ,再啟動就成功了:

復制代碼
[root@172 etc]# /usr/local/php7/sbin/php-fpm 
[23-Oct-2016 14:19:14] 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.
[23-Oct-2016 14:19:14] ERROR: No pool defined. at least one pool section must be specified in config file
[23-Oct-2016 14:19:14] ERROR: failed to post process the configuration
[23-Oct-2016 14:19:14] ERROR: FPM initialization failed
[root@172 etc]# cd php-fpm.d
[root@172 php-fpm.d]# ll
總用量 20
-rw-r--r--. 1 root root 18521 10月 22 23:43 www.conf.default
[root@172 php-fpm.d]# cp www.conf.default www.conf
[root@172 php-fpm.d]# /usr/local/php7/sbin/php-fpm 
[root@172 php-fpm.d]# ps -aux | grep php-fpm
root      32369  0.0  0.2 148336  2548 ?        Ss   14:22   0:00 php-fpm: master process (/usr/local/php7/etc/php-fpm.conf)

nobody    32370  0.0  0.2 148336  2200 ?        S    14:22   0:00 php-fpm: pool www

nobody    32371  0.0  0.2 148336  2200 ?        S    14:22   0:00 php-fpm: pool www

root      32373  0.0  0.0 112664   984 pts/1    R+   14:23   0:00 grep --color=auto php-fp

[root@172 php-fpm.d]# 
復制代碼

然后打開編輯 /usr/local/nginx/conf/nginx.conf 文件,找到下面這段並改為如下圖:

復制代碼
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;
        }
復制代碼

再進入html目錄下,創建一個test.php文件:

復制代碼
[root@172 nginx]# cd html/
[root@172 html]# ll
總用量 8
-rw-r--r--. 1 root root 537 10月 23 13:43 50x.html
-rw-r--r--. 1 root root 612 10月 23 13:43 index.html
[root@172 html]# vim test.php

#輸入
<?php
phpinfo();

#保存退出
[root@172 html]# ../sbin/nginx -s reload      #重新載入nginx
復制代碼

打開瀏覽器,輸入你的ip地址:http://xxx.xxx.xx.xxx/test.php 訪問:

 

 至此,lnmp環境搭建完成。 

 

 
分類:  Linux, Mysql, PHP


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM