LAMP服务部署
【摘要】 1、如果是在弹性云服务器上部署就不用更换yum源,虚拟机上面模拟首先更换yum。https://developer.aliyun.com/mirror/ ##阿里镜像源2、开始安装LAMP服务[root@localhost ~]# yum -y install httpd php php-fpm php-server php-mysql ##分别安装ht...
1、如果是在弹性云服务器上部署就不用更换yum源,虚拟机上面模拟首先更换yum。
https://developer.aliyun.com/mirror/ ##阿里镜像源
2、开始安装LAMP服务
[root@localhost ~]# yum -y install httpd php php-fpm php-server php-mysql ##分别安装httpd php php-server php-fpm php-mysql等服务
3、重启httpd和php
[root@node-0002 ~]# nohup python -m SimpleHTTPServer 80 > /dev/null 2>&1 & 开放80端口
[1] 8110
[root@node-0002 ~]# curl 127.0.0.1:80
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html>
<title>Directory listing for /</title>
<body>
<h2>Directory listing for /</h2>
<hr>
<ul>
<li><a href=".bash_history">.bash_history</a>
<li><a href=".bash_logout">.bash_logout</a>
<li><a href=".bash_profile">.bash_profile</a>
<li><a href=".bashrc">.bashrc</a>
<li><a href=".cshrc">.cshrc</a>
<li><a href=".history">.history</a>
<li><a href=".pki/">.pki/</a>
<li><a href=".ssh/">.ssh/</a>
<li><a href=".tcshrc">.tcshrc</a>
</ul>
<hr>
</body>
</html>
[root@node-0002 ~]# touch SERVER1 ##创建一个文件
在这里出现了一个问题:(我们来一起看一下)
httpd服务启动不了
[root@node-0002 ~]# netstat -ntulp |grep 80 ##查看端口被python占用
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 8110/python
解决:
[root@node-0002 ~]# ps -ef|grep python
root 654 1 0 18:16 ? 00:00:00 /usr/bin/python2 -Es /usr/sbin/tuned -l -P
root 8110 8081 0 18:32 pts/0 00:00:28 python -m SimpleHTTPServer 80
root 18341 8081 0 19:43 pts/0 00:00:00 grep --color=auto python
[root@node-0002 ~]# kill -9 8110
再次查看端口:
[root@node-0002 ~]# netstat -ntulp |grep 80
[1]+ Killed nohup python -m SimpleHTTPServer 80 > /dev/null 2>&1
重启HTTP和php服务
[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# systemctl enable httpd ##重启http
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@localhost ~]# systemctl restart php-fpm
[root@localhost ~]# systemctl enable php-fpm ##重启php
Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.
[root@localhost ~]#
[root@localhost ~]#echo "<?php echo phpinfo(); ?>" >/var/www/html/index.php #编写php代码并查看 web界面
[root@localhost ~]# cat /var/www/html/index.php
<?php echo phpinfo(); ?>
[root@localhost ~]# chmod -R 777 /var/www/html
[root@localhost ~]# systemctl restart httpd
4、web界面验证http是否启动
如果不能访问:
(1)弹性云主机去安全组添加:http 80端口
(2)虚拟机里面的话:
[root@localhost ~]# systemctl start firewalld ##重启防火墙
[root@localhost ~]# firewall-cmd --list-ports ##查看端口
##这里显示没有端口开启
[root@localhost ~]# firewall-cmd --zone=public --add-port=80/tcp --permanent ##开启tcp/80这个端口
success
[root@localhost ~]# firewall-cmd --reload ##启动端口
success
[root@localhost ~]# firewall-cmd --list-ports
80/tcp ##再次查看就会发现80端口已经开启
5、卸载Mariadb数据库(卸载mariadb数据库是为了防止密码冲突)
[root@localhost ~]# yum -y remove mariadb-server
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com ##我这里用的是虚拟机源也是阿里的镜像源
6、重启Mariadb并重置密码:
[root@localhost ~]# wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
[root@localhost ~]# yum -y install mysql57-community-release-el7-8.noarch.rpm
Loaded plugins: fastestmirror
[root@localhost ~]# yum -y install mysql-community-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
[root@localhost ~]# systemctl restart mysqld
[root@localhost ~]# systemctl enable mysqld
[root@localhost ~]# grep -Eo "for root@localhost:.*" /var/log/mysqld.log |sed -r "s/(for.*localhost:)(.*)/\2/"
gc<F_aDZR5r?
[root@localhost ~]# mysql_secure_installation ##初始化数据库密码
Securing the MySQL server deployment.
Enter password for user root: gc<F_aDZR5r?
The existing password for the user account root has expired. Please set a new password.
New password: Huawei@123
Re-enter new password: Huawei@123
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing password for root.
Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : n
... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n
... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove yest database and access to it? (Press y|Y for Yes, any other key for No) : y
- Dropping test database...
Success.
- Removing privileges on test database...
Success.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.
All done!
[root@localhost ~]#
[root@localhost ~]#
7、登入数据库设置权限
[root@localhost ~]# mysql -uroot -pHuawei@123
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.35 MySQL Community Server (GPL)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
参考:https://www.cnblogs.com/sanduzxcvbnm/p/9789236.html
[root@localhost ~]# mysql -uroot -pHuawei@123
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.35 MySQL Community Server (GPL)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set host='%' where user='root' limit 1; ##配置MySQL远程连接
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges; ##刷新权限
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
验证:
[root@localhost ~]# mysql -h 172.16.175.85 -u root -pHuawei@123
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.35 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]>
[root@localhost ~]# mysql -uroot -pHuawei@123
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql> create database Discuz;
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| Discuz |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)
mysql>
8、部署网站服务:
[root@localhost ~]# wget http://download.comsenz.com/DiscuzX/3.2/Discuz_X3.2_SC_UTF8.zip
-bash: wget: 未找到命令 ##没有安装wget这个命令
[root@localhost ~]# yum -y install wget ##yum安装
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
正在解决依赖关系
--> 正在检查事务
[root@localhost ~]# wget http://download.comsenz.com/DiscuzX/3.2/Discuz_X3.2_SC_UTF8.zip ##拖取资料包
--2021-10-07 16:10:21-- http://download.comsenz.com/DiscuzX/3.2/Discuz_X3.2_SC_UTF8.zip
正在解析主机 download.comsenz.com (download.comsenz.com)... 223.111.194.252, 223.111.112.109, 36.156.85.208, ...
正在连接 download.comsenz.com (download.comsenz.com)|223.111.194.252|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 301 Moved Permanently
位置:https://download.comsenz.com/DiscuzX/3.2/Discuz_X3.2_SC_UTF8.zip [跟随至新的 URL]
--2021-10-07 16:10:21-- https://download.comsenz.com/DiscuzX/3.2/Discuz_X3.2_SC_UTF8.zip
正在连接 download.comsenz.com (download.comsenz.com)|223.111.194.252|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:12486773 (12M) [application/zip]
正在保存至: “Discuz_X3.2_SC_UTF8.zip”
100%[==================================================>] 12,486,773 3.10MB/s 用时 4.0s
2021-10-07 16:10:26 (2.96 MB/s) - 已保存 “Discuz_X3.2_SC_UTF8.zip” [12486773/12486773])
[root@localhost ~]# ll ##查看
总用量 12200
-rw-------. 1 root root 1318 10月 3 23:46 anaconda-ks.cfg
-rw-r--r--. 1 root root 12486773 4月 8 2020 Discuz_X3.2_SC_UTF8.zip
[root@localhost ~]#
[root@localhost ~]# yum -y install unzip ##下载unzip软件
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
[root@localhost ~]# unzip Discuz_X3.2_SC_UTF8.zip ##解压
[root@localhost ~]# ll ##查看解压包
总用量 12204
-rw-------. 1 root root 1318 10月 3 23:46 anaconda-ks.cfg
-rw-r--r--. 1 root root 12486773 4月 8 2020 Discuz_X3.2_SC_UTF8.zip
drwxr-xr-x. 2 root root 102 5月 31 2016 readme
drwxr-xr-x. 12 root root 4096 5月 31 2016 upload
drwxr-xr-x. 4 root root 72 5月 31 2016 utility
[root@localhost ~]# cp -rf upload/* /var/www/html/ ##把解压的包cp到另一个目录去
[root@localhost ~]#
[root@localhost ~]# chmod -R 777 /var/www/html/ ##赋予777的权限
[root@localhost ~]#
[root@localhost ~]# systemctl restart httpd ##重启httpd服务
[root@localhost ~]# systemctl enable httpd
[root@localhost ~]#
9、web界面查看网站部署
参考:https://www.cnblogs.com/sanduzxcvbnm/p/9789236.html
参考:https://www.icode9.com/
【版权声明】本文为华为云社区用户原创内容,未经允许不得转载,如需转载请自行联系原作者进行授权。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)