首页 » Linux » 正文

LNMP环境搭建(一)

RPM包方式安装

1、更换yum为阿里云源,提高安装速度

mkdir -p /etc/yum.repos.d/bak
mv /etc/yum.repos.d/* /etc/yum.repos.d/bak
touch /etc/yum.repos.d/aliyun-base.repo
touch /etc/yum.repos.d/aliyun-epel.repo
###BASE源
cat >> /etc/yum.repos.d/aliyun-base.repo << EOF
[base]
name=Centos-7-Base
baseurl=https://mirrors.aliyun.com/centos/7.7.1908/os/x86_64/
gpgcheck=0
enabled=1

#releasedupdates
[updates]
name=Centos-7-Updates
baseurl=https://mirrors.aliyun.com/centos/7.7.1908/updates/x86_64/
gpgcheck=0
enabled=1
###EPEL源
#additionalpackagesthatmaybeuseful
[extras]
name=Centos-7-Extras
baseurl=https://mirrors.aliyun.com/centos/7.7.1908/extras/x86_64/
gpgcheck=0
enabled=1
EOF

cat >> /etc/yum.repos.d/aliyun-epel.repo << EOF
[EPEL]
name=aliyun_epel
baseurl=https://mirrors.aliyun.com/epel/7/x86_64/
enabled=1
gpgcheck=0
EOF

安装依赖库

yum install -y wget git net-tools vim gcc gcc-c++ make \
zlib zlib-devel freetype-devel bzip2 bzip2-devel curl curl-devel \
libXpm libXpm-devel t1lib t1lib-devel openssl openssl-devel pcre pcre-devel \
autoconf automake libtool yasm libxml2  glibc-headers \
libxml2-devel libticonv libticonv-devel libwebp libwebp-devel \
libjpeg libjpeg-devel libtiff libtiff-devel libpng libpng-devel \
freetype freetype-devel fontconfig fontconfig-devel gd gd-devel \
libssh2 libssh2-devel ncurses-devel libtirpc libtirpc-devel libaio libaio-devel \
glibc glibc-devel ncurses-devel ncurses python-devel xz-devel xz lz4-devel \
harfbuzz-devel harfbuzz systemd-devel openldap openldap-devel \
openldap.i686 openldap-devel.i686

1、安装Mysql

wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
rpm -ivh mysql80-community-release-el7-3.noarch.rpm

查看启用的MySql源

yum repolist all | grep mysql

禁用不需要的源

yum install yum-utils -y (安装yum-config-manager插件)
yum-config-manager --disable mysql80-community

启用需要的源

yum-config-manager --enable mysql57-community

或者直接编辑mysql-commuity.repo文件启用mysql5.7的源

安装mysql 5.7

yum install mysql-server mysql mysql-devel -y

启动mysql

systemctl  start mysqld
systemctl enable mysqld

查看mysql初始密码

grep "password" /var/log/mysqld.log

用mysql -uroot -p登陆后修改密码(需符合复杂性要求)

mysql>ALTER USER 'root'@'localhost' IDENTIFIED BY 'yourpassword';
mysql> FLUSH PRIVILEGES;

显示已经安装的插件

mysql> SHOW PLUGINS;

卸载密码复杂性要求插件

UNINSTALL PLUGIN validate_password;

2、安装PHP

安装php的源

wget   https://mirror.webtatic.com/yum/el7/webtatic-release.rpm 
yum localinstall webtatic-release.rpm  -y
###已经启用了阿里云的epel源
rm -f /etc/yum.repos.d/epel.repo
rm -f /etc/yum.repos.d/epel-testing.repo

查看已经安装的php版本

rpm -qa|grep php

安装PHP及常用扩展

yum install -y php72w-fpm php72w-mysqlnd php72w-opcache php72w-gd \
php72w-pdo php72w-devel php72w-cli php72w-common php72w-xml \
php72w-mbstring php72w-ldap php72w-intl php72w-bcmath php72w-pear \
php72w-tidy php72w-snmp php72w-soap php72w-pecl-apcu php72w-pecl-apcu-devel \
php72w-pecl-redis php72w-pecl-memcached php72w-pecl-geoip php72w-imap
 
或者用yum install php72w-* --exclude=php72w-mysql来把所有的php的扩展等全安装了

或者安装常用的一些扩展

yum install -y php72w-fpm php72w-mysqlnd php72w-opcache php72w-gd \
php72w-pdo php72w-devel php72w-cli php72w-common php72w-xml \
php72w-mbstring php72w-ldap 

3、安装Nginx

touch  /etc/yum.repos.d/nginx.repo 

输入以下内容

[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key

安装nginx

yum install nginx -y

打开vim /etc/nginx/conf.d/default.conf文件,在server字段中添加以下内容后保存退出

   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;
    }

启动nginx

systemctl  start  nginx
systemctl enable  nginx

打开防火墙

firewall-cmd    --permanent    --add-service=http
firewall-cmd    --permanent   --add-service=https
firewall-cmd    --reload

打开/etc/php-fpm.d/www.conf文件,把里面的user和group两项中的用户名和组名修改成nginx

启动PHP

systemctl   start php-fpm
systemctl   enable php-fpm

测试是否安装成功

echo '<?php phpinfo(); ?>' > /usr/share/nginx/html/index.php

打开网页显示php配置信息即为安装成功

发表评论