Home  >  Article  >  Backend Development  >  Teach you step by step Linux PHP environment deployment and project launch (share)

Teach you step by step Linux PHP environment deployment and project launch (share)

慕斯
慕斯forward
2021-06-07 09:49:575798browse

##This article will share with you Linux PHP environment deployment and project launchIt has certain reference Value, friends in need can refer to it, I hope it will be helpful to everyone.

Teach you step by step Linux PHP environment deployment and project launch (share)

1. Project online deployment

1. Foreword

If you want to deploy For environment online projects, the following conditions must first be met: server (IP, account password, terminal), corresponding software, domain name (recording analysis, code), etc.

Server and domain name purchase

First log in to the console and obtain the IP address of the host that needs to be connected:

Teach you step by step Linux PHP environment deployment and project launch (share)

Get it After connecting to the public IP, you can use the remote terminal tool to connect to the server to be operated online.

Remote tools can use Putty, CMD, etc., without restrictions.

Teach you step by step Linux PHP environment deployment and project launch (share)

Take CentOS7.6 as an example. After purchasing a server and generating an instance, please execute "yum -y update" to update the entire system when logging in to the system for the first time to prevent There are loopholes in the system:

Teach you step by step Linux PHP environment deployment and project launch (share)

2. Install PHP7

In the current system default yum source, the latest version of PHP is 5.4.16[DY2], Projects that need to be launched require a minimum version of PHP7.0. At this time, EPEL[DY3] can exactly solve this problem.

a. Install epel for CentOS7

 rpm -Uvhhttps://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

b. Obtain the yum source of PHP7

rpm -Uvhhttps://mirror.webtatic.com/yum/el7/webtatic-release.rpm

c. Install PHP7.2 and its common extensions

yum install php72w php72w-cli php72w-common php72w-develphp72w-embedded php72w-fpm php72w-gd php72w-mbstring php72w-mysqlndphp72w-opcache php72w-pdo php72w-xml

Teach you step by step Linux PHP environment deployment and project launch (share)


d. Test PHP installation

php -v

Teach you step by step Linux PHP environment deployment and project launch (share)

3. Install Apache2

a. Execute the installation yum command:

yum -y install httpd

b. Set Apache to boot and start Apache:

systemctl enable httpd && systemctl start httpd[DY4]

c. Write a static file and a The php script tests whether Apache parses dynamic and static files normally

Note: The default site of Apache is located at "/var /www/html"

Create index.html and index.php files with any content:

Use a browser for test access:

Teach you step by step Linux PHP environment deployment and project launch (share)

4. Install Mariadb[DY5]

The Mariadb installed here is a major branch of MySQL, and it is not much different from MySQL in use.

a. Execute the installation instructions

yum -y install mariadb-server

Teach you step by step Linux PHP environment deployment and project launch (share)

b. Start the Mariadb service and set the startup items

systemctl enable mariadb && systemctlstart mariadb

c. Execute the initialization of the Mariadb database Instructions (setting initial password and other operations)

mysql_secure_installation[DY6]

d. Try to log in to Mariadb using the command line

mysql -u root -p

Teach you step by step Linux PHP environment deployment and project launch (share)##5 , Domain name resolution

Before modifying the hosts file, it was actually a type of domain name resolution. At that time, it was only limited to local, but now it needs to be considered online.

To do resolution, you must log in to the domain name control panel. Before parsing the domain name, it is best to ensure that the domain name has been registered. If there is no registered domain name, although the resolution will be successful, it will affect the use. When using will be intercepted by the service provider.

Teach you step by step Linux PHP environment deployment and project launch (share)Click the Add Analysis Record button:

Teach you step by step Linux PHP environment deployment and project launch (share)Fill in the corresponding record information in the pop-up window interface [DY7 ]:

Teach you step by step Linux PHP environment deployment and project launch (share)Use ping test:

Teach you step by step Linux PHP environment deployment and project launch (share)

6. Unzip the code and import it into the database

Step 1**: Import the sql**** file into the database**

Enter the command line management interface of the database, create the required database edu16, and use the source command to import the sql file:

Teach you step by step Linux PHP environment deployment and project launch (share)

Step 2* *: Create the running directory of the site, decompress the uploaded code zip**** package, and then copy the code to the running directory of the site**

a. The site directory is agreed to be "/var /www/html".

Create site directory:

The directory already exists, no need to create it

b. Copy the previously uploaded code compressed package to the current site directory, decompress the compressed package, and the decompression is complete You can delete it later

Decompression syntax: unzip compressed package path

Teach you step by step Linux PHP environment deployment and project launch (share)

At this time, because the site entry file is in the public directory, and the site of the current project is in /var In /www/html, there is a missing public, so you need to modify the DocumentRoot item in the apache configuration file.

# vim /etc/httpd/conf/httpd.conf
Teach you step by step Linux PHP environment deployment and project launch (share)

Teach you step by step Linux PHP environment deployment and project launch (share)

##Also grant write permission to the temporary directory:

Teach you step by step Linux PHP environment deployment and project launch (share) Solve the pseudo-static problem (if you don’t solve it, you can only access the homepage, and other pages will get 404):

Teach you step by step Linux PHP environment deployment and project launch (share)

Idea: Open the root directory of the current site AllowOverride configuration item, set it to All, and then restart apache.

7. Create a virtual host

Objective: It is required that the online server can be accessed using the https protocol. [Improve security and enhance user confidence in the website]

a. Apply for an SSL certificate

If you want your site to support the https protocol, you must first apply for a server certificate from the CA. There are currently many free certificates available for application, such as Sysmantec's one-year free certificate in cooperation with Alibaba Cloud. Generally, free certificates can only be bound to one domain name. In addition to one year of free service, there is also three months of free service, but there is no limit on the number of times, the number of domain names, and even supports wildcards.

Take Alibaba Cloud as an example:

https://common-buy.aliyun.com/?spm=5176.2020520163.cas.3.267d56a7EBRcYw&commodityCode=cas#/buy

Teach you step by step Linux PHP environment deployment and project launch (share)

After payment is completed, click "Certificate to be applied for":


Teach you step by step Linux PHP environment deployment and project launch (share)
Teach you step by step Linux PHP environment deployment and project launch (share)

Teach you step by step Linux PHP environment deployment and project launch (share)
Teach you step by step Linux PHP environment deployment and project launch (share) ## Wait for the certificate issuance to be completed, and then download the certificate:

Teach you step by step Linux PHP environment deployment and project launch (share)The public and private certificate files obtained after decompressing the compressed package:

Teach you step by step Linux PHP environment deployment and project launch (share)Upload the three files to the server, and fix the save path and try not to change it.

It is agreed to store the public and private certificate files in "/ssl/"


Teach you step by step Linux PHP environment deployment and project launch (share)b. Install Apache's mod_ssl module

yum -y install mod_ssl

Teach you step by step Linux PHP environment deployment and project launch (share)c. Virtual host configuration reference (80 443):

Note: apache installed in yum

way# The default main configuration file for ## is located at /etc/httpd/conf/httpd.conf

根据主配置文件中的配置可以看出,其引入了conf.d目录下的全部conf文件,那么可以在该目录中创建一个vhosts.conf****文件,作为虚拟主机的配置文件:

80端口主机:

<VirtualHost *:80>
ServerAdmin cherish@cherish.pw
DocumentRoot"PATH"
ServerName “yourdomain.com”
<Directory “PATH”>
Allow from all
AllowOverride all
Options -indexes
Require all granted

443端口主机:

<VirtualHost *:443>
SSLEngine on
SSLCertificateFile “公钥文件路径”
SSLCertificateKeyFile “私钥文件路径”
SSLCertificateChainFile “证书链文件路径”
SSLCipherSuite"ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4:!DH:!DHE"
SSLProtocol TLSv1.1 TLSv1.2
Headeralways set Strict-Transport-Security “max-age=63072000; includeSubdomains;preload”
DocumentRoot “PATH”
ServerName “yourdomain.com”
<Directory “PATH”>
Allowfrom all
AllowOverride all
Options -indexes
Require all granted

Teach you step by step Linux PHP environment deployment and project launch (share)

创建好之后,参考上述的框框中配置代码,进行修改,其中443端口的虚拟主机配置含义如下:
Teach you step by step Linux PHP environment deployment and project launch (share)

修改完毕之后保存退出,然后重启apache

systemctl restart httpd

d. 打开浏览器访问项目,检查https协议是否生效

Teach you step by step Linux PHP environment deployment and project launch (share)

问题,生效虽然生效了,但是https协议需要用户手动去补充,在直接输入域名访问的时候默认还是80的http****协议,如何解决?

答:使用重写的方法,强制用户在访问http的时候跳转到https。操作步骤如下,在站点根目录下的“.htaccess”文件中添加如下代码,保存退出即可:
Teach you step by step Linux PHP environment deployment and project launch (share)

RewriteCond %{HTTPS} !=on

RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R,L]

举手之劳:框架运行的时候报错了,请解决。

错误1**:权限不足**
Teach you step by step Linux PHP environment deployment and project launch (share)

解决办法:
Teach you step by step Linux PHP environment deployment and project launch (share)

错误2**:数据库连接失败**

Teach you step by step Linux PHP environment deployment and project launch (share)

解决办法:修改项目目录下的.env文件

Teach you step by step Linux PHP environment deployment and project launch (share)

处理完毕之后项目即可访问您的项目了。


[DY1]如搭配使用的服务器在大陆境内,则需要域名先通过ICP备案。

[DY2]RHEL以及他的衍生发行版如CentOS、Scientific Linux为了稳定,官方的rpm repository提供的rpm包往往是很滞后的,当然了,这样做这是无可厚非的,毕竟这是服务器版本,安全稳定才是重点。

[DY3]EPEL:Extra Packages of EnterpriseLinux

[DY4]“指令A && 指令B”语法表示当指令A执行成功之后再去执行指令B。

systemctl指令是CentOS7中特有的指令,含义如指令名称:systemcontrol。

控制服务开关:

systemctl 开关服务名

启动项管理:

  • systemctl enable/disable 服务名

  • [DY5]在CentOS7的yum源中,数据库软件没有MySQL,取而代之的是Mariadb。

  • [DY6]执行该指令后依次有以下几个输入内容:

  • 输入当前数据库root帐号密码,没有密码则直接按回车;

  • 是否设置密码?输入Y后,为root用户设置密码;

  • 是否移除匿名用户?选择Y;

  • 是否禁止root用户远程登录?Y/n均可,不会生效;

  • 是否删除测试的test数据库?选择Y/n均可;

  • 是否刷新权限?选择Y;

[DY7]常见的几个记录类型:

A记录:将域名指向一个IPv4地址;

CNAME记录:域名的别名,将一个域名指向另一个域名;

MX记录:一般用于做域名邮箱,将域名指向一个邮件服务器;

推荐学习:《PHP视频教程

The above is the detailed content of Teach you step by step Linux PHP environment deployment and project launch (share). For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete