摘要:安裝之前要先安裝那些準(zhǔn)備裝的擴(kuò)展要用到的軟件模塊接下來上面已經(jīng)提到,已經(jīng)刪除了擴(kuò)展,所以不再是一個(gè)有效的選項(xiàng)。
實(shí)現(xiàn)環(huán)境
Centos 7 64位
IP地址:172.16.0.20
Nginx:1.12.0
Mysql:5.7.18
PHP:7.1.4
yum源:aliyun源
創(chuàng)建一個(gè)目錄存放下載的軟件
[root@localhost ~]# mkdir /software [root@localhost ~]# cd /software/軟件下載地址
這是我的網(wǎng)盤鏈接
或者去它們各自的官網(wǎng)下載最新版,下載命令參考
wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.18.tar.gz wget https://sourceforge.net/projects/pcre/files/pcre/8.40/pcre-8.40.tar.gz wget http://nginx.org/download/nginx-1.12.0.tar.gz wget http://hk1.php.net/distributions/php-7.1.4.tar.gz
這是需要的包
[root@localhost software]# ll 總用量 757804 -rw-r--r-- 1 root root 61612105 4月 18 14:55 mysql-boost-5.7.18.tar.gz -rw-r--r--. 1 root root 980831 4月 14 17:08 nginx-1.12.0.tar.gz -rw-r--r-- 1 root root 20319716 4月 18 15:41 php-7.1.4.tar.gz關(guān)閉系統(tǒng)限制
關(guān)閉系統(tǒng)防火墻
[root@localhost software]# systemctl stop firewalld.service [root@localhost software]# systemctl disable firewalld.service
關(guān)閉SElinux
[root@localhost software]# sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config [root@localhost software]# setenforce 0開始安裝nginx 創(chuàng)建www賬戶 用來啟動(dòng)nginx
[root@localhost software]# useradd www -s /sbin/nologin安裝依賴的包
[root@localhost software]# yum -y install pcre pcre-devel zlib zlib-devel gcc-c++ gcc openssl*解壓Nginx源碼包
root@localhost software]# tar zxvf nginx-1.12.0.tar.gz進(jìn)入解壓后的目錄,對(duì)Nginx進(jìn)行配置
[root@localhost software]# cd nginx-1.12.0/ [root@localhost nginx-1.12.0]# ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_realip_module --with-http_sub_module --with-http_gzip_static_module --with-http_stub_status_module --with-pcre編譯和安裝
[root@localhost nginx-1.12.0]# make && make install啟動(dòng)Nginx
[root@localhost nginx-1.12.0]# /usr/local/nginx/sbin/nginx瀏覽器訪問測試是否ok 關(guān)閉Nginx進(jìn)程
[root@localhost nginx-1.12.0]# killall nginx [root@localhost nginx-1.12.0]# ps -ef|grep nginxnginx命令做軟連接方便使用
[root@localhost nginx-1.12.0]# ln -s /usr/local/nginx/sbin/nginx /sbin/nginx編寫nginx啟動(dòng)腳本
cat >> /usr/lib/systemd/system/nginx.service << EOF [Unit] Description=nginx - high performance web server Documentation=http://nginx.org/en/docs/ After=network-online.target remote-fs.target nss-lookup.target [Service] Type=forking PIDFile=/usr/local/nginx/logs/nginx.pid ExecStartPre=/usr/sbin/nginx -t ExecStart=/usr/sbin/nginx ExecReload=//usr/sbin/nginx -s reload ExecStop=/usr/sbin/nginx -s stop PrivateTmp=true [Install] WantedBy=multi-user.target EOF修改完systemctl服務(wù),需要重新加載下daemon
[root@localhost nginx-1.12.0]# systemctl daemon-reload用systemctl啟動(dòng)Nginx服務(wù),并查看狀態(tài)
[root@localhost nginx-1.12.0]# systemctl start nginx [root@localhost nginx-1.12.0]# systemctl status nginx ● nginx.service - nginx - high performance web server Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled) Active: active (running) since 二 2017-04-18 14:06:58 CST; 8s ago Docs: http://nginx.org/en/docs/ Process: 11816 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS) Process: 11813 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS) Main PID: 11818 (nginx) CGroup: /system.slice/nginx.service ├─11818 nginx: master process /usr/sbin/nginx └─11820 nginx: worker process 4月 18 14:06:58 localhost.localdomain systemd[1]: Starting nginx - high performance web server... 4月 18 14:06:58 localhost.localdomain nginx[11813]: nginx: the configuration file /usr/local/nginx/conf/nginx...s ok 4月 18 14:06:58 localhost.localdomain nginx[11813]: nginx: configuration file /usr/local/nginx/conf/nginx.con...sful 4月 18 14:06:58 localhost.localdomain systemd[1]: Failed to read PID from file /usr/local/nginx/logs/nginx.pi...ment 4月 18 14:06:58 localhost.localdomain systemd[1]: Started nginx - high performance web server.設(shè)置nginx開機(jī)啟動(dòng)
[root@localhost nginx-1.12.0]# systemctl enable nginx
nginx安裝完成,下面安裝mysql
[root@localhost nginx-1.12.0]# cd /software/ [root@localhost software]# yum -y install ncurses ncurses-devel bison cmake gcc gcc-c++創(chuàng)建用戶和組
[root@localhost software]# groupadd mysql [root@localhost software]# useradd -s /sbin/nologin -g mysql mysql -M [root@localhost software]# id mysql解壓mysql源碼包
[root@localhost software]# tar zxvf mysql-boost-5.7.18.tar.gz進(jìn)入解壓后的目錄,對(duì)mysql進(jìn)行配置(5.5以上都是cmake)
[root@localhost software]# cd mysql-5.7.18/ [root@localhost mysql-5.7.18]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DSYSCONFDIR=/usr/local/mysql/etc -DSYSTEMD_PID_DIR=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DMYSQL_DATADIR=/usr/local/mysql/data -DWITH_BOOST=boost -DWITH_SYSTEMD=1
記住這個(gè)/usr/local/mysql/mysql.sock,php連接mysql會(huì)用到。
編譯和安裝[root@localhost mysql-5.7.18]# make && make install初始化數(shù)據(jù)庫及啟動(dòng)
[root@localhost mysql-5.7.18]# chown -R mysql.mysql /usr/local/mysql/ [root@localhost mysql-5.7.18]# cd /usr/local/mysql/
cat >> my.cnf << EOF [client] port = 3306 default-character-set=utf8 socket = /usr/local/mysql/mysql.sock [mysql] port = 3306 default-character-set=utf8 socket = /usr/local/mysql/mysql.sock [mysqld] user = mysql basedir = /usr/local/mysql datadir = /usr/local/mysql/data port = 3306 default-character-set=utf8 pid-file = /usr/local/mysql/mysqld.pid socket = /usr/local/mysql/mysql.sock server-id = 1 # 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 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES EOF
[root@localhost mysql]# chown mysql.mysql my.cnf [root@localhost mysql]# echo "PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH" >> /etc/profile [root@localhost mysql]# echo "export PATH" >> /etc/profile [root@localhost mysql]# source /etc/profile [root@localhost mysql]# bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data [root@localhost mysql]# cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/ [root@localhost mysql]# systemctl daemon-reload [root@localhost mysql]# systemctl start mysqld [root@localhost data]# ps -ef|grep mysql設(shè)置mysql開機(jī)啟動(dòng)
[root@localhost mysql]# systemctl enable mysqld查看Mysql啟動(dòng)狀態(tài)
[root@localhost mysql]# systemctl status mysqld ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled) Active: active (running) since 三 2017-04-19 10:48:20 CST; 25min ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 12734 ExecStart=/usr/local/mysql/bin/mysqld --daemonize --pid-file=/usr/local/mysql/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS) Process: 12714 ExecStartPre=/usr/local/mysql/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) Main PID: 12737 (mysqld) CGroup: /system.slice/mysqld.service └─12737 /usr/local/mysql/bin/mysqld --daemonize --pid-file=/usr/local/mysql/mysqld.pid 4月 19 10:48:20 localhost.localdomain mysqld[12734]: 2017-04-19T02:48:20.943096Z 0 [Note] Server hostname (bi...3306 4月 19 10:48:20 localhost.localdomain mysqld[12734]: 2017-04-19T02:48:20.943247Z 0 [Note] IPv6 is available. 4月 19 10:48:20 localhost.localdomain mysqld[12734]: 2017-04-19T02:48:20.943354Z 0 [Note] - "::" resolves to "::"; 4月 19 10:48:20 localhost.localdomain mysqld[12734]: 2017-04-19T02:48:20.943397Z 0 [Note] Server socket creat...::". 4月 19 10:48:20 localhost.localdomain mysqld[12734]: 2017-04-19T02:48:20.966965Z 0 [Note] Event Scheduler: Lo...ents 4月 19 10:48:20 localhost.localdomain mysqld[12734]: 2017-04-19T02:48:20.967379Z 0 [Note] /usr/local/mysql/bi...ons. 4月 19 10:48:20 localhost.localdomain mysqld[12734]: Version: "5.7.18" socket: "/usr/local/mysql/mysql.sock"...tion 4月 19 10:48:20 localhost.localdomain mysqld[12734]: 2017-04-19T02:48:20.967402Z 0 [Note] Executing "SELECT *...eck. 4月 19 10:48:20 localhost.localdomain mysqld[12734]: 2017-04-19T02:48:20.967409Z 0 [Note] Beginning of list o...bles 4月 19 10:48:20 localhost.localdomain systemd[1]: Started MySQL Server.進(jìn)入數(shù)據(jù)庫,創(chuàng)建一個(gè)測試數(shù)據(jù)庫以及授權(quán)遠(yuǎn)程用戶可訪問這個(gè)數(shù)據(jù)庫
[root@localhost mysql]# mysql Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 5 Server version: 5.7.18 Source distribution Copyright (c) 2000, 2017, 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> create database ceshi CHARACTER SET utf8 COLLATE utf8_general_ci; Query OK, 1 row affected (0.00 sec) mysql> grant all on ceshi.* to ceshi@"%" identified by "ceshi2017"; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.01 sec)查看授權(quán)的用戶表
[root@localhost mysql]# mysql Welcome to the MySQL monitor. Commands end with ; or g. Server version: 5.7.18 Source distribution 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> SELECT DISTINCT CONCAT("User: """,user,"""@""",host,""";") AS query FROM mysql.user; +--------------------------------+ | query | +--------------------------------+ | User: "ceshi"@"%"; | | User: "mysql.sys"@"localhost"; | | User: "root"@"localhost"; | +--------------------------------+ 3 rows in set (0.00 sec)
在別的機(jī)器連接172.16.0.20的ceshi數(shù)據(jù)庫
[root@localhost ~]# mysql -h172.16.0.20 -uceshi -p"ceshi2017" mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 11 Server version: 5.7.18 Source distribution Copyright (c) 2000, 2017, 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 | | ceshi | +--------------------+ 2 rows in set (0.00 sec)
PHP 7 在15年年底推出,PHP官方說的比 PHP 5 快2倍,就為這個(gè),這個(gè)鮮必須嘗。不過有個(gè)很值得注意的地方是,雖然 PHP 7 增加了不少新特性,但也很多地方是向后不兼容的,例如 mysql 擴(kuò)展,在 PHP 7 中已經(jīng)被刪除。 現(xiàn)在最新版本是7.1.4。
進(jìn)入software目錄[root@localhost mysql]# cd /software/接著解壓php源碼包
[root@localhost software]# tar zxvf php-7.1.4.tar.gz再進(jìn)入解壓后的文件夾
[root@localhost software]# cd php-7.1.4/
這里將只安裝一些常用的擴(kuò)展,大家可以根據(jù)自己的實(shí)際需要進(jìn)行增減,可以通過以下命令查看PHP安裝是具體有有些擴(kuò)展和選項(xiàng):
[root@localhost php-7.1.4]# ./configure --help
有接近300個(gè)選項(xiàng)。
安裝之前要先安裝那些準(zhǔn)備裝的擴(kuò)展要用到的軟件模塊[root@localhost php-7.1.4]# yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel curl curl-devel openssl openssl-devel接下來 configure PHP 7
[root@localhost php-7.1.4]# ./configure --prefix=/usr/local/php --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-mysqli --with-zlib --with-curl --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-openssl --enable-mbstring --enable-xml --enable-session --enable-ftp --enable-pdo -enable-tokenizer --enable-zip
上面已經(jīng)提到,PHP 7 已經(jīng)刪除了 MySQL 擴(kuò)展,所以 -with-mysql 不再是一個(gè)有效的選項(xiàng)。這里用 MySQLi 或 PDO 代替。
其中 --prefix 是安裝目錄,上面提到在同一個(gè)服務(wù)器安裝多個(gè) PHP 版本,這個(gè) --prefix 設(shè)定是很有必要的。至于其他擴(kuò)展大家按實(shí)際增減。
如果 configure 成功的話,將會(huì)看到以下類似字樣:
+--------------------------------------------------------------------+ | License: | | This software is subject to the PHP License, available in this | | distribution in the file LICENSE. By continuing this installation | | process, you are bound by the terms of this license agreement. | | If you do not agree with the terms of this license, you must abort | | the installation process at this point. | +--------------------------------------------------------------------+ Thank you for using PHP.編譯和安裝
[root@localhost php-7.1.4]# make && make install
好,PHP 7 已經(jīng)安裝完成,下面進(jìn)行配置
PHP 的配置文檔[root@localhost php-7.1.4]# cp php.ini-development /usr/local/php/lib/php.ini
php.ini 路徑應(yīng)該放在 PREFIX/lib 文件夾,除非在安裝的時(shí)候通過這個(gè)選項(xiàng)修改
--with-config-file-path=PATH
如果安裝 PHP 時(shí)沒有指明 --prefix ,那么就 php.ini 路徑就是 /usr/local/lib/php.ini 。剛才安裝時(shí)有指明 --prefix ,所以是 /usr/local/php/lib/php.ini
然后根據(jù)實(shí)際自己需要修改 php.ini。
查找 mysqli.default_socket,修改成 mysqli.default_socket = /usr/local/mysql/mysql.sock:
[root@localhost php-7.1.4]# grep mysqli.default_socket /usr/local/php/lib/php.ini mysqli.default_socket = [root@localhost php-7.1.4]# sed -i "s#mysqli.default_socket =#mysqli.default_socket = /usr/local/mysql/mysql.sock#" /usr/local/php/lib/php.ini [root@localhost php-7.1.4]# grep mysqli.default_socket /usr/local/php/lib/php.ini mysqli.default_socket = /usr/local/mysql/mysql.sock
其中 /usr/local/mysql/mysql.sock 就是上面安裝 MySQL 時(shí)提到的。這個(gè)值必須填,否則會(huì)出現(xiàn)如下錯(cuò)誤:
Warning: mysqli_connect(): (HY000/2002): No such file or directory
修改時(shí)區(qū),查找 date.timezone,改成(主要將前面的 ; 去掉,這個(gè)是注釋用的):
root@localhost php-7.1.4]# grep date.timezone /usr/local/php/lib/php.ini ; http://php.net/date.timezone ;date.timezone = [root@localhost php-7.1.4]# sed -i "s#;date.timezone =#date.timezone = Asia/Shanghai#" /usr/local/php/lib/php.ini [root@localhost php-7.1.4]# grep date.timezone /usr/local/php/lib/php.ini ; http://php.net/date.timezone date.timezone = Asia/Shanghai
好了,PHP 7 已經(jīng)安裝好,下面驗(yàn)證一下
[root@localhost php-7.1.4]# /usr/local/php/bin/php -v PHP 7.1.4 (cli) (built: Apr 17 2017 14:58:11) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
再查看下已經(jīng)安裝的模塊
[root@localhost php-7.1.4]# /usr/local/php/bin/php -m [PHP Modules] Core ctype curl date dom fileinfo filter ftp gd hash iconv json libxml mbstring mysqli mysqlnd openssl pcre PDO pdo_sqlite Phar posix Reflection session SimpleXML SPL sqlite3 standard tokenizer xml xmlreader xmlwriter zip zlib [Zend Modules]
接下來配置 php-fpm,復(fù)制 php-fpm 的配置文檔
[root@localhost php-7.1.4]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf [root@localhost php-7.1.4]# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
修改 /usr/local/php/etc/php-fpm.d/www.conf,把啟動(dòng)用戶改為和nginx服務(wù)同一個(gè)啟動(dòng)用戶(前面Nginx使用的是www賬戶,這里改成和Nginx使用一樣的賬戶;一般都是使用www用戶)
[root@localhost php-7.1.4]# grep -E "user =|group =" /usr/local/php/etc/php-fpm.d/www.conf user = nginx group = nginx [root@localhost php-7.1.4]# sed -i "s#user = nginx#user = www#" /usr/local/php/etc/php-fpm.d/www.conf [root@localhost php-7.1.4]# sed -i "s#group = nginx#group = www#" /usr/local/php/etc/php-fpm.d/www.conf [root@localhost php-7.1.4]# grep -E "user =|group =" /usr/local/php/etc/php-fpm.d/www.conf user = www group = www ;listen.group = www
其中 www.conf 中要留意這個(gè)值 listen = 127.0.0.1:9000
[root@localhost php-7.1.4]# grep "listen = 127.0.0.1" /usr/local/php/etc/php-fpm.d/www.conf
這里使用 9000 端口,這個(gè)選項(xiàng)在配置 Nginx 網(wǎng)站時(shí)要用到的。
配置 php-fpm 啟動(dòng)服務(wù)腳本
[root@localhost php-7.1.4]# cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/
查看啟動(dòng)腳本中指定的程序目錄和pid文件(默認(rèn)已經(jīng)修改過了,如果沒有修改過執(zhí)行下面操作)
[root@localhost php-7.1.4]# grep -E "PIDFile|ExecStart" /usr/lib/systemd/system/php-fpm.service PIDFile=/usr/local/php/var/run/php-fpm.pid ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf
修改啟動(dòng)腳本,把里邊 prefix 相關(guān)的內(nèi)容用實(shí)際路徑代替
[root@localhost php-7.1.4]# vim /usr/lib/systemd/system/php-fpm.service 將 PIDFile=${prefix}/var/run/php-fpm.pid ExecStart=${exec_prefix}/sbin/php-fpm --nodaemonize --fpm-config ${prefix}/etc/php-fpm.conf 修改成 PIDFile=/usr/local/php/var/run/php-fpm.pid ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf
重新載入 systemd
[root@localhost php-7.1.4]# systemctl daemon-reload
讓 php-fpm 隨機(jī)啟動(dòng)
[root@localhost php-7.1.4]# systemctl enable php-fpm Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.
立即啟動(dòng) php-fpm
[root@localhost php-7.1.4]# systemctl start php-fpm
查看狀態(tài)
[root@localhost php-7.1.4]# systemctl status php-fpm ● php-fpm.service - The PHP FastCGI Process Manager Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; vendor preset: disabled) Active: active (running) since 一 2017-04-17 15:37:06 CST; 1min 9s ago Main PID: 55770 (php-fpm) CGroup: /system.slice/php-fpm.service ├─55770 php-fpm: master process (/usr/local/php/etc/php-fpm.conf) ├─55771 php-fpm: pool www └─55772 php-fpm: pool www 4月 17 15:37:06 localhost.localdomain systemd[1]: Started The PHP FastCGI Process Manager. 4月 17 15:37:06 localhost.localdomain systemd[1]: Starting The PHP FastCGI Process Manager...
好,php-fpm 已經(jīng)成功啟動(dòng),那就立即建個(gè)網(wǎng)站看看
配置 Nginx 站點(diǎn)先建立一個(gè) lnmp 站點(diǎn),路徑是 /var/www/html
[root@localhost php-7.1.4]# mkdir -p /var/www/html [root@localhost php-7.1.4]# chown -R www.www /var/www
并準(zhǔn)備好 phpinfo 測試文件
cat >> /var/www/html/test.php << EOF創(chuàng)建一個(gè) Nginx 配置文件放到 /usr/local/nginx/conf/conf.d 中
[root@localhost php-7.1.4]# cd /usr/local/nginx/conf [root@localhost conf]# sed -i "$iinclude /usr/local/nginx/conf/conf.d/*;" nginx.conf [root@localhost conf]# cat nginx.conf [root@localhost conf]# mkdir conf.d [root@localhost conf]# cd conf.d/創(chuàng)建test.com.conf文件并寫入以下內(nèi)容
cat >> test.com.conf <其中 server_name localhost; 中的 localhost 改成你自己的域名(例如:www.baidu.com,這里我直接使用localhost和81端口來測試。網(wǎng)站域名解析默認(rèn)都是使用80端口的)
其中 root /var/www/html; 就是剛才創(chuàng)建的站點(diǎn)目錄
其中 fastcgi_pass 127.0.0.1:9000; 就是上面配置 php-fpm 提到要留意的值
修改配置后一定要記得 reload nginx 才能生效[root@localhost conf.d]# systemctl reload nginx [root@localhost conf.d]# systemctl reload php-fpm最后的配置(nginx服務(wù)器的IP必須和域名做解析,才可以使用域名訪問服務(wù),域名購買一般在阿里云上購買)
這里我們直接使用IP:81訪問(因?yàn)槲覀兪褂玫亩丝谑?1;域名是localhost,也就是nginx所在主機(jī)IP的意思)
創(chuàng)建一鍵安裝腳本one-click-install-lnmp.sh#!/bin/sh # __author__ = "junxi" # This script is used by fast installed lnmp ...... # write by 2017/04/19 mkdir /software cd /software/ ll systemctl stop firewalld.service systemctl disable firewalld.service sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config setenforce 0 ######start install nginx###### echo "######start install nginx######" useradd www -s /sbin/nologin yum -y install pcre pcre-devel zlib zlib-devel gcc-c++ gcc openssl* tar zxvf nginx-1.12.0.tar.gz cd nginx-1.12.0/ ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_realip_module --with-http_sub_module --with-http_gzip_static_module --with-http_stub_status_module --with-pcre make && make install sleep 2 ln -s /usr/local/nginx/sbin/nginx /sbin/nginx cat >> /usr/lib/systemd/system/nginx.service << EOF [Unit] Description=nginx - high performance web server Documentation=http://nginx.org/en/docs/ After=network-online.target remote-fs.target nss-lookup.target [Service] Type=forking PIDFile=/usr/local/nginx/logs/nginx.pid ExecStartPre=/usr/sbin/nginx -t ExecStart=/usr/sbin/nginx ExecReload=//usr/sbin/nginx -s reload ExecStop=/usr/sbin/nginx -s stop PrivateTmp=true [Install] WantedBy=multi-user.target EOF systemctl daemon-reload systemctl start nginx systemctl enable nginx systemctl status nginx sleep 2 echo "######nginx is install completed done.######" ###### start install mysql ###### cd /software/ yum -y install ncurses ncurses-devel bison cmake gcc gcc-c++ groupadd mysql useradd -s /sbin/nologin -g mysql mysql -M id mysql chown -R mysql.mysql /usr/local/mysql tar zxvf mysql-boost-5.7.18.tar.gz cd mysql-5.7.18/ cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DSYSCONFDIR=/usr/local/mysql/etc -DSYSTEMD_PID_DIR=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DMYSQL_DATADIR=/usr/local/mysql/data -DWITH_BOOST=boost -DWITH_SYSTEMD=1 sleep 1 make && make install sleep 2 chown -R mysql.mysql /usr/local/mysql/ cd /usr/local/mysql/ echo "######create my.cnf######" cat >> my.cnf << EOF [client] port = 3306 default-character-set=utf8 socket = /usr/local/mysql/mysql.sock [mysql] port = 3306 default-character-set=utf8 socket = /usr/local/mysql/mysql.sock [mysqld] user = mysql basedir = /usr/local/mysql datadir = /usr/local/mysql/data port = 3306 default-character-set=utf8 pid-file = /usr/local/mysql/mysqld.pid socket = /usr/local/mysql/mysql.sock server-id = 1 # 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 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES EOF chown mysql.mysql my.cnf echo "PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH" >> /etc/profile echo "export PATH" >> /etc/profile source /etc/profile bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/ systemctl daemon-reload systemctl start mysqld systemctl enable mysqld ps -ef|grep mysql systemctl status mysqld echo "######mysql is install completed done.######" ###### start install php ###### cd /software tar zxvf php-7.1.4.tar.gz cd php-7.1.4/ ./configure --help yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel curl curl-devel openssl openssl-devel ./configure --prefix=/usr/local/php --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-mysqli --with-zlib --with-curl --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-openssl --enable-mbstring --enable-xml --enable-session --enable-ftp --enable-pdo -enable-tokenizer --enable-zip sleep 1 make && make install sleep 2 cp php.ini-development /usr/local/php/lib/php.ini grep mysqli.default_socket /usr/local/php/lib/php.ini sed -i "s#mysqli.default_socket =#mysqli.default_socket = /usr/local/mysql/mysql.sock#" /usr/local/php/lib/php.ini grep mysqli.default_socket /usr/local/php/lib/php.ini grep date.timezone /usr/local/php/lib/php.ini sed -i "s#;date.timezone =#date.timezone = Asia/Shanghai#" /usr/local/php/lib/php.ini grep date.timezone /usr/local/php/lib/php.ini /usr/local/php/bin/php -v /usr/local/php/bin/php -m cp /usr/local/php/etc/php-fpm.conf.default cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf grep -E "user =|group =" /usr/local/php/etc/php-fpm.d/www.conf sed -i "s#user = nginx#user = www#" /usr/local/php/etc/php-fpm.d/www.conf sed -i "s#group = nginx#group = www#" /usr/local/php/etc/php-fpm.d/www.conf grep -E "user =|group =" /usr/local/php/etc/php-fpm.d/www.conf cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/ grep -E "PIDFile|ExecStart" /usr/lib/systemd/system/php-fpm.service systemctl daemon-reload systemctl enable php-fpm systemctl start php-fpm systemctl status php-fpm echo "######php is install completed done.######" ####### create test.com file used by test lnmp config is correct or incorrect ###### mkdir -p /var/www/html chown -R www.www /var/www cat >> /var/www/html/test.php << EOF > test.com.conf <把nginx-1.12.0.tar.gz、mysql-boost-5.7.18.tar.gz、php-7.1.4.tar.gz這三個(gè)文件和one-click-install-lnmp.sh腳本下載下來,放到/software目錄下(這是下載地址),放在同一個(gè)目錄下,運(yùn)行下面命令進(jìn)行安裝
[root@localhost ~]# mkdir /software [root@localhost ~]# cd /software/ [root@localhost software]# ll 總用量 80984 -rw-r--r--. 1 root root 61612105 4月 19 14:22 mysql-boost-5.7.18.tar.gz -rw-r--r--. 1 root root 980831 4月 19 14:23 nginx-1.12.0.tar.gz -rw-r--r--. 1 root root 6282 4月 19 14:24 one-click-install-lnmp.sh -rw-r--r--. 1 root root 20319716 4月 19 14:23 php-7.1.4.tar.gz [root@localhost software]# sh one-click-install-lnmp.sh等待安裝完成即可。
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://specialneedsforspecialkids.com/yun/39897.html
摘要:安裝之前要先安裝那些準(zhǔn)備裝的擴(kuò)展要用到的軟件模塊接下來上面已經(jīng)提到,已經(jīng)刪除了擴(kuò)展,所以不再是一個(gè)有效的選項(xiàng)。 實(shí)現(xiàn)環(huán)境 Centos 7 64位 IP地址:172.16.0.20Nginx:1.12.0Mysql:5.7.18PHP:7.1.4yum源:aliyun源 如果你的系統(tǒng)是新安裝的redhat 7或 Centos 7 ,可以使用我的一鍵優(yōu)化腳本優(yōu)化系統(tǒng),有利于系統(tǒng)的使用和...
摘要:下源碼安裝一前言之前,我的開發(fā)環(huán)境是。重新加載權(quán)限表將確保所有到目前為止所做的更改將立即生效。然后,和注意,如果是使用二進(jìn)制包安裝了及相應(yīng)的開發(fā)庫,不需要指定路徑。五參考資料入門教程編譯安裝編譯安裝 Debian9下源碼安裝LNMP 一、前言 之前,我的開發(fā)環(huán)境是Windows-10+PHP-7.1+Nginx-1.10+MariaDB-10.1。 后面開發(fā)需要使用到memcached...
閱讀 1439·2021-11-11 16:54
閱讀 9319·2021-11-02 14:44
閱讀 2371·2021-10-22 09:53
閱讀 3259·2019-08-30 11:18
閱讀 1951·2019-08-29 13:29
閱讀 2003·2019-08-27 10:58
閱讀 1623·2019-08-26 11:38
閱讀 3518·2019-08-26 10:31