Quickly build a lamp website platform
1.1 Questions
This example requires a fast build of the lamp dynamic Web platform based on a Linux host and ensures that PHP applications and databases can be supported to accomplish the following tasks:
1) Install the Lamp platform components to start the lamp platform
软件包:httpd、mariadb-server、mariadb、php、php-mysql系统服务:httpd、mariadb
2) write a test page to ensure that the lamp platform is available
访问 http://虚拟机地址/test1.php ,能显示PHP环境信息访问 http://虚拟机地址/test2.php ,能报告数据库连接状态信息
1.2 Solutions
When you turn on network service applications such as WEB/FTP in a CentOS7 system, you may receive security policy effects such as firewall, SELinux, and so on, which are configured by default. To avoid interference, these protection mechanisms are recommended in the learning process.
To turn off firewall policy:
[Email protected] ~]# Systemctl stop Firewalld
[Email protected] ~]# systemctl disable FIREWALLD
Turn off the SELinux protection mechanism:
[[email protected] ~]# Setenforce 0//Switch to loose mode now
[[email protected] ~]# Getenforce//Confirm result
Permissive
[[email protected] ~]# vim/etc/selinux/config//After boot no longer mandatory
Selinux=permissive//Loose mode
1.3 Steps
The implementation of this case needs to follow the steps below.
Step one: Install the lamp platform components, start the lamp platform
1) Install the Lamp components package
Mainly include: httpd, Mariadb-server, mariadb, PHP, Php-mysql.
[Email protected] ~]# yum-y install httpd mariadb-server mariadb php php-mysql
.. ..
has been installed:
Mariadb.x86_64 1:5.5.52-1.EL7
Mariadb-server.x86_64 1:5.5.52-1.EL7
Php.x86_64 0:5.4.16-42.EL7
Php-mysql.x86_64 0:5.4.16-42.EL7
To be installed as a dependency:
Libzip.x86_64 0:0.10.1-8.EL7
Perl-dbd-mysql.x86_64 0:4.023-5.EL7
Php-cli.x86_64 0:5.4.16-42.EL7
Php-common.x86_64 0:5.4.16-42.EL7
Php-pdo.x86_64 0:5.4.16-42.EL7
Complete!
2) Start lamp build corresponding system service
Mainly include: Web service httpd, database service mariadb. PHP Web page parsing function by the HTTPD service when needed to invoke the corresponding module file implementation, no corresponding service.
[Email protected] ~]# systemctl restart httpd mariadb//Service
[[email protected] ~]# systemctl enable httpd mariadb//Set boot start
Created symlink From/etc/systemd/system/multi-user.target.wants/mariadb.service to/usr/lib/systemd/system/ Mariadb.service.
Step two: Write a test page to make sure the lamp platform is available
1) test PHP page parsing
Create a new test page test1.php in the Web server's Web page directory.
[Email protected] ~]# vim/var/www/html/test1.php
<?php
Phpinfo (); displaying PHP environment information
?>
You can see the PHP environment information by accessing http://127.0.0.1/test1.php via the Firefox browser, which is shown in 1.
2) test PHP page parsing and database connection
Create another Test Web page in the Web server's web directory test2.php, where the MARIADB database service is not configured, the administrator account is root, the password is empty.
[Email protected] ~]# vim/var/www/html/test2.php
<?php
$link =mysql_connect (' localhost ', ' root ', ');
if ($link) echo "Success!"; Success shows Success!!
else echo "Failure!"; Failure will show Failure!!
Mysql_close (); To close a database connection
?>
通过Firefox浏览器访问 http://127.0.0.1/test2.php ,可以看到数据库连接的反馈信息,正常结果页面应显示"Success !!",-2所示。 ![](http://i2.51cto.com/images/blog/201802/27/0f80ed1c5e195882ad8c5edb9ce6850d.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)
Quickly build a lamp website platform