首页 » Apache » 正文

LAMP环境搭建(一)

RPM包方式安装

1、更换yum源到aliyun

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

2、安装依赖库

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

3、安装apache

yum install httpd -y
systemctl start httpd
systemctl enable httpd

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

4、安装MySQL(Mariadb)

MySQL安装参考链接:https://yisca.cn/?p=573
###安装Mariadb
touch /etc/yum.repos.d/mariadb.repo
cat >> /etc/yum.repos.d/mariadb.repo << EOF
[mariadb]
name=mariadb
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mariadb/yum/10.3/centos7-amd64
enabled=1
gpgcheck=0
EOF

yum install mariadb mariadb-server mariadb-devel -y
systemctl start mariadb

###更改root密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
FLUSH PRIVILEGES;

5、安装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 mod_php72w 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

6、修改Apache配置文件

cd /etc/httpd/conf
mv httpd.conf httpd.conf.bak
cat httpd.conf.bak |grep -v "#" |grep -v "^s*$" >> httpd.conf
#grep -v "^s*$"表示去除空行 

sed -i 's/index.html/index.html index.php/g' httpd.conf
systemctl restart httpd

touch /var/www/html/index.php
cat >> /var/www/html/index.php << EOF
<?php
phpinfo();
?>
EOF
浏览器打开显示phpinfo页面即可表示安装成功,如果出现没有解析PHP文件的情况,打开httpd.conf文件,找到 AddType application/x-gzip .gz .tgz ,在下面一行添加 AddType application/x-httpd-php .php 
cd /etc/httpd/conf
sed -i '/AddType application\/x-gzip .gz .tgz/a\    AddType application\/x-httpd-php .php' httpd.conf
7、安装wordpress测试
mysql -uroot -p123456 << EOF
CREATE USER 'wordpress'@'localhost' IDENTIFIED BY '123456';
CREATE DATABASE wordpress CHARSET 'utf8';
GRANT ALL ON wordpress.* TO 'wordpress'@'localhost' IDENTIFIED BY '123456';
FLUSH PRIVILEGES;
EOF

wget https://downloads.wordpress.org/release/zh_CN/wordpress-5.3.zip
unzip wordpress-5.3.zip
cd wordpress
mv -f * /var/www/html/

chown apache:apache -Rf /var/www/html/
chmod -Rf 755 /var/www/html

###如果提示没有写入权限关闭selinux即可
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g'  /etc/selinux/config

###或者执行
chcon -R -t httpd_sys_content_rw_t /var/www/html


/usr/sbin/sestatus 可以查看selinux运行状态

发表评论