参考本专栏上一节《CentOS7虚拟机安装及界面图形化》内容。
sudo-i
切换至root用户。rpm -qa | grep httpd
yum list installed | grep httpd
yum install httpd* -y
用这个命令来安装apache。systemctl start httpd.service
启动Apache,并输入命令systemctl status httpd.service
查看启动后的状态。看到已成功启动。/var/www/html
,编辑默认主页vim /var/www/html/index.html
。按ins键插入模式下输入以下命名,按Esc键回到命令模式,按:进入末行模式,输入wq保存并退出。setenforce 0
关闭防火墙。vim /etc/httpd/conf/httpd.conf
打开编辑。要是编辑后的文件生效,需要重启以下服务。# ServerRoot: The top of the directory tree under which the server's # configuration, error, and log files are kept. # # Do not add a slash at the end of the directory path. If you point # ServerRoot at a non-local disk, be sure to specify a local disk on the # Mutex directive, if file-based mutexes are used. If you wish to share the # same ServerRoot for multiple httpd daemons, you will need to change at # least PidFile. # ServerRoot "/etc/httpd"
# Listen: Allows you to bind Apache to specific IP addresses and/or # ports, instead of the default. See also the <VirtualHost> # directive. # # Change this to Listen on specific IP addresses as shown below to # prevent Apache from glomming onto all bound IP addresses. # #Listen 12.34.56.78:80 Listen 80
# If you wish httpd to run as a different user or group, you must run # httpd as root initially and it will switch. # # User/Group: The name (or #number) of the user/group to run httpd as. # It is usually good practice to create a dedicated user and group for # running httpd, as with most system services. # User apache Group apache
# DocumentRoot: The directory out of which you will serve your # documents. By default, all requests are taken from this directory, but # symbolic links and aliases may be used to point to other locations. # DocumentRoot "/var/www/html"
# Relax access to content within /var/www. # <Directory "/var/www"> AllowOverride None # Allow open access: Require all granted </Directory>
# Further relax access to the default document root: <Directory "/var/www/html"> # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn't give it to you. # # The Options directive is both complicated and important. Please see # http://httpd.apache.org/docs/2.4/mod/core.html#options # for more information. # Options Indexes FollowSymLinks # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # AllowOverride None # # Controls who can get stuff from this server. # Require all granted </Directory>
sudo-i
切换至root用户。rpm -qa | grep mysql
yum list installed | grep mysql
yum install mysql-server -y
用这个命令来安装MySQL。这里执行安装命令是无效的,因为centos-7默认是Mariadb,所以执行该命令只是更新Mariadb数据库wget http://repo.mysql.com/mysql80-community-release-el7.rpm
下载最新版mysql。rpm -ivh mysql80-community-release-el7.rpm
进行安装。安装后会获得两个mysql的yum repo源,输入命令cd /etc/yum.repos.d/
进行查看。yum install mysql-server --nogpgcheck
开始安装,其中 --nogpgcheck 表示进行跳过公钥检查安装,否则会报错。在安装过程中会多次询问输入,均输入y
并回车。systemctl start mysqld.service
启动服务。2022-01-24T08:20:12.790955Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.28) initializing of server in progress as process 12665 2022-01-24T08:20:12.825559Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started. 2022-01-24T08:20:13.309612Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended. 2022-01-24T08:20:14.519212Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: frc?h9SrPtIq 2022-01-24T08:20:16.647145Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.28) starting as process 12712 2022-01-24T08:20:16.665299Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started. 2022-01-24T08:20:16.951166Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended. 2022-01-24T08:20:17.327996Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed. 2022-01-24T08:20:17.328057Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel. 2022-01-24T08:20:17.726155Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock 2022-01-24T08:20:17.726208Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.28' socket: '/var/lib/mysql/mysql.sock' port: 3306 MySQL Community Server - GPL.
mysql -u root -p"
回车,输入上述临时密码登录数据库。alter user'root'@'localhost' IDENTIFIED BY '新密码';
新密码要包含大小写、特殊字符、数字、长度位数等要求,例如123456.comCOM,不然会提示不满足复杂度。输入密码时注意要以分号结尾。\q
退出,使用新密码再次尝试登录。sudo-i
切换至root用户。rpm -qa | grep php
yum list installed | grep php
yum install php
开始安装php。yum install php-mysql
进行安装。yum install php-mbstring
进行安装,同理地,安装过程有提示时输入y。vim /etc/php.ini
进行PHP配置短标记功能,在命令模式下输入/short进行关键字查找,如下图。vim /var/www/html/index.php
在默认网站目录下新建一个网页。192.168.1.2/index.php
测试Apache能否成功解析PHP,自行使用自己的IP地址。看到一片空白,出了问题。192.168.1.2/index.php
测试看到以下界面,说明LAMP平台搭建成功。