LAMP架构

LAMP(linux,apache,mysql,php)是linux系统下常用的网站架构模型,用来运行PHP网站。(这得apache是httpd服务),这些服务可以安装同意主机上,也可以安装不同主机上,但httpd和PHP必须在同一主机上(目的是提升整个架构的性能)。

安装LAMP(yum安装)

 安装基本组件

[root@localhost ~]# yum install -y php php-mysql httpd mysql mysql-server

修改apache的配置文件,让其支持php程序

[root@localhost ~]# vim /etc/httpd/conf.d/php.conf
AddHandler php5-script .php <<<指定将后缀是php的文件交给名为php5-script的处理器来解释
AddType text/html.php <<<添加一种支持的文件类型,后缀是.php
DirectoryIndex index.php <<如果用户没有指定默认文件。就此次文件返回给用户
保证有如上三行

重启httpd

[root@localhost ~]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
                                                                    [  OK  ]
执行下面命令,如下说明启动成功
[root@localhost ~]# ss -tnl |grep "80" LISTEN 0 128 :::80 :::*

启动mysql

[rootlocalhost ~]# service mysqld restart
Stopping mysqld:                                           [  OK  ]
Starting mysqld:                                           [  OK  ]
[root@localhost ~]# ss -tnl |grep "3306"
LISTEN     0      50                        *:3306                     *:*     

 准备测试页

[root@localhost ~]# cd /var/www/html/
[root@localhost html]# vim test.php
<html>
        <head><title>my的测试php页面</title></head>
        <body>
               <h2>my test page</h2>
                <?php
                            phpinfo();
                        ?>
        </body>
</html>

浏览器测试http://10.220.5.61/test.php

部署wordpress(使用PHP语言开发的博客平台)

使用rz上传wordpress

解压

[root@localhost ~]# unzip wordpress-3.3.1-zh_CN.zip 
[root@localhost ~]# cp -rvf wordpress/* /var/www/html
[root@localhost ~]# cd /var/www/html
[root@localhost html]# cp wp-config-sample.php wp-config.php <<目的是为了生成配置文件
[root@localhost html]#  vim wp-config.php

 修改如下:

创建相关的数据库和用户

[root@localhost ~]# mysql -uroot -p 123
mysql> create database wordpressDB;
Query OK, 1 row affected (0.00 sec)
mysql> grant all on *.* to 'wordpressDB'@'127.0.0.1' identified by '123';
Query OK, 0 rows affected (0.00 sec)

用浏览器访问,出现下图说明部署成功

总结

      PHP链接mysql的条件

   1.安装组件:php-mysql

   2。php脚本中指定mysql的ip  账号 密码 库名

原文地址:https://www.cnblogs.com/bo-ke/p/9780669.html