Home >Backend Development >PHP Tutorial >Teach you step by step Linux PHP environment deployment and project launch (share)
1. Project online deployment1. 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 purchaseFirst log in to the console and obtain the IP address of the host that needs to be connected: 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. 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: 2. Install PHP7In 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 CentOS7rpm -Uvhhttps://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpmb. Obtain the yum source of PHP7
rpm -Uvhhttps://mirror.webtatic.com/yum/el7/webtatic-release.rpmc. 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
php -v3. Install Apache2a. Execute the installation yum command:
yum -y install httpdb. 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: 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 instructionsyum -y install mariadb-serverb. Start the Mariadb service and set the startup items
systemctl enable mariadb && systemctlstart mariadbc. 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
##5 , Domain name resolution
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.
Click the Add Analysis Record button:
Fill in the corresponding record information in the pop-up window interface [DY7 ]:
Use ping test:
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:
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
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
Solve the pseudo-static problem (if you don’t solve it, you can only access the homepage, and other pages will get 404):
## Wait for the certificate issuance to be completed, and then download the certificate:
The public and private certificate files obtained after decompressing the compressed package:
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/"
b. Install Apache's mod_ssl module
yum -y install mod_ssl
c. Virtual host configuration reference (80 443):
Note: apache installed in yumway# 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
创建好之后,参考上述的框框中配置代码,进行修改,其中443端口的虚拟主机配置含义如下:
修改完毕之后保存退出,然后重启apache
systemctl restart httpd
d. 打开浏览器访问项目,检查https协议是否生效
问题,生效虽然生效了,但是https协议需要用户手动去补充,在直接输入域名访问的时候默认还是80的http****协议,如何解决?
答:使用重写的方法,强制用户在访问http的时候跳转到https。操作步骤如下,在站点根目录下的“.htaccess”文件中添加如下代码,保存退出即可:
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R,L]
举手之劳:框架运行的时候报错了,请解决。
错误1**:权限不足**
解决办法:
错误2**:数据库连接失败**
解决办法:修改项目目录下的.env文件
处理完毕之后项目即可访问您的项目了。
[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!