LAMP搭建

一、准备好一台虚拟机(lamp.index.cox),进行时间同步

[root@lamp ~]# systemctl restart chronyd
[root@lamp ~]# systemctl enable chronyd
[root@lamp ~]# hwclock -w

二、下载安装httpd,mariadb mariadb-server

[root@lamp ~]# yum -y install httpd mariadb mariadb-server
[root@lamp ~]# systemctl restart httpd
[root@lamp ~]# systemctl enable httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.ser
[root@lamp ~]# systemctl restart mariadb
[root@lamp ~]# systemctl enable mariadb
Created symlink /etc/systemd/system/mysql.service → /usr/lib/systemd/
Created symlink /etc/systemd/system/mysqld.service → /usr/lib/systemd
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.

三、设置mariadb

[root@lamp ~]# mysql_secure_installation 

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password or using the unix_socket ensures that nobod
can log into the MariaDB root user without the proper authorisation.

You already have your root account protected, so you can safely answe

Switch to unix_socket authentication [Y/n] //切换到unix_socket认证
Enabled successfully!
Reloading privilege tables..
 ... Success!


You already have your root account protected, so you can safely answe

Change the root password? [Y/n] y //修改root密码
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing an
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installatio
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y //删除匿名用户
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  T
ensures that someone cannot guess at the root password from the netwo

Disallow root login remotely? [Y/n] n //禁止root用户远程登录
 ... skipping.

By default, MariaDB comes with a database named 'test' that anyone ca
access.  This is also intended only for testing, and should be remove
before moving into a production environment.

Remove test database and access to it? [Y/n] y //删除测试数据库并访问它
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so f
will take effect immediately.

Reload privilege tables now? [Y/n] y //现在重新加载特权表
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

四、下载安装php

[root@lamp ~]# yum -y install php php-cli php-fpm php-gd php-curl php
Last metadata expiration check: 0:03:15 ago on Mon 15 Jul 2024 04:05:
Dependencies resolved.

五、更改时区

[root@lamp ~]# vim /etc/php.ini
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone =Asia/Shanghai //亚洲时区
[root@lamp ~]# systemctl restart php-fpm
[root@lamp ~]# systemctl enable php-fpm

六、写入php网页,更改配置文件

[root@lamp ~]# cd /var/www/html/
[root@lamp html]# vim index.php //写入网页
<?php
        phpinfo();
/>

~                    
[root@lamp html]# vim /etc/httpd/conf/httpd.conf //更改配置文件
 <IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>
[root@lamp html]# systemctl restart httpd
[root@lamp html]# systemctl enable httpd

七、下载安装lrzsz,上传文件并安装tar解压文件

[root@lamp html]# yum -y install lrzsz
[root@lamp html]# mkdir /opt/software
[root@lamp html]# cd /opt/software/
[root@lamp software]# ls
[root@lamp software]# rz -E
rz waiting to receive. //上传文件 
[root@lamp software]# ls
wordpress-6.5.5.tar.gz
[root@lamp html]# yum -y install tar
[root@lamp software]# tar -xzvf wordpress-6.5.5.tar.gz //解压文件

八、更改默认网页位置,修改所有者所属组并赋予权限

[root@lamp software]# cp -r wordpress /var/www/html/ //更改默认网页位置
[root@lamp software]# cd /var/www/html/
[root@lamp html]# ls
index.php  wordpress
[root@lamp html]# cd 
[root@lamp ~]# chown -R apache.apache /var/www/html/wordpress/ //修改所有者,所属组
[root@lamp ~]# chmod -R 775 /var/www/html/wordpress/ // 赋予775权限

九、进入mysql,创建数据库用户

[root@lamp ~]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 10.5.22-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input s

MariaDB [(none)]> create database wordpress_db; //创建数据库名字
Query OK, 1 row affected (0.000 sec)

MariaDB [(none)]> create user 'wordpress_user'@'localhost' identifiedd by 'redhat'; //创建用户和密码
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> grant all on wordpress_db.* to wordpress_user; //授权
ERROR 1133 (28000): Can't find any matching row in the user table
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.000 sec)

MariaDB [(none)]> exit
Bye

十、用虚拟主机实现

[root@lamp ~]# cp -p /usr/share/doc/httpd-core/httpd-vhosts.conf /etc/httpd/conf.d/
[root@lamp ~]# vim /etc/httpd/conf.d
[root@lamp ~]# vim /etc/httpd/conf.d/httpd-vhosts.conf 
<VirtualHost 192.168.35.142:80>
    DocumentRoot "/var/www/html/wordpress"
    <Directory "/var/www/html/wordpress">
        Options Indexes FollowSymLinks //赋予权限,在主配置文件中/etc/httpd/conf/httpd.conf
        AllowOverride all
        Require all granted
    </Directory>
</VirtualHost>
[root@lamp ~]# systemctl restart httpd
[root@lamp ~]# systemctl enable httpd

十一、搭建完成

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值