如何將寫好的項目部署到云服務器,讓外界可以通過互聯(lián)網(wǎng)訪問項目網(wǎng)站。以下使用的是騰訊云服務器操作,系統(tǒng)環(huán)境為CentOS7.9。
一、購買云服務器
打開騰訊云官網(wǎng),注冊好自己的平臺賬號。如果是新人的話去新人專區(qū)購買服務器,性價比高。
這里可以選的服務器有輕量云服務器、云服務器CVM。兩者都可以指定自己的操作系統(tǒng),配置自定義環(huán)境上沒有區(qū)別。輕量云服務器帶寬比云服務器CVM大,但是輕量云服務器有流量限制,云服務器CVM是沒有流量限制的,但輕量云性價比高。以下操作輕量云服務器還是云服務器CVM可以部署。
二、開放安全組(防火墻)
有效去防止入侵者去攻擊服務器,不建議全部端口開放。
這里把以下端口開放
80 | WEB服務 |
443 | HTTPS服務 |
3306 | MySQL |
22 | 登錄服務器 |
ICMP | Ping |
三、部署云服務器環(huán)境
?1,安裝HTTPD服務器
[root@localhost ~]# yum install httpd -y
2,啟用HTTPD服務并設置開機啟動
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl enable httpd?
3,測試網(wǎng)站是否能訪問
?以上訪問成功接下來做以下操作
4,安裝PHP服務器
[root@localhost ~]# yum install php php-mysql?-y
5,配置HTTPD
[root@localhost ~]# echo "AddType application/x-httpd-php .php" >> /etc/httpd/conf/httpd.conf?
[root@localhost ~]# vi /etc/httpd/conf/httpd.conf?
#找到
DirectoryIndex index.html
后面追加 index.php 如下
?保存退出
6,重啟HTTPD服務器
[root@localhost ~]# systemctl restart httpd?
7,測試php文件可用
[root@localhost ~]# echo "<?php phpinfo(); ?>" > /var/www/html/index.php
?
注意:/var/www/html/目錄是存放你的項目目錄!
以上訪問沒有問題接下來可以做mysql配置了
8,安裝mysql服務器(mariadb)【你的項目中不使用數(shù)據(jù)庫可以跳了到第12個步驟就可以完成網(wǎng)站上線】
[root@localhost ~]# yum install mariadb?mariadb-server -y
9,啟用服務器并設置開機啟動
[root@localhost ~]# systemctl start mariadb.service ??
[root@localhost ~]# systemctl enable mariadb.service?
10,mysql數(shù)據(jù)庫初始化
[root@localhost ~]# 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
you haven't set the root password yet, the password will be blank,
so you should just press enter here.Enter current password for root (enter for none): ????????????????#初次運行直接回車
OK, successfully used password, moving on...Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.Set root password? [Y/n] Y????????????????#是否設置密碼,輸入Y或者直接車
New password:? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#輸入root密碼
Re-enter new password:? ? ? ? ? ? ? ? ? ? ? ? ?#再輸入root密碼
Password updated successfully!
Reloading privilege tables..
?... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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? [Y/n]? ? ? ? ? ? ? ? ? ? ? ? #是否刪除匿名用戶,回車
?... 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? [Y/n] n? ? ? ? ? ? ? ? #是否禁止root遠程登錄,輸N否
?... skipping.By default, MariaDB 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 test database and access to it? [Y/n]? ? ? ? ?#是否刪除test數(shù)據(jù)庫,回車
?- 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? [Y/n]? ? ? ? ? ? ? ? ?#是否重新加載權限表,回車
?... 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!
[root@localhost ~]#?
11,測試數(shù)據(jù)庫連接
[root@localhost ~]# mysql -uroot -p123456 -h127.0.0.1
Welcome to the MariaDB monitor. ?Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 5.5.68-MariaDB MariaDB ServerCopyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>?
以上設置了mysql密碼 數(shù)據(jù)庫地址為:localhost?用戶名為:root 密碼為: 123456? ? (項目包里的數(shù)據(jù)庫連接配置寫成這個)
四、部署PHP項目到服務器
12,上傳文件到CentOS
這里使用的是SecureCRT演示
??
?以上是上傳文件到CentOS操作,如果還不會,建議重開。
13,授權root用戶遠程訪問
MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
14,創(chuàng)建一個數(shù)據(jù)庫并導入(這里按照你的項目去創(chuàng)建)【這里不會使用的話可以用數(shù)據(jù)庫工具可視化創(chuàng)建】
MariaDB [(none)]> create database room;? ? #創(chuàng)建數(shù)據(jù)名
Query OK, 1 row affected (0.00 sec)MariaDB [(none)]> use room;? ? ? ? ? ? ? ? ? ? ? ? #進入這個數(shù)據(jù)庫
Database changed
MariaDB [room]> source /var/www/html/room.sql? ? ? ? ? ? ? ? #導入數(shù)據(jù)庫
導入完成,網(wǎng)站就部署部署完畢。文章來源:http://www.zghlxwxcb.cn/news/detail-447818.html
防止別人可以攻擊服務器,去騰訊云上安全規(guī)則(防火墻)除了80,443端口其他都禁用。有需要上服務器的時候去開啟服務。文章來源地址http://www.zghlxwxcb.cn/news/detail-447818.html
到了這里,關于PHP項目部署到云服務器(CentOS+HTTP+PHP+MYSQL)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!