文章目录

  • 四、LAMP&LNMP架构
    • 4.1 背景知识
      • 4.1.1 CGI的处理流程
      • 4.1.2 相关术语释疑
      • 4.1.3 php-fpm转发过程图解
      • 4.1.4 web server和CGI的交互模式
    • 4.2 LAMP
      • 4.2.1 (centos6)mysql的基本用法
        • 1.rpm安装
        • 2.启动服务
        • 3.常用操作
        • 4.数据库的备份
        • 5.常用的sql语句
        • 6.忘记root密码
      • 4.2.2 LAMP下安装wordpress
        • 1.mysql配置
        • 2.apache配置
        • 3.PHP配置
        • 4.WordPress配置
        • 5.Discuz
    • 4.3 LNMP
      • 4.3.1 nginx的基本用法
      • 4.3.2 编译安装lnmp
        • 1.编译安装mysql
        • 2.安装php
        • 3.安装nginx

四、LAMP&LNMP架构

4.1 背景知识

CGI Common Gateway Interface

公共网关接口,是一个Web服务器主机提供信息服务的标准接口。

服务器端 CGI 程序接收信息有三种途径:环境变量、命令行和标准输入

4.1.1 CGI的处理流程

4.1.2 相关术语释疑

  • cgi:它是一种协议。通过cgi协议,web server可以将动态请求和相关参数发送给专门处理动态内容的应用程序。
  • fastcgi:也是一种协议,只不过是cgi的优化版。cgi的性能较差,fastcgi则在其基础上进行了改进。它是与Http类似的一种应用层通信协议。
  • php-cgi:php-cgi是个CGI程序,fastcgi是一种协议,而php-cgi实现了这种协议。不过这种实现比较烂。它是单进程的,一个进程处理一个请求,处理结束后进程就销毁。
  • php-fpm:是对php-cgi的改进版,它直接管理多个php-cgi进程/线程。也就是说,php-fpm是php-cgi的进程管理器因此它也算是fastcgi协议的实现。在一定程度上讲,php-fpm与php的关系,和tomcat对java的关系是类似的。
  • cgi进程/线程:在php上,就是php-cgi进程/线程。专门用于接收web server的动态请求,调用并初始化zend虚拟机。
  • cgi脚本:被执行的php源代码文件。
  • zend虚拟机:对php文件做词法分析、语法分析、编译成opcode,并执行。最后关闭zend虚拟机。
  • cgi进程/线程和zend虚拟机的关系:cgi进程调用并初始化zend虚拟机的各种环境。

Nginx 与 PHP-FPM 运行原理:https://www.iteye.com/blog/wangzq-phper-2314034

Fastcgi是用来提高CGI程序性能的,那么CGI程序的性能问题在哪呢?“PHP解析器会解析php.ini文件,初始化执行环境”

4.1.3 php-fpm转发过程图解

FPM(FastCGI Process Manager)

4.1.4 web server和CGI的交互模式

1.cgi模式

httpd接收到一个动态请求就fork一个cgi进程,cgi进程返回结果给httpd进程后自我销毁。

2.动态模块模式

将php-cgi的模块(例如php5_module)编译进httpd。在httpd启动时会加载模块,加载时也将对应的模块激活,php-cgi也就启动了。

3.php-fpm模式

使用php-fpm管理php-cgi,此时httpd不再控制php-cgi进程的启动。可以将php-fpm独立运行在非web服务器上,实现所谓的动静分离。

PHP-FPM 的主配置文件是 /etc/php7/php-fpm.conf

  • 配置
<VirtualHost *:80>DocumentRoot  "/www/web/forum"ServerName www.forum.comProxyRequests OffProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/www/web/forum/$1<Directory "/www/web/forum">Options noneAllowOverride noneRequire all granted</Directory>
</VirtualHost>

LoadModule rewrite_module modules/mod_rewrite.so

AddType application/x-httpd-php .php

AddType application/x-httpd-php-source .phps

LoadModule proxy_module modules/mod_proxy.so

LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

4.2 LAMP

LAMP(Linux+Apache+Mysql+Php/Perl/Python…)

4.2.1 (centos6)mysql的基本用法

1.rpm安装
yum install mysql-server
2.启动服务
service mysqld start
3.常用操作

mysql客户端命令

mysql-u # 用户名-p # 密码-h # 主机-P # 协议

更改用户密码

mysqladmin实现

mysqladmin -uroot password 'new-password' -p
# or
mysqladmin -u root -h hostname password 'new-password'

修改数据库实现

mysql> SET PASSWORD FOR 'root@host_name' = PASSWORD('new-password');
# or
mysql> UPDATE mysql.user SET PASSWORD=PASSWORD('new-password') where CONDITION;
# or
mysql> flush privillage;

服务端常用命令

常用mysql交互模式语句

show databases;
show tables;
use DB;
select * from TB;
create database DB;
grant all on DB.TB  to 'USER'@'HOST' identified by 'PASS';
flush privileges;

批处理模式(用于将表导入数据库)

mysql < *.sql
4.数据库的备份
mysqldump -uroot -p PASSWORD [DB_NAME] > [DUMP_FILE] # 备份指定数据库
mysqldump --no-data --databases mydatabase1 mydatabase2 mydatabase3 > [DdMP_FILE] # 只备份表结构
mysqldump --all-databases > [DUMP_FILE] # 备份所有数据库
5.常用的sql语句

数据定义语言-DDL(data define language)

数据定义,建立数据库的基本组件

# 创建(CREATE)
CREATE DATABASE db_name;# 删除(DROP)
DROP DATABASE db_name;
TABLE [IF NOT EXISTS] tb_name;
USER 'username' @ 'host' IDENTIFIED BY 'password';# 修改(ALTER)
ALTER TABLE tb_name

数据操作语言-DML:根据需要插入,修改,删除数据库中的数据

# 插入(INSERT)
INSERT INTO tb_name (col1,col2,...) VALUES | VALUE ("String",NUM,...)
#eg:INSERT INTO tb_name (Name,Age) VALUE (haha,22);# 更新(UPDATE)
UPDATE tb_name SET column=VALUE; # 更改所有字段的值# 删除(DELETE)
DELETE FROM tb_name; #删除所有行
DELETE FROM tb_name WHERE expression;
#eg:DELETE FROM student WHERE Name="haha";# 选择(SELECT)
SELECT * FROM tb_name; # 无where则显示字段的所有行
SELECT * FROM tb_name WHERE expression;

数据控制语言-DCL:实现用户的授权和撤权

# 授权(GRANT)
GRANT privillage ON db_name.tb_name TO 'username'@'host' IDENTIFIED BY 'PASSWORD';
# privillage;可以是INSERT,UPDATE,DELETE,SELECT,ALL
# 用户名不存在则会自动创建
GRANT ALL ON db_name.* TO 'username'@'host';
SHOW GRANTS FOR 'username'@'%' # 查看授权信息# 撤权(REVOKE)
REVOKE privillage ON  ON db_name.tb_name TO 'username'@'host' IDENTIFIED BY 'PASSWORD';# 刷新权限
flush privileges;
6.忘记root密码
# 跳过访问控制权限进入mysql
# 编辑/etc/my.cnf,添加一行:skip-grant-table
[mysqld]
skip-grant-table# 重启mysqld
service mysqld restart# 修改密码
UPDATE mysql.user SET PASSWORD=PASSWORD('') where user='root' and host='localhost';
# 编辑/etc/my.cnf,删除skip-grant-table# 重启服务
service mysqld restsrt

4.2.2 LAMP下安装wordpress

1.mysql配置
  • 安装mysql
[root@lnmp ~]# yum install -y mariadberver
[root@lnmp ~]# yum install -y mariadb-server

centos7的默认数据库为mariadb。

  • 启动mysql
[root@lnmp ~]# systemctl start mariadb
[root@lnmp ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
  • 登录mysql

默认情况下,新用户是没有密码的,直接回车进入修改密码

[root@lnmp ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.65-MariaDB MariaDB ServerCopyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MariaDB [(none)]> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -ADatabase changed
MariaDB [mysql]> update user set password=PASSWORD("123") where user="root";
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4  Changed: 4  Warnings: 0MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)MariaDB [mysql]> quit
Bye
[root@lnmp ~]# systemctl restart mariadb
[root@lnmp ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.65-MariaDB MariaDB ServerCopyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MariaDB [(none)]>
2.apache配置
  • 下载apache rpm包并安装
[root@lnmp ~]# yum install -y httpd
[root@lnmp ~]# systemctl start httpd
[root@lnmp ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

之前是建了虚拟主机的www.haha.com

3.PHP配置
  • 安装php
[root@lnmp ~]# yum install -y php
[root@lnmp ~]# systemctl restart httpd
  • 创建检验文件
[root@lnmp ~]# cd /data/haha
[root@lnmp haha]# vim index.php
<?phpecho "<h1> php </h1>";
?>

使用浏览器打开

  • 安装php中的Mysql组件
[root@lnmp ~]# yum install -y php-mysql

安装完后有很多mysql相关内容

phpinfo();

  • 安装phpMyAdmin(非必装)
[root@lnmp ~]# yum install -y phpmyadmin

phpmyadmin不能直接用浏览器打开要建一个快键方式

[root@lnmp ~]# ln -s /usr/share/phpMyAdmin/ /data/haha/

然后就可以了

4.WordPress配置
  • 创建数据库
MariaDB [(none)]> create database wordpress;
Query OK, 1 row affected (0.00 sec)MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
| wordpress          |
+--------------------+
5 rows in set (0.38 sec)MariaDB [(none)]>
  • 下载wordpress压缩包并解压,然后编辑一下文件
[root@lnmp ~]# wget https://wordpress.org/wordpress-4.8.tar.gz
[root@lnmp ~]# tar -xzvf wordpress-4.8.tar.gz
[root@lnmp ~]# vim wordpress/wp-config-sample.php
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress');/** MySQL database username */
define('DB_USER', 'root');/** MySQL database password */
define('DB_PASSWORD', '123');/** MySQL hostname */
define('DB_HOST', 'localhost');[root@lnmp ~]# cp -rf wordpress /data/haha/
  • 访问

先创建一个用户并授权

MariaDB [(none)]> grant all on wordpress.* to 'kuangfeng'@'localhost' identified by '123' ;
Query OK, 0 rows affected (0.12 sec)
  • 手工建文件

[root@lnmp ~]# ll /data/haha -d
drwxr-xr-x 3 root root 4096 Jun  3 23:21 /data/haha
[root@lnmp ~]# vim /data/haha/wordpress/wp-config.php

完成

完成

5.Discuz

安装解压

[root@lnmp ~]# wget http://download.comsenz.com/DiscuzX/3.3/Discuz_X3.3_SC_GBK.zip
[root@lnmp ~]# yum install -y unzip
[root@lnmp ~]# unzip Discuz_X3.3_SC_GBK.zip
[root@lnmp ~]# cp -rf upload /data/haha/

第一步

然后用浏览器打开

第二步

检查 Discuz! X3.2 论坛系统的安装环境及目录权限。

确保都可写

第三步

选择“全新安装 Discuz! X(含 UCenter Server)”。

第四步

先创建一个数据库专门放这类数据并授权

MariaDB [(none)]> create database discuz;
Query OK, 1 row affected (0.03 sec)MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| discuz             |
| mysql              |
| performance_schema |
| test               |
| wordpress          |
+--------------------+
6 rows in set (0.01 sec)
MariaDB [(none)]> grant all on discuz.* to 'kuangfeng'@'localhost' identified by '123' ;
Query OK, 0 rows affected (0.13 sec)

填写服务器的数据库信息与论坛系统管理员信息。

之前的数据库密码

第五步

等待 Discuz! X3.2 论坛系统安装完毕

4.3 LNMP

LNMP(Linux+Nginx+MySQL+Php)

4.3.1 nginx的基本用法

安装

[root@lnmp ~]# yum install -y nginx

源码编译安装

./configure
make
mak install

启动&重启

/usr/local/nginx/sbin/nginx
nginx -t # 测试配置文件
nginx -s reload

添加虚拟主机

[root@lnmp ~]# vim /etc/nginx/nginx.conf
include             /etc/nginx/conf.d/vhost/haha.conf;
[root@lnmp ~]# mkdir /etc/nginx/conf.d/vhost

配置文件 php

[root@lnmp ~]# vim /etc/nginx/conf.d/vhost/haha.conf
server {listen 80;server_name www.haha.com;root /data/haha;sendfile        on;location / {root /data/haha/;index index.html index.php;}location ~ \.php$ {fastcgi_pass 127.0.0.1:9000;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name ;include fastcgi_params;}
}

访问nginx映射的代码目录中的index.php报错502:https://blog.csdn.net/qq_16265383/article/details/88960602

完成

4.3.2 编译安装lnmp

1.编译安装mysql

安装编译工具和相关依赖

[root@lnmp ~]# yum install -y apr* autoconf automake bison bzip2 bzip2* cpp curl curl-devel fontconfig fontconfig-devel freetype freetype* freetype-devel gcc gcc-c++ gd gettext gettext-devel glibc kernel kernel-headers keyutils keyutils-libs-devel krb5-devel libcom_err-devel libpng libpng-devel libjpeg* libsepol-devel libselinux-devel libstdc++-devel libtool* libgomp libxml2 libxml2-devel libXpm* libtifflibtiff* make mpfr ncurses* ntp openssl openssl-devel patch pcre-devel perl php-common php-gd policycoreutils telnet t1lib t1lib* nasm nasm* wget zlib-devel

下载依赖安装包

[root@lnmp ~]# mkdir /tmp/source
[root@lnmp ~]# cd /tmp/source/
[root@lnmp source]#
[root@lnmp source]# wget http://nginx.org/download/nginx-1.10.3.tar.gz
[root@lnmp source]# wget https://www.php.net/distributions/php-5.4.35.tar.gz
[root@lnmp source]# wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.17.tar.gz
[root@lnmp source]# wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
[root@lnmp source]# wget http://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
[root@lnmp source]# wget http://nchc.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz
wget http://iweb.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz

安装libiconv,libmcrypt,mhash,bision

[root@lnmp source]# tar -xzvf libmcrypt-2.5.8.tar.gz
[root@lnmp source]# tar -xzvf libiconv-1.14.tar.gz
[root@lnmp source]# tar -xzvf mhash-0.9.9.9.tar.gz [root@lnmp source]# cd libmcrypt-2.5.8
[root@lnmp libmcrypt-2.5.8]# ./configure --prefix=/usr/local
[root@lnmp libmcrypt-2.5.8]# make && make install[root@lnmp source]# cd libiconv-1.14
[root@lnmp libiconv-1.14]# ./configure --prefix=/usr/local
[root@lnmp libiconv-1.14]# make && make install[root@lnmp source]# cd mhash-0.9.9.9
[root@lnmp mhash-0.9.9.9]# ./configure --prefix=/usr/local
[root@lnmp mhash-0.9.9.9]# make && make install

问题

[root@lnmp libiconv-1.14]# cd srclib/
[root@lnmp srclib]# sed -i -e '/gets is a security/d' ./stdio.in.h

安装cmake

[root@lnmp source]# wget https://cmake.org/files/v3.6/cmake-3.6.1.tar.gz
[root@lnmp source]# tar -xzvf cmake-3.6.1.tar.gz
[root@lnmp cmake-3.6.1]# ./configure --prefix=/usr
[root@lnmp cmake-3.6.1]# gmake
[root@lnmp cmake-3.6.1]# gmake install

准备用户,目录

[root@lnmp source]# groupadd mysql
[root@lnmp source]# useradd -g mysql mysql
[root@lnmp source]# groupadd nginx
[root@lnmp source]# useradd -g nginx nginx
[root@lnmp source]# mkdir -p /data/mysql
[root@lnmp source]# chown -R mysql.mysql /data/mysql
[root@lnmp source]# mkdir -p /data/www
[root@lnmp source]# chown -R nginx.nginx /data/www

安装

[root@lnmp source]# tar -xzvf mysql-5.6.17.tar.gz
[root@lnmp source]# cd mysql-5.6.17
[root@lnmp mysql-5.6.17]# cmake -DCMAKE_INTSALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DMYSQL_DATADIR=/data/mysql -DENABLE_DOWNLOADS=1
[root@lnmp mysql-5.6.17]# make && make install

注:可能会报错,先执行以下两步再编译

[root@lnmp mysql-5.6.19]# rm CMakeCache.txt
[root@lnmp mysql-5.6.19]# yum install ncurses-devel

CentOS安装MySQL时报Curses library not found:https://blog.csdn.net/u010098331/article/details/51519234

为了让 MySQL 数据库程序正常运转起来,需要先删除/etc 目录中的默认配置文件,然后在 MySQL 数据库程序的保存目录 scripts 内找到一个名为 mysql_install_db 的脚本程序,执行这个脚本程序并使用–user 参数指定 MySQL 服务的对应账号名称(在前面步骤已经创建),使用–basedir 参数指定 MySQL 服务程序的保存目录,使用–datadir 参数指定 MySQL 真实数据库的文件保存目录,这样即可生成系统数据库文件,也会生成出新的 MySQL 服务配置文件。

[root@lnmp mysql-5.6.17]# rm -rf /etc/my.cnf
[root@lnmp mysql-5.6.17]# cd /usr/local/mysql
[root@lnmp mysql]# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql

把系统新生成的 MySQL 数据库配置文件链接到/etc 目录中,然后把程序目录中的开机程序文件复制到/etc/rc.d/init.d 目录中,以便通过 service 命令来管理 MySQL 数据库服务程序。记得把数据库脚本文件的权限修改成 755 以便于让用户有执行该脚本的权限:

[root@lnmp mysql]# ln -s my.cnf /etc/my.cnf
[root@lnmp mysql]# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@lnmp mysql]# chmod 755 /etc/rc.d/init.d/mysqld

编辑刚复制的 MySQL 数据库脚本文件,把第 46、47 行的 basedir 与 datadir 参数分别修改为 MySQL 数据库程序的保存目录和真实数据库的文件内容。

[root@lnmp mysql]# vim /etc/rc.d/init.d/mysqldbasedir=/usr/local/mysql
datadir=/data/mysql

配置好脚本文件后便可以用 service 命令启动 mysqld 数据库服务了。mysqld 是 MySQL数据库程序的服务名称,注意不要写错。顺带再使用 chkconfig 命令把 mysqld 服务程序加入到开机启动项中。

[root@lnmp mysql]# service mysqld start
Starting MySQL. SUCCESS!
[root@lnmp mysql]# chkconfig mysqld on

想要把命令所保存的目录永久性地定义到 PATH 变量中,需要编辑/etc/profile 文件并在末尾追加的命令目录

初始化mysql

[root@lnmp mysql-5.6.17]# /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql/ --user=mysql

添加mysql服务到init脚本

[root@lnmp mysql-5.6.17]# cd /usr/local/mysql
[root@lnmp mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@lnmp mysql]# vim /etc/profile
[root@lnmp mysql]# PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
[root@lnmp mysql]# export PATH
[root@lnmp mysql]# source /etc/profile

修改mysql的root用户密码

[root@lnmp mysql]# mysqladmin -u root password '123'

运行安全设置脚本,修改MYSQL用户root的密码,同时可禁止root远程连接,移除test数据库和匿名用户

[root@lnmp mysql]# /usr/local/mysql/bin/mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none): 回车
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] y
New password: root
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
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? [Y/n] 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? [Y/n] y
... 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? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
... Success!
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
Cleaning up...
2.安装php

编译

[root@lnmp ~]# mkdir /usr/local/php
[root@lnmp ~]# cd /tmp/source/
[root@lnmp source]# tar -xzvf php-5.4.35.tar.gz
[root@lnmp source]# cd php-5.4.35
[root@lnmp php-5.4.35]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-mysql=/usr/local/mysql/ --enable-mbstring --enable-soap --enable-bcmath --enable-zip --enable-calendar --enable-sockets --with-curl=/usr/local/  --with-png-dir=/usr/local/ --with-freetype-dir=/usr/local/ --with-jpeg-dir=/usr/local/ --with-mhash=/usr/local/ --with-zlib-dir=/usr/local/ --with-mcrypt=/usr/local/ --with-iconv=/usr/local/ --with-gd
[root@lnmp php-5.4.35]# make && make install
[root@lnmp php-5.4.35]# cp php.ini-development /usr/local/php/etc/php.ini
[root@lnmp php-5.4.35]# rm -rf /etc/php.ini
[root@lnmp php-5.4.35]# cp php.ini-production /usr/local/php/etc/php.ini
[root@lnmp php-5.4.35]# ln -s /usr/local/php/etc/php.ini /etc/php.ini
[root@lnmp php-5.4.35]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[root@lnmp php-5.4.35]# ln -s /usr/local/php/etc/php-fpm.conf /etc/php-fpm.conf

php-fpm.conf 是 php 服务程序重要的配置文件

启用该配置文件中第 25 行左右的 pid 文件保存目录,然后分别将第 148 和 149 行的 user 与 group 参数分别修改为 www账户和用户组名称:

去掉25行pid前的分号

148和149行的nobody改成www

[root@lnmp php-5.4.35]# vim /usr/local/php/etc/php-fpm.confpid = run/php-fpm.piduser = nginx
group = nginx

配置妥当后便可把用于管理 php 服务的脚本文件复制到/etc/rc.d/init.d 中了。为了能够执行脚本,请记得为脚本赋予 755 权限。最后把 php-fpm 服务程序加入到开机启动项中:

[root@lnmp php-5.4.35]# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
[root@lnmp php-5.4.35]# chmod 755 /etc/rc.d/init.d/php-fpm
[root@lnmp php-5.4.35]# chkconfig php-fpm on

配置php-fpm

启动php-fpm

[root@lnmp php-5.4.35]# /usr/local/php/sbin/php-fpm &
[1] 39223
3.安装nginx

安装nginx的依赖库

[root@lnmp php-5.4.35]# yum install -y pcre zlib

编译安装nginx

[root@lnmp source]# tar -xzvf nginx-1.10.3.tar.gz
[root@lnmp source]# cd nginx-1.10.3
[root@lnmp nginx-1.10.3]# ./configure --prefix=/usr/local/nginx
[root@lnmp nginx-1.10.3]# make && make install

将nginx的执行路径加入PATH

[root@lnmp nginx-1.10.3]# vim /etc/profile
/usr/local/nginx/sbin:$PATH
[root@lnmp nginx-1.10.3]# source /etc/profile

配置nginx脚本

[root@lnmp ~]# vim /etc/rc.d/init.d/nginx
#!/bin/bash
# nginx - this script starts and stops the nginx daemon
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /usr/local/nginx/conf/nginx.conf
# pidfile: /usr/local/nginx/logs/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=`$nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`if [ -z "`grep $user /etc/passwd`" ]; thenuseradd -M -s /bin/nologin $userfi
options=`$nginx -V 2>&1 | grep 'configure arguments:'`
for opt in $options; doif [ `echo $opt | grep '.*-temp-path'` ]; thenvalue=`echo $opt | cut -d "=" -f 2`if [ ! -d "$value" ]; then# echo "creating" $valuemkdir -p $value && chown -R $user $valuefifi
done
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
#configtest || return $?
stop
sleep 1
start
}
reload() {
#configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)rh_status_q && exit 0$1;;
stop)rh_status_q || exit 0$1;;
restart|configtest)
$1
;;
reload)rh_status_q || exit 7$1;;
force-reload)force_reload;;
status)rh_status;;
condrestart|try-restart)rh_status_q || exit 0;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
[root@lnmp ~]# chmod 755 /etc/rc.d/init.d/nginx
[root@lnmp ~]# /etc/rc.d/init.d/nginx restart
Reloading systemd:  [  OK  ]
Restarting nginx (via systemctl):  [  OK  ]
[root@lnmp ~]# chkconfig nginx on

编辑nginx配置文件,加入解析php相关配置

    server {listen       80;server_name  www.haha.com;root /data/haha;location / {index index.php;}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;}                                              }

问题:可能解析不了,就把fastcgi_param SCRIPT_FILENAME documentrootdocument_rootdocumentr​ootfastcgi_script_name;改为绝对路径fastcgi_param SCRIPT_FILENAME /data/haha$fastcgi_script_name;

编辑文件

[root@lnmp ~]# mkdir /data/haha
[root@lnmp ~]# vim /data/haha/index.php<?phpecho "<h1> haha php </h1>";
?>

进入浏览器测试

web服务之LAMPLNMP架构相关推荐

  1. web服务端的架构演变

    此文已由作者肖凡授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 最近Lofter项目碰到很多性能上的问题,特别是数据库相关的,每次推送后,告警就会第一时间到来.这些问题随着产 ...

  2. Web服务的体系架构

    Web简介: Web是WWW(World Wide Web)的简称,又称为万维网,是建立在客户机/服务器上的,以HTML语言和HTML协议为基础,提供面向Internet服务的,有一致用户界面的一种信 ...

  3. python代码转成php代码的工具 或者go转成php的代码,想把odoo改成成php swoole当成web服务+go的架构

    目前市场上有一些可以将Python代码转换为PHP代码的工具,例如: Transcrypt:Transcrypt是一个将Python代码转换为JavaScript和PHP的工具.它可以将Python代 ...

  4. web服务:原理与技术01

    电子服务系统设计复习总结01 前言 本文档原意为考试复习所用,基于 <web服务:原理与技术> 课本. 第一章 1.什么是WS (Web Service) ​ ①当服务使用因特网作为通信手 ...

  5. 干净架构在 Web 服务开发中的实践

    干净架构(The Clean Architecture)是 Bob 大叔在 2012 年的一篇博文 The Clean Architecture 中,提出的一种适用于复杂业务系统的软件架构方式.干净架 ...

  6. Web服务 源码编译安装LAMP架构

    Web服务 源码编译安装LAMP架构 一.LAMP架构 1.LAMP架构是什么 2.各组件的主要作用 二.编译安装Apache httpd服务 1.关闭防火墙,将安装Apache所需软件包传到/opt ...

  7. web服务优化与健壮性改进_创建健壮的微服务架构所涉及的组件

    web服务优化与健壮性改进 在本文中,我们将简要学习构建强大的微服务应用程序所需的各种软件组件. 在简要了解每个架构组件之前,我们将陈述设计微服务架构时出现的一般查询. 1.微服务架构组件 每当我们创 ...

  8. 常用的系统架构 web服务器之iis,apache,tomcat三者之间的比较

    常用的系统架构是: Linux + Apache + PHP + MySQL Linux + Apache + Java (WebSphere) + Oracle Windows Server 200 ...

  9. 综合架构web服务之nginx详解

    文章目录 nginx 服务配置详细介绍 关于作者 前言 一.nginx web 入门简介 1.1 什么是nginx 1.2 常见的网站服务 1.3 nginx 网站服务特点 1.4 网站页面访问原理 ...

最新文章

  1. 有存款,才能过得更踏实
  2. 设计模式(35)-----设计模式阶段性总结(一句话概括一个模式)
  3. 转:在windows通过Xrdp软件远程桌面连接Fedora
  4. c语言中continue在case中,C語言switch case 語句中能否使用continue 關鍵字?
  5. 2018-2019 20165226 Exp9 Web安全基础
  6. php扩展 waf,基于PHP扩展的WAF实现
  7. google 浏览器默认打开控制台_chrome浏览器使用 Console(控制台)
  8. bootstraptable导出excel独立使用_使用 EasyPOI 优雅导出Excel模板数据(含图片)
  9. 手工编程是指利用计算机完成,西安交通大学17年3月课程考试《CAD CAM》作业考核试题...
  10. 江苏省有JAVA技能大赛,江苏省职业学校技能大赛组委会
  11. 顶刊学者带你深度理解本地差分隐私【会议笔记】
  12. 字符串在Python中的本质是一个序列。 数字类型不是序列,不是可迭代对象,只能看做一个整体不可分割...
  13. anaconda + pycharm安装教程补充
  14. paip.提升分词---准确度--常用量词表
  15. EMC与电阻、电容和电感的关系
  16. shopnc route.php,shopnc商城专题页的伪静态支持
  17. 联通链:5G时代的信任链
  18. 使用python监控NTP系统(时钟服务器)
  19. 英语语法之强调句和倒装
  20. 有画快说番外篇-张聪-专题视频课程

热门文章

  1. WordPress无插件实现主题彩色标签云的N种方法总结
  2. win10系统升级后触摸板点击没反应
  3. 仿bilibili微信小程序3
  4. 24岁想学插画来得及吗?零基础学插画需要了解这些
  5. 10个实用技巧让你的 Vue 代码更优雅
  6. 微信开放平台开发第三方授权登陆(三):Android客户端
  7. 元素显示类型-快元素、行内元素、行内快元素、盒子模型以及元素类型相互转换
  8. 对电影制作是一大福音!Recycle-GAN 研发出能简单转换影像新技术
  9. 走完离职流程心力交瘁,血泪教训:年终奖兑换期权要慎重,期权变现有风险,加班认定最管用的是加班申请记录!...
  10. 【GT跑车】GT跑车是什么意思 GT跑车有哪些