CentOS7 搭建LNMP
使用CentOS 1708,其实就是RHEL 7.4,使用YUM搭建LNMP环境(Linux、Nginx、MariaDB、PHP),全部使用新版组件,比如Nginx 1.12.2、MariaDB 10.2,PHP 7.1,并运行wordpress
环境配置
关闭selinux vi /etc/sysconfig/selinux SELINUX=disabled SELINUXTYPE=disabled 执行setenforce 0 关闭防火墙 systemctl stop firewalld systemctl disable firewalld 添加epel附加源 yum install epel-release yum update 安装常用组件 yum install zip unzip wget net-tools gcc automake autoconf libtool make gcc-c++ libmcrypt-devel mhash-devel libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel libidn libidn-devel openssl openssl-devel
安装Nginx
vi /etc/yum.repos.d/nginx.repo 添加 [nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/7/$basearch/ gpgcheck=0 enabled=1 yum install nginx #安装nginx systemctl start nginx 开启nginx服务 systemctl enable nginx 设置HTTP自启
测试
安装MariaDB
vi /etc/yum.repos.d/mariadb.repo 添加 [mariadb] name=MariaDB baseurl=http://yum.mariadb.org/10.2/centos7-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1 yum install MariaDB-server MariaDB-client #安装mariadb systemctl start mariadb.service 开启mariadb服务 systemctl enable mariadb.service 设置DB自启
配置数据库
mysql_secure_installation Enter current password for root (enter for none): 回车 Set root password? [Y/n] y New password:123456 Re-enter new password:123456 Remove anonymous users? [Y/n] y Disallow root login remotely? [Y/n] y Remove test database and access to it? [Y/n] y Reload privilege tables now? [Y/n] y mysql -u root -p create database wp; 创建数据库 grant all on wp.* to 'wp' identified by 'vmos'; 用户名为wp,密码为vmos flush privileges; 刷新权限 quit
安装PHP
安装webtatic源 rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm 安装PHP7.x yum install php71w-common php71w-fpm php71w-gd php71w-opcache php71w-pecl-imagick php71w-gd php71w-process php71w-mysqlnd php71w-mcrypt php71w-intl php71w-imap php71w-odbc php71w-mbstring php71w-recode php71w-soap php71w-pdo php71w-pecl-redis php71w-pear php71w-pecl-memcached php71w-devel php71w-xml php71w-xmlrpc systemctl start php-fpm 开启fpm服务 systemctl enable php-fpm 设置fpm自启
测试
配置php
vi /etc/php.ini date.timezone = PRC
配置fpm (Nginx服务器只会响应静态请求,所以需要配合php-fpm来解析php网页的动态请求)
vi /etc/php-fpm.d/www.conf 修改 user = nginx group = nginx
配置nginx
vi /etc/nginx/nginx.conf在最后一行看到include /etc/nginx/conf.d/*.conf; 然后 vi /etc/nginx/conf.d/default.conf 在location的index中添加 index.php 再下面添加 location ~ \.php$ { root /usr/share/nginx/html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
测试
增加测试页
vi /usr/share/nginx/html/info.php 添加 <?php phpinfo(); ?>
重启服务
systemctl restart php-fpm systemctl restart nginx
测试
安装WordPress
rm -rf /usr/share/nginx/html/index.html #移除默认nginx首页 cd /root/ && wget https://wordpress.org/latest.tar.gz tar -xvzf latest.tar.gz mv wordpress/* /usr/share/nginx/html/ #复制到webroot路径 chown -R nginx:nginx /usr/share/nginx/html/ #设置帐户在webroot路径权限 chmod -R 755 /usr/share/nginx/html/ #设置webroot路径权限
安装phpMyAdmin
wget https://files.phpmyadmin.net/phpMyAdmin/4.7.7/phpMyAdmin-4.7.7-all-languages.zip unzip phpMyAdmin-4.7.7-all-languages.zip mkdir /usr/share/nginx/html/phpmyadmin #webroot创建phpmyadmin路径 mv phpMyAdmin-4.7.7-all-languages/* /usr/share/nginx/html/phpmyadmin/ #将解压好的文件拷贝到webroot路径
配置phpmyadmin
cd /usr/share/nginx/html/phpmyadmin/ cp config.sample.inc.php config.inc.php vi config.inc.php 修改 $cfg['blowfish_secret'] = ‘vm0SteCH,c0M@VMoSTECh.cN@vM0sTecH’;
vi /etc/php.ini 修改 session.save_path = "/var/lib/php/session/" mkdir /var/lib/php/session chmod -R 777 /var/lib/php/session
测试
输入MariaDB 用户名root 密码123456登录即可
本站所有文章均可随意转载,转载时请保留原文链接及作者。