LNMP是指一组通常一起使用来运行动态网站或者服务器的自由软件名称首字母缩写。L指Linux ,N指Nginx,M一般指MySQL,也可以指MariaDB,P一般指PHP,也可以指Perl或Python。
LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构。
这四种软件均为免费开源软件,组合到一起,成为一个免费、高效、扩展性强的网站服务系统。
首先,浏览器发送http request请求到服务器(Nginx),服务器响应并处理web请求,将一些静态资源(CSS,图片,视频等)保存服务器上,然后将php脚本通过接口传输协议(网关协议)PHP-FCGI(fast-cgi)传输给PHP-FPM(进程管理程序),PHP-FPM不做处理,然后PHP-FPM调用PHP解析器进程,PHP解析器解析php脚本信息。PHP解析器进程可以启动多个,进行并发执行。然后将解析后的脚本返回到PHP-FPM,PHP-FPM再通过fast-cgi的形式将脚本信息传送给Nginx.服务器再通过Http response的形式传送给浏览器。浏览器再进行解析与渲染然后进行呈现。
部署环境:
最好是双核,硬盘大与20G。
Mysql5.7源码包下载地址
mkdir /usr/local/lnmp/
tar zxf mysql-boost-5.7.17.tar.gz
yum install gcc gcc-c++ ncurses-devel bison -y
yum install cmake-2.8.12.2-4.el6.x86_64.rpm -y
cd mysql-5.7.17/
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql -DMYSQL_DATADIR=/usr/local/lnmp/mysql/data -DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH_BOOST=boost/boost_1_59_0/
make && make install
groupadd -g 27 mysql
useradd -u 27 -g 27 mysql -s /sbin/nologin
vim ~/.bash_profile
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin
source ~/.bash_profile
cd support-files/
cp my-default.cnf /etc/my.cnf
vim /etc/my.cnf
basedir = /usr/local/lnmp/mysql
datadir = /usr/local/lnmp/mysql/data
# port = .....
# server_id = .....
socket = /usr/local/lnmp/mysql/data/mysql.sock
chown root.mysql /usr/local/lnmp/mysql -R
[root@server1 support-files]# cd /usr/local/lnmp/mysql/support-files/
[root@server1 support-files]# cp mysql.server /etc/init.d/mysqld
[root@server1 support-files]# chown root.root /etc/init.d/mysqld
[root@server1 support-files]# ll /etc/init.d/mysqld
-rwxr-xr-x 1 root root 10916 Apr 24 18:13 /etc/init.d/mysqld
mysqld --user=mysql --initialize #初始化后最后会给出初始的root密码
chown mysql.mysql /usr/local/lnmp/mysql/data/ -R
/etc/init.d/mysqld start
[root@server1 support-files]# mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root: # 这里输入初始化给的初始密码
The existing password for the user account root has expired. Please set a new password.
New password:
Re-enter new 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: No
Using existing password for root.
Change the password for root ? ((Press y|Y for Yes, any other key for No) :
... skipping.
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) :
... skipping.
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) :
... skipping.
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) :
... 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) :
... skipping.
All done!
mysql -p
PHP官网:
https://www.php.net/
大家可以在PHP官网下载源码包
需要解决的依赖:
gmp-devel-4.3.1-7.el6_2.2.x86_64
gmp-devel-4.3.1-7.el6_2.2.x86_64
libmcrypt-
gmp-devel-4.3.1-7.el6_2.2.x86_64
freetype-devel
libpng-devel-1.2.49-1.el6_2.x86_64
libjpeg-turbo-devel-1.2.1-1.el6.x86_64
libcurl-devel
openssl-devel
libxml2-devel
yum安装:
yum install -y net-snmp-devel libmcrypt-* gmp-devel-4.3.1-7.el6_2.2.x86_64 freetype-devel 2:libpng-devel-1.2.49-1.el6_2.x86_64 libjpeg-turbo-devel-1.2.1-1.el6.x86_64 libcurl-devel openssl-devel libxml2-devel
tar jxf php-5.6.35.tar.bz2
cd cd php-5.6.35
./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc --with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir --with-png-dir --with-jpeg-dir --with-freetype-dir --with-gmp --with-gettext --with-pear --enable-mysqlnd --enable-inline-optimization --enable-soap --enable-ftp --enable-sockets --enable-mbstring --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-mcrypt --with-mhash
make && make install
[root@server1 php]# cd /usr/local/lnmp/php/etc/
[root@server1 etc]# ls
pear.conf php-fpm.conf.default
useradd nginx
[root@server1 php]# cd /usr/local/lnmp/php/etc/
[root@server1 etc]# ls
pear.conf php-fpm.conf.default
[root@server1 etc]# cp php-fpm.conf.default php-fpm.conf
[root@server1 etc]# vim php-fpm.conf
25 pid = run/php-fpm.pid
[root@server1 fpm]# cp ~/php-5.6.35/php.ini-production /usr/local/lnmp/php/etc/php.ini
[root@server1 fpm]# vim /usr/local/lnmp/php/etc/php.ini
[root@server1 php-5.6.35]# cd ~/php-5.6.35/sapi/fpm/
[root@server1 fpm]# cp init.d.php-fpm /etc/init.d/php-fpm
[root@server1 fpm]# chmod +x /etc/init.d/php-fpm、
/etc/init.d/php-fpm start