Centos7安装LAMP教程

一、关闭防火墙

[root@localhost ~]# systemctl stop firewalld    // 临时关闭
[root@localhost ~]# systemctl disable firewalld   //禁止开机启动
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

二、安装Apache、PHP、Mysql

1、安装apache
[root@localhost ~]# yum -y install httpd

直到返回

......
Installed:
  httpd.x86_64 0:2.4.6-40.el7.centos.4                                          

Dependency Installed:
  apr.x86_64 0:1.4.8-3.el7                      apr-util.x86_64 0:1.5.2-6.el7   
  httpd-tools.x86_64 0:2.4.6-40.el7.centos.4    mailcap.noarch 0:2.1.41-2.el7   

Complete!

表示安装成功
2.安装php
安装php72w,是需要配置额外的yum源地址的

[root@localhost ~]# yum install epel-release -y
[root@localhost ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

安装拓展包

[root@localhost ~]# yum -y install php72w php72w-cli php72w-fpm php72w-common php72w-devel

或者豪华版本

[root@localhost ~]# yum -y install php72w php72w-cli php72w-fpm php72w-common php72w-devel php72w-embedded php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml
Dependency Installed:
  autoconf.noarch 0:2.69-11.el7                           automake.noarch 0:1.13.4-3.el7                  
  libargon2.x86_64 0:20161029-3.el7                       m4.x86_64 0:1.4.16-10.el7                       
  pcre-devel.x86_64 0:8.32-17.el7                         perl.x86_64 4:5.16.3-294.el7_6                  
  perl-Carp.noarch 0:1.26-244.el7                         perl-Data-Dumper.x86_64 0:2.145-3.el7           
  perl-Encode.x86_64 0:2.51-7.el7                         perl-Exporter.noarch 0:5.68-3.el7               
  perl-File-Path.noarch 0:2.09-2.el7                      perl-File-Temp.noarch 0:0.23.01-3.el7           
  perl-Filter.x86_64 0:1.49-3.el7                         perl-Getopt-Long.noarch 0:2.40-3.el7            
  perl-HTTP-Tiny.noarch 0:0.033-3.el7                     perl-PathTools.x86_64 0:3.40-5.el7              
  perl-Pod-Escapes.noarch 1:1.04-294.el7_6                perl-Pod-Perldoc.noarch 0:3.20-4.el7            
  perl-Pod-Simple.noarch 1:3.28-4.el7                     perl-Pod-Usage.noarch 0:1.63-3.el7              
  perl-Scalar-List-Utils.x86_64 0:1.27-248.el7            perl-Socket.x86_64 0:2.010-4.el7                
  perl-Storable.x86_64 0:2.45-3.el7                       perl-Test-Harness.noarch 0:3.28-3.el7           
  perl-Text-ParseWords.noarch 0:3.29-4.el7                perl-Thread-Queue.noarch 0:3.02-2.el7           
  perl-Time-HiRes.x86_64 4:1.9725-3.el7                   perl-Time-Local.noarch 0:1.2300-2.el7           
  perl-constant.noarch 0:1.27-2.el7                       perl-libs.x86_64 4:5.16.3-294.el7_6             
  perl-macros.x86_64 4:5.16.3-294.el7_6                   perl-parent.noarch 1:0.225-244.el7              
  perl-podlators.noarch 0:2.5.1-3.el7                     perl-threads.x86_64 0:1.87-4.el7                
  perl-threads-shared.x86_64 0:1.43-6.el7                

Complete!

出现这个表示安装成功,安装完成后,启动服务

[root@localhost ~]# systemctl enable php-fpm.service # 设置开机自动启动
Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.
[root@localhost ~]# systemctl start php-fpm.service # 启动php

3.安装Mysql

[root@localhost ~]# yum -y install mysql

返回

Installed:
  mariadb.x86_64 1:5.5.64-1.el7                                                                            

Dependency Updated:
  mariadb-libs.x86_64 1:5.5.64-1.el7                                                                       

Complete!

7.2版本的Centos已经把mysql更名为mariadb,表示安装成功!
4.安装 mysql-server

[root@localhost ~]# yum -y install mysql-server
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirror.lzu.edu.cn
 * extras: mirrors.nwsuaf.edu.cn
 * updates: mirrors.tuna.tsinghua.edu.cn
No package mysql-server available.
Error: Nothing to do

返回错误!!!
分析解决方案
CentOS 7+ 版本将MySQL数据库软件从默认的程序列表中移除,用mariadb代替了,entos7配置教程上,大多都是安装mariadb,因为centos7默认将mariadb视作mysql
因为mysqloracle收购后,原作者担心mysql闭源,所以又写了一个mariadb,这个数据库可以理解为mysql的分支。如果需要安装mariadb,只需通过yum就可。

有两种解决方案:

一是安装mariadb

[root@localhost ~]# yum install -y mariadb 

二是从官网下载mysql-server
我们采用第二种方案

[root@localhost ~]# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
[root@localhost ~]# rpm -ivh mysql-community-release-el7-5.noarch.rpm
[root@localhost ~]# yum install mysql-community-server

如果出现

-bash: wget: command not found

那么输入

[root@localhost ~]# yum install wget

当出现

Total download size: 547 k
Installed size: 2.0 M
Is this ok [y/d/N]:

输入y即可
然后出现

Is this ok [y/d/N]: y
...
Installed:
  wget.x86_64 0:1.14-18.el7_6.1                                                                            

Complete!

安装成功
然后重新输入

[root@localhost ~]# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
[root@localhost ~]# rpm -ivh mysql-community-release-el7-5.noarch.rpm
[root@localhost ~]# yum install mysql-community-server

然后需要确定,输入y回车即可

Install  3 Packages (+8 Dependent packages)

Total download size: 82 M
Is this ok [y/d/N]: 

一直选择输入 y ,有两次选择,直到返回:

Replaced:
  mariadb.x86_64 1:5.5.50-1.el7_2      mariadb-libs.x86_64 1:5.5.50-1.el7_2     

Complete!

安装成功
5.安装php-mysql

[root@localhost ~]# yum -y install php72w-mysql

直到返回

Installed:
  php72w-mysql.x86_64 0:7.2.22-1.w7                                                                        

Dependency Installed:
  php72w-pdo.x86_64 0:7.2.22-1.w7                                                                          

安装成功! ! !

三、安装基本常用扩展包

1、安装Apache扩展包

[root@localhost ~]# yum -y install httpd-manual mod_ssl mod_perl mod_auth_mysql

返回

......
Installed:
  httpd-manual.noarch 0:2.4.6-40.el7.centos.4                                   
  mod_ssl.x86_64 1:2.4.6-40.el7.centos.4                                        

Complete!

安装成功
2、安装Mysql扩展包

[root@localhost ~]# yum -y install mysql-connector-odbc mysql-devel libdbi-dbd-mysql

返回:

......
Dependency Installed:
  libdbi.x86_64 0:0.8.4-6.el7         libdbi-drivers.x86_64 0:0.8.3-16.el7     
  unixODBC.x86_64 0:2.3.1-11.el7     

Complete!

安装成功!!!

四、配置Apache、mysql开机启动

[root@localhost ~]# systemctl start httpd.service #启动apache
[root@localhost ~]# systemctl stop httpd.service #停止apache
[root@localhost ~]# systemctl restart httpd.service #重启apache
[root@localhost ~]# systemctl enable httpd.service #设置apache开机启动

如果是采用方法一安装的mariadb,安装完成以后使用下面的命令开启数据库服务:

#启动MariaDB

[root@localhost ~]# systemctl start mariadb.service   

#停止MariaDB

[root@localhost ~]# systemctl stop mariadb.service   

#重启MariaDB

[root@localhost ~]# systemctl restart mariadb.service  

#设置开机启动

[root@localhost ~]# systemctl enable mariadb.service  

重启对应服务

[root@localhost ~]# service mysqld restart # 重启数据库

[root@localhost ~]# service php-fpm start # 重启php

[root@localhost ~]# service httpd restart # 重启apache

五、配置Mysql

初次安装mysql是没有密码的,我们可以设置密码,mysql的默认账户为root、
也可以不设置,不设置就跳过这一步
设置 MySQL 数据 root 账户的密码:

[root@localhost ~]# mysql_secure_installation

当出现如下提示时候直接按回车:

Enter current password for root

出现如下再次回车:

Set root password? [Y/n]

出现如下提示输入你需要设置的密码,这里输入了root,输入密码是不显示的,回车后再输入一次确认:

New password:

接下来还会有四个确认,分别是:

Remove anonymous users? [Y/n]
Disallow root login remotely? [Y/n]
Remove test database and access to it? [Y/n]
Reload privilege tables now? [Y/n]

直接回车即可

六、测试环境

1、我们在浏览器地址栏输入http://localhost/如下图,说明我们的apache测试成功
在这里插入图片描述2.测试Php
进入apache的web根目录:/var/www/html 中写一个最简单的php测试页面

[root@localhost ~]# cd /var/www/html
[root@localhost html]# touch phpinfo-test.php
[root@localhost html]# vi phpinfo-test.php

进入到了控制模式之后按键盘字母 i 进入到编辑模式,将如下代码输入到文件中

<?php
 
echo "<title>Phpinfo Test.php</title>";
 
phpinfo()
 
?>

按 esc 退出编辑模式,回到控制模式,输入 :wq 然后回车,在浏览器中输入服地址http://localhost/phpinfo-test.php
出现下图则成功。

七、安装WordPress

1.创建数据库

# 登录数据库
[root@localhost]mysql -u root -p
Enter password:(输入你设置的root的密码,默认为空)
# 创建数据库
mysql>CREATE DATABASE wordpress;
# 创建数据库用户和密码(可设可不设)
mysql>CREATE USER wordpressuser@localhost IDENTIFIED BY 'wordress_password';
# 设置wordpressuser访问wordpress数据库权限(可设可不设)
mysql>GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost IDENTIFIED BY 'wordress_password';
# 刷新数据库设置
mysql>FLUSH PRIVILEGES;
# 退出数据库
mysql>exit

2.下载wordpress安装包:

[root@localhost ~]# cd ~
[root@localhost ~]# wget http://wordpress.org/latest.tar.gz

然后解压出来,拷贝到/var/www/html/wordpress目录:

# 解压wordpress
[root@localhost ~]# tar xzvf latest.tar.gz
# 拷贝到/var/www目录
[root@localhost ~]# sudo rsync -avP ~/wordpress/ /var/www/html/wordpress

如果出现的情况

[root@localhost ~]# sudo rsync -avP ~/wordpress/ /var/www/html/wordpress
-bash: rsync: command not found

那么输入

[root@localhost ~]# yum install rsync

当出现

Is this ok [y/d/N]: 

输入y

然后重新拷贝一遍

[root@localhost ~]# sudo rsync -avP ~/wordpress/ /var/www/html/wordpress

然后编辑wp-config.php文件:

# 切换到wordpress目录
[root@localhost]cd /var/www/html/wordpress
# 复制wp-config.php文件
[root@localhost wordpress]cp wp-config-sample.php wp-config.php
# 编辑wp-config.php文件
[root@localhost wordpress]sudo vim wp-config.php

如果出现

[root@localhost wordpress]# sudo vim wp-config.php
sudo: vim: command not found

输入

yum install vim

当出现

Is this ok [y/d/N]: 

输入y
然后重新输入

[root@localhost wordpress]# sudo vim wp-config.php

按i进入编辑模式
然后在配置文件里设置正确的值:

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'database_name_here'); 
/** MySQL database username */
define('DB_USER', 'username_here');
/** MySQL database password */
define('DB_PASSWORD', 'password_here');
/** MySQL hostname */
define('DB_HOST', 'localhost');

database_name_here输入你创建的数据库名字(一般为wordpress)
username_here输入你的数据库用户名字(默认root)
password_here输入你设置数据库用户密码(默认为空)
localhost一般不用修改
输入完以后按Esc再输入:wq敲回车退出编辑模式
然后输入http://localhost/wordpress进入此页面

在这里插入图片描述
如果出现的 不是此页面,出现
您的PHP似乎没有安装运行WordPress所必需的MYSQL扩展.
解决方法

[root@localhost]# vi /etc/php.ini

在php.ini中寻找合适的地方添加以下代码

extension=mysql.so

写完以后保存退出并重启服务器,如不能登录http://localhost/wordpress请查看是否关闭防火墙,及是否打开apache和数据库
打开以后刷新页面就可以了

给wordpress设置权限,解除下载插件或主题等需要FTP凭证的问题
在wordpress的wp-config.php添加以下代码
查找wp-config.php的路径

[root@localhost]# find / -name 'wp-config.php'

出现

[root@localhost ~]#  find / -name 'wp-config.php'
/var/www/html/wordpress/wp-config.php

保存这个路径用vim编辑

[root@localhost ~]# vim /var/www/html/wordpress/wp-config.php
define("FS_METHOD", "direct");
define("FS_CHMOD_DIR", 0777);
define("FS_CHMOD_FILE", 0777);

下载插件等出现Installation failed: Could not create directory时
方案一、因为是用户没有权限,所以可以直接设置目录访问权限为777,不建议这样操作,这样操作不太安全

[root@localhost ~]# chmod -R 777 /var/www/html/wordpress  (WordPress的目录)

方案二、安装的主题或者插件用的FTP为 vsftpd ,服务器为 Apache2,所以直接授权apache访问权限即可。

通过chown设置权限组的权限

[root@localhost ~]# chown -R apache:root /var/www/html/wordpress     (WorldPress的目录)

刷新页面即可

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值