搭建LNMP
1 需要3个服务共同搭建lnmp
nginx
mysql
php
首先做nginx服务并验证
先搭建nginx所需要的实验环境
安装nginx依赖包
yum -y install openssl openssl-devel install zlib zlib-devel pcre pcre-devel
2 下载nginx包到/usr/local/src
cd /usr/local/src
用rz调用所需要的包
解包,-C并指定到/usr/local/src
tar -zxvf nginx-1.12.2.tar.gz -C /usr/local/src
cd /usr/local/src/nginx-1.12.2
创建data server
mkdir -p /data/server
配置./configure
./configure --prefix=/data/server/nginx
make -j4 && make install
3设置账号
groupadd nginx
useradd -M -g nginx -s /sbin/nologin nginx
cd /usr/local/nginx/conf
vim nginx.conf,设置user参数如下:
user nginx nginx
其他不需要该
4 vim /lib/systemd/system/nginx.service
并改其内容
[uint]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/data/server/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
5 启动nginx服务
systemctl start nginx.service
6浏览网页并输入ip进行验证
Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.
Thank you for using nginx.
出现上述网页即为成功
搭建mysql实验
- 卸载已有mysql
查看是否已安装mysql:
rpm -qa mysql
有则卸载:
rpm -e --nodeps 文件名称
是否存在与mysql相关的文件或目录:
whereis mysql
是则删除。
查看是否存在mariadb:
rpm -qa | grep mariadb
存在则卸载:
rpm -e --nodeps 文件名 //文件名是上一个命令查询结果
存在/etc/my.cnf,则需要先删除:
rm /etc/my.cnf
- 安装编译mysql需要的依赖包
yum install libevent* libtool* autoconf* libstd* ncurse* bison* openssl*
- 安装cmake(mysql5.5之后需要用cmake支持编译安装)
查看是否已安装cmake:
rpm -qa cmake
没有则下载编译安装:
cd /usr/local/src
wget http://www.cmake.org/files/v2.8/cmake-2.8.12.1.tar.gz
tar -xf cmake-2.8.12.1.tar.gz
cd cmake-2.8.12.1
./configure
make
make install
检查cmake是否安装成功:
cmake --version
- 下载mysql包并解压(到/usr/local/src目录)
cd /usr/local/src
wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.38.tar.gz
tar -zxvf mysql-5.6.38.tar.gz
- 编译安装(到/usr/local/mysql目录)
cd mysql-5.6.38
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
6执行make -j4 make install安装
7配置mysql
groupadd mysql
useradd -M -g mysql -s /sbin/nologin mysql
chown -R mysql:mysql /data/server/mysql
8 cd /data/server/mysql/scripts
./mysql_install_db --basedir=/data/server/mysql --datadir=/usr/local/mysql/data --user=mysql
9 vi或vim到mysql服务中
vi /lib/systemd/system/mysql.service
10文件内容修改
[Unit]
Description=mysq
After=network.target
[Service]
Type=forking
ExecStart=/data/server/mysql/support-files/mysql.server start
]ExecStart=/data/server/mysql/support-files/mysql.server start
ExecStop=/data/server/mysql/support-files/mysql.server stop
ExecRestart=/data/server/mysql/support-files/mysql.server restart
ExecReload=/data/server/mysql/support-files/mysql.server reload
PrivateTmp=true
[Install]
WantedBy=multi-user.target
10启动mysql
systemctl start mysql.service
11.查看是否启动成功:ps aux | grep mysq
三.安装PHP,先找到php所需要的依赖关系的安装包
并用yum安装
1 yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel readline readline-devel libxslt libxslt-devel
发现其中有一个包需要手动编译安装
libmcrypt和libmcrypt-devel
进行手动安装即可
cd /usr/local/src/
用rz进行调用解包并用-C指定到/usr/local/src
tar -zxvf libmcrypt-2.5.8.tar.gz -c/usrlocal/src
cd /usr/local/src/ libmcrypt-2.5.8
用./configure 配置
./configure --prefix=/data/server/libmcrypt
用make -j4 && make install 来进行编译安装
make -j4 && make instal
2. 下载php包并解压
cd /usr/local/src
tar -zxvf php-7.2.0.tar.gz -C /usr/local/src
3编译并安装
cd php-7.2.0
./configure --prefix=/data/server/php --disable-fileinfo --enable-fpm --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-openssl --with-zlib --with-curl --enable-ftp --with-gd --with-xmlrpc --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-gd-native-ttf --enable-mbstring --with-mcrypt=/usr/local/libmcrypt --enable-zip --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-mysql-sock=/var/lib/mysql/mysql.sock --without-pear --enable-bcmath
然后用make -j4 && make install
make -j4 && make install
4 将php包解压目录中的配置文件放置到正确位置(configure命令中的–with-config-file-path设置的位置)
cp php.ini-development /etc/php.ini
5. 创建并设置php-fpm运行账号
groupadd www-data
useradd -M -g www-data -s /sbin/nologin www-data
cd /data/serve/php/etc
cp php-fpm.conf.default php-fpm.conf
vi php-fpm.conf
6
发现搜索不到“user”(设置运行账号的位置),但发现文件的最后一行:
cd php-fpm.d
cp www.conf.default www.conf
vi www.conf
搜索“user”设置运行账号:
user=www-data
group=www-data
7配置nginx支持php
vi /data/server/nginx/conf/nginx.conf
location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
d
o
c
u
m
e
n
t
r
o
o
t
document_root
documentrootfastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
8重启nginx服务
systemctl start nginx.service
9 启动php-fpm:
systemctl start php-fpm.service
查看是否启动成功:
ps aux | grep php-fpm
10写个脚本并验证
<?php
phpinfo();
PHP logo
PHP Version 7.2.0
System Linux localhost.localdomain 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64
Build Date Dec 24 2019 21:35:33
Configure Command ‘./configure’ ‘–prefix=/data/server/php’ ‘–disable-fileinfo’ ‘–enable-fpm’ ‘–with-config-file-path=/etc’ ‘–with-config-file-scan-dir=/etc/php.d’ ‘–with-openssl’ ‘–with-zlib’ ‘–with-curl’ ‘–enable-ftp’ ‘–with-gd’ ‘–with-xmlrpc’ ‘–with-jpeg-dir’ ‘–with-png-dir’ ‘–with-freetype-dir’ ‘–enable-gd-native-ttf’ ‘–enable-mbstring’ ‘–with-mcrypt=/usr/local/libmcrypt’ ‘–enable-zip’ ‘–enable-mysqlnd’ ‘–with-mysqli=mysqlnd’ ‘–with-pdo-mysql=mysqlnd’ ‘–with-mysql-sock=/var/lib/mysql/mysql.sock’ ‘–without-pear’ ‘–enable-bcmath’
Server API FPM/FastCGI
Virtual Directory Support disabled
Configuration File (php.ini) Path /etc
Loaded Configuration File /etc/php.ini
Scan this dir for additional .ini files /etc/php.d
Additional .ini files parsed (none)
PHP API 20170718
PHP Extension 20170718
Zend Extension 320170718
Zend Extension Build API320170718,NTS
PHP Extension Build API20170718,NTS
Debug Build no
Thread Safety disabled
Zend Signal Handling enabled
Zend Memory Manager enabled
Zend Multibyte Support provided by mbstring
IPv6 Support enabled