部署LAMP平台及遇到的问题

本文详细介绍了如何在CentOS 7上部署LAMP环境,包括安装Linux、Apache、MariaDB和PHP,以及配置Apache、防火墙、数据库、WordPress,并解决遇到的MySQL连接错误和seLinux权限问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

LAMP = Linux + Apache + MySQL/MariaDB + PHP/Python

操作步骤:

第01步:安装CentOS Linux 7并 做一个快照

第02步:安装MariaDB

yum install -y mariadb mariadb-server

第03步::yum安装httpd。

yum install httpd httpd-devel

第04步:安装编译器gcc

yum install -y gcc

第05步:编译安装php。(PHP7.3.5版本太高可能有问题)

yum -y install libxml2 libxml2-devel

wget https://www.php.net/distributions/php-7.3.5.tar.gz

tar xvf php-7.3.5.tar.gz

cd php-7.3.5

./configure --with-apxs2=/usr/bin/apxs --with-pdo-mysql --with-mysqli --with-zlib --without-pear --disable-phar

make

make install

成功编译安装完成后,再安装pear

wget  http://pear.php.net/go-pear.phar

/usr/local/bin/php go-pear.phar

cp php.ini-production /usr/local/php/php.ini

第06步:安装完成后配置Apache

vim /etc/httpd/conf/httpd.conf

      加入:

<FilesMatch \.php$>

         SetHandler application/x-httpd-php

</FilesMatch>

   :/Indexes查找并删除Indexes(可不删除,但在生产环境中需要删除,否则别人能看到其他文件内容,不安全)

<IfModule dir_module>

  搜索index.html,在其后添加index.php

:wq保存退出

第07步:配置一个虚拟主机

vi /etc/httpd/conf.d/1.conf

复制以下内容

<VirtualHost *:80>

      DocumentRoot     /var/www/html

      ServerName          localhost

</VirtualHost>

      退出,重启服务

systemctl restart httpd

写一个简单的php网页,测试php是否可用

vi /var/www/html/index.php

<?php

     echo phpinfo();

?>

打开浏览器访问

http://localhost/index.php

      能看到PHP相关文档即为成功

第08步:防火墙的处理

firewall-cmd --add-port=3306/tcp --permanent

firewall-cmd --add-port=80/tcp --permanent

firewall-cmd --reload

第09步:数据库设置

systemctl start mariadb

mysqladmin -u root -p password '123456'

mysql -u root -p

>create database wordpress;

>grant all privileges on wordpress.* to tom@localhost identified by 'Ab123456';

>grant all privileges on wordpress.* to tom@127.0.0.1 identified by 'Ab123456';

>flush privileges;

>exit;

第09步:安装Wordpress

wget https://wordpress.org/latest.tar.gz

[tar xvf wordpress-4.9.4-zh_CN.tar.gz(中文版)]

tar xvf wordpress-xxx.tar.gz

cp -r wordpress/* /var/www/html/

restorecon -Rv /var/www/html

chown -R apache:apache /var/www/html

第10步:访问网络配置

setsebool -P httpd_can_network_connect 1

setsebool -P httpd_can_network_connect_db 1

restorecon -rv /var/www/html

ausearch -c 'httpd' --raw | audit2allow -M my-httpd

semodule -i my-httpd.pp

第11步:用浏览器访问http://localhost/

数据库名称:wordpress

数据库用户:tom

数据库密码:Ab123456

主机地址:127.0.0.1

前缀:wp_

在网站内配置以上信息

将生成的配置拷贝下来

vi /var/www/html/wp-config.php

粘贴

:wq保存退出

完成上面的操作后,再点击生成网站,进入wordpress

第12步:安装数据库管理工具phpmyadmin

tar xvf phpMyAdmin-xxxx.tar.gz

cd phpMyAdminxxxx

cp config.sample.inc.php config.inc.php

vim config.inc.php

[blowfish_secret]='1234567890abcdefghijklmnopqrstuvwxyz'

$cfg['Servers'][$i]['controlhost'] = 'localhost';

$cfg['Servers'][$i]['controlport'] = '3306';

$cfg['Servers'][$i]['controluser'] = 'root';

$cfg['Servers'][$i]['controlpass'] = '123456';

:wq

cd

mkdir /var/www/html/phpmyadmin

cp -r /root/phpMyAdmin-4.8.3-all-languages/* /var/www/html/phpmyadmin

在clone机上浏览器中访问

http://192.168.127.131/phpmyadmin  访问数据库管理工具

用户名:root

密码:123456

可查看mysql和wordpress等数据库


出现的问题

1.出现的问题:

mysql数据库连接失败

解决方法:

//进入数据库

Mysql –u root mysql

//设置数据库新密码

MariaDB[(none)]> UPDATE mysql.user SET password = PASSWORD(‘输入你自己的新密码’) WHERE USER = ‘root’;  

//更新数据库

MariaDB[(none)]>FLUSH PRIVILEGES;

[当时的我是直接quit; 退出了数据库,然后systemctl restar mariadb 重新启动数据库的]

然后 我进来了

但是,原先是数据库是空密码的,也就是说我在mysqladmin –u root –p password ‘123456’之后的Enter password是直接回车的,不需要任何密码!而我将123456输入了进去,所以导致它报错了

 

2. 出现的问题:

ausearch -c 'httpd' --raw | audit2allow -M my-httpd

提示信息:Nothing to do

然后my-httpd.pp 也Failed

不知道什么问题,重新输入命令就可以了……

有时不论怎么输入都提示Nothing to do

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值