架构 服务器清单 服务器架构实战作者
概述
详解
PHP的环境搭建
PHP的帮助使用和配置文件
PHP的Hello World
PHP的库函数调用
PHP的Web程序
PHP的函数和面向对象使用
PHP的数据库访问
Nginx安装和配置访问
WordPress的安装和配置实用
推进资料:图书,视频,代码等
总述
PHP基础环境准备
安装虚拟机
VM(Virtual Box)
安装操作系统
Centos
网络使用桥接的方式连接
虚拟机有独立的IP,和主机可以相互访问
PHP安装
#wget http://pa1.php.net/distributions/php-5.6.22.tar.gz #tar –zxf php-5.6.22.tar.gz #./configure #yum install libxml2 libxslt #yum install libxml2-devel –y #find / -name “xml2-config” #make #make install #php version
PHP的帮助和配置文件
php --help php –i php –ini http://php.net/manual/en/configuration.file.php php –m pear pear list
PHP基础编程
第一个PHP程序
文件helloworld.php
执行$php helloword.php
未来经常用来测试的代码
PHP库函数调用
使用库函数
文件func.php
执行$php func.php
设置php.ini文件#locate php.ini # vi /usr/local/lib/php.ini
或者直接设置
PHP的Web程序
启动内置服务器
访问:
可以编辑hello.php文件:
PHP Test
PHP的函数和面向对象使用
参考代码
PHP的数据库访问
MySQL的安装
#yum install mysql #mysql -h 192.168.5.116 -P 3306 -u root -p123456 PHP的配置 ./configure --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-zlib echo "mysql conn start. \n"; $mysqli = new mysqli(" 192.168.0.104 ", " root ", " 123456","test"); if ($mysqli->connect_errno) { echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;} else { echo “database connection success. \n”;} echo "mysql conn end. \n"; ?>
Nginx安装
#yum list | grep nginx #vi /etc/yum.repos.d/nginx.repo #yum install -y nginx service nginx start # 启动Nginx服务 service nginx stop # 停止Nginx服务 /etc/nginx/nginx.conf # Nginx配置文件位置 [nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=0 enabled=1
Nginx配置访问
Nginx #iptables -A IN_public_allow -p tcp -m tcp --dport 80 -m conntrack --ctstate NEW -j ACCEPT #nginx -t [root@10 ~]# cat /etc/nginx/nginx.confuser nginx;worker_processes 1;error_log /var/log/nginx/error.log warn;pid /var/run/nginx.pid;events { worker_connections 1024;}http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main ‘$remote_addr - $remote_user [$time_local] “$request” ’ ‘$status $body_bytes_sent “$http_referer” ’ ‘“$http_user_agent” “$http_x_forwarded_for”’; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; upstream blog.91tianwu.com {server localhost:8000 weight=5; } server {listen 80; server_name blog.91tianwu.com;location / {proxy_pass http:// blog.91tianwu.com/;} } include /etc/nginx/conf.d/*.conf; client_max_body_size 20m;}
WordPress安装
MySQL的database创建
WordPress的下载和解压
#wget https://cn.wordpress.org/wordpress-4.5.2-zh_CN.tar.gz #tar –zxf word* #php -S localhost:8000
多域名的Nginx配置和WordPress设置
[root@10 ~]# cat /etc/nginx/nginx.confuser nginx;worker_processes 1;error_log /var/log/nginx/error.log warn;pid /var/run/nginx.pid;events { worker_connections 1024;}http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; upstream blog.91tianwu.com {server localhost:8000 weight=5; } upstream bbs.91tianwu.com {server localhost:8001 weight=5; } server {listen 80; server_name blog.91tianwu.com;location / {proxy_pass http://blog.91tianwu.com/;} } server {listen 80; server_name bbs.91tianwu.com;location / {proxy_pass http://bbs.91tianwu.com/; } } include /etc/nginx/conf.d/*.conf; client_max_body_size 20m;} #php -S localhost:8000 #php -S localhost:8001
Database建立2个
Nginx配置2个域名和proxy
启动配置WordPress
推荐资料
李明老师讲Linux
《php和mysql web开发》
网站
http://php.net/
没有比官网更权威的了!
推荐免费视频
一小时学会建网站(三乐大掌柜)
基本参考文献
http://php.net/
http://php.net/manual/en/
排错时使用
http://blog.chinaunix.net/uid-26719405-id-3409842.html http://stackoverflow.com/questions/16765158/date-it-is-not-safe-to-rely-on-the-systems-timezone-settings http://php.net/manual/zh/datetime.configuration.php#ini.date.timezone附录:Linux服务器安全设置
iptables关闭 /sbin/iptables -P INPUT ACCEPT /sbin/iptables -F Iptables -nL #iptables -A IN_public_allow -p tcp -m tcp --dport 80 -m conntrack --ctstate NEW -j ACCEPT #iptables -A IN_public_allow -p tcp -m tcp --dport 21-m conntrack --ctstate NEW -j ACCEPT SELinux关闭 /usr/sbin/sestatus -v
修改/etc/selinux/config 文件
将SELINUX=enforcing改为SELINUX=disabled
重启机器即可
附录:Linux服务器FTP安装
#yum install vsftpd –y #useradd -d /phproot/blog -m -s /sbin/nologin blogftp #mkdir -p /phproot/blog #chown -R blogftp.blogftp /phproot/blog #passwd blogftp vi /etc/vsftpd/vsftpd.conf #禁止匿名访问 anonymous_enable=NO #用户只能访问限制的目录 chroot_local_user=YES #service vsftpd restart #cd /phproot/blog #touch test.txt $ftp [email protected] 报错:500 OOPS: vsftpd: refusing to run with writable root inside chroot() #vi /etc/vsftpd/vsftpd.conf allow_writeable_chroot=YES 报错:500 OOPS: could not read chroot() list file:/etc/vsftpd/chroot_list vi /etc/vsftpd/vsftpd.conf 设置 chroot_local_user=YES chroot_list_enable=YES # (default follows) chroot_list_file=/etc/vsftpd/chroot_list vi /etc/vsftpd/chroot_list 添加用户名 chmod 755 blog/
附录:Linux下PHP环境变量设置
[root@twjp bin]# cat ~/.bash_profile # .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PHP_HOME=/usr/local/php PATH=$PATH:$HOME/bin:$PHP_HOME/bin export PATH