系统运维-22-2-LAMP和PHP程序
WEB服务的请求流程
Client --> http --> httpd --> cgi --> application server ( program file ) --> mariadb
Centos 7 程序包
httpd
php
php-mysql
mariadb-server
注意:php要求httpd使用prefork MPM
启动服务
systemctl start httpd.service
systemctl start mariadb.service
测试
php程序执行环境,创建test.php
<?php
phpinfo();
?>
测试php程序与mysql通信,创建test2.php
<?php
$conn=mysql_connec('','mysql','');
if ($conn)
echo "ok";
else
echo "failure";
mysql_close();
?>
[[email protected] ~]# ll | grep wordpress
-rw-r--r-- 1 root root 6526208 May 6 08:36 wordpress-4.3.1.tar.gz
[[email protected] ~]# tar xf wordpress-4.3.1.tar.gz
[[email protected] ~]# ll | grep wordpress
drwxr-xr-x 5 nobody 65534 4096 Sep 15 2015 wordpress
-rw-r--r-- 1 root root 6526208 May 6 08:36 wordpress-4.3.1.tar.gz
[[email protected] ~]# cp -a wordpress /var/www/html/
[[email protected] ~]# cd /var/www/html/wordpress
[[email protected] wordpress]# ll
total 176
-rw-r--r-- 1 nobody 65534 418 Sep 2 2015 index.php
-rw-r--r-- 1 nobody 65534 19930 Sep 2 2015 license.txt
-rw-r--r-- 1 nobody 65534 7360 Sep 15 2015 readme.html
-rw-r--r-- 1 nobody 65534 4951 Sep 2 2015 wp-activate.php
drwxr-xr-x 9 nobody 65534 4096 Sep 15 2015 wp-admin
-rw-r--r-- 1 nobody 65534 271 Sep 2 2015 wp-blog-header.php
-rw-r--r-- 1 nobody 65534 5007 Sep 2 2015 wp-comments-post.php
-rw-r--r-- 1 nobody 65534 2764 Sep 2 2015 wp-config-sample.php
drwxr-xr-x 4 nobody 65534 52 Sep 15 2015 wp-content
-rw-r--r-- 1 nobody 65534 3286 Sep 2 2015 wp-cron.php
drwxr-xr-x 12 nobody 65534 4096 Sep 15 2015 wp-includes
-rw-r--r-- 1 nobody 65534 2380 Sep 2 2015 wp-links-opml.php
-rw-r--r-- 1 nobody 65534 3123 Sep 2 2015 wp-load.php
-rw-r--r-- 1 nobody 65534 34669 Sep 2 2015 wp-login.php
-rw-r--r-- 1 nobody 65534 8252 Sep 2 2015 wp-mail.php
-rw-r--r-- 1 nobody 65534 11062 Sep 2 2015 wp-settings.php
-rw-r--r-- 1 nobody 65534 25124 Sep 2 2015 wp-signup.php
-rw-r--r-- 1 nobody 65534 4035 Sep 2 2015 wp-trackback.php
-rw-r--r-- 1 nobody 65534 3055 Sep 2 2015 xmlrpc.php
[[email protected] wordpress]# cp wp-config-sample.php wp-config.php
[[email protected] wordpress]# vim wp-config.php
[[email protected] wordpress]# grep define wp-config.php
define('DB_NAME', 'wpdb');
define('DB_USER', 'wpuser');
define('DB_PASSWORD', 'wppasswd');
define('DB_HOST', 'localhost');
define('DB_CHARSET', 'utf8');
define('DB_COLLATE', '');
define('AUTH_KEY', 'put your unique phrase here');
define('SECURE_AUTH_KEY', 'put your unique phrase here');
define('LOGGED_IN_KEY', 'put your unique phrase here');
define('NONCE_KEY', 'put your unique phrase here');
define('AUTH_SALT', 'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT', 'put your unique phrase here');
define('NONCE_SALT', 'put your unique phrase here');
define('WP_DEBUG', false);
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
[[email protected] wordpress]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.60-MariaDB MariaDB Server
Copyright (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)]> GRANT ALL ON wpdb.* TO 'wpuser'@'localhost' IDENTIFIED BY 'wppasswd';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> GRANT ALL ON wpdb.* TO 'wpuser'@'127.0.0.1' IDENTIFIED BY 'wppasswd';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> CREATE DATABASE wpdb;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> exit
Bye
[[email protected] wordpress]# mysql -uwpuser -pwppasswd
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 5.5.60-MariaDB MariaDB Server
Copyright (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)]> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| test |
| wpdb |
+--------------------+
3 rows in set (0.00 sec)
MariaDB [(none)]> exit
Bye
phpMyAdmin工具
mariadb的webGUI
[[email protected] ~]# ll | grep php
[[email protected] ~]# unzip phpMyAdmin-4.8.5-all-languages.zip
[[email protected] ~]# ll | grep php
drwxr-xr-x 12 root root 4096 Jan 25 22:04 phpMyAdmin-4.8.5-all-languages
-rw-r--r-- 1 root root 10794370 May 6 09:06 phpMyAdmin-4.8.5-all-languages.zip
[[email protected] ~]# cp -a phpMyAdmin-4.8.5-all-languages /var/www/html/
[[email protected] ~]# cd /var/www/html/
[[email protected] html]# ll
total 20
-rw-r--r--. 1 root root 13 Jan 13 05:22 index.html
drwxr-xr-x 12 root root 4096 Jan 25 22:04 phpMyAdmin-4.8.5-all-languages
-rw-r--r--. 1 root root 13 Jan 4 23:41 test.html
drwxr-xr-x 5 nobody 65534 4096 May 6 08:42 wordpress
[[email protected] html]# ln -sv phpMyAdmin-4.8.5-all-languages pma
‘pma’ -> ‘phpMyAdmin-4.8.5-all-languages’
[[email protected] html]# cd pma/
[[email protected] ~]# tr -d 'a-zA-Z0-9' < /dev/urandom | head -30 | md5sum
f94a464f8ddb21e868e642c31795d683 -
[[email protected] pma]# vim config.inc.php
[[email protected] pma]# grep cfg config.inc.php | head -1
$cfg['blowfish_secret'] = 'f94a464f8ddb21e868e642c31795d683'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
[[email protected] pma]# yum install -y php-mbstring
[[email protected] pma]# systemctl reload httpd.service
phpMyAdmin
information_schema在数据库不运行的时候没有数据,运行时产生数据,类似system
performance_schema,类似program
mysql,源数据的数据库
php解释器与Mariadb交互
解释器无需与Mariadb交互,那些用到数据存储系统的程序才需要与数据存储交互
存储系统
文件系统:文件
SQL:Mariadb,Oracle,MSSQL
NoSQL:redis,mongodb,hbase
NewSQL
PHP的Opcode
1)Scanning(Lexing)-将PHP代码转换为语言片段(TOKEN)
2)Parsing-将TOKEN转换成简单而有意义的表达式
3)Compilation-将表达式编译成Opcode
4)Execution-顺序执行Opcodes,每次一条,从而实现PHP脚本的功能
扫描--分析--编译--执行