博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
搭建Linux平台PHP、MySQL、Apache环境
阅读量:4086 次
发布时间:2019-05-25

本文共 8599 字,大约阅读时间需要 28 分钟。

Apache

简述

本文主要讲述在 vps 主机上部署 apache 服务器,首先需要购买 vps 主机,其次需要购买域名,再将域名解析到 vps 主机的 ip 地址上,以后就可以使用该域名访问我们的服务器了。

软件下载

进入 ,点击 Download2.4.29 (released 2017-10-23)Source: httpd-2.4.29.tar.gz [ PGP ] [ MD5 ] [ SHA1 ] [ SHA256 ] ,下载后,文件名为:httpd-2.4.29.tar.gz

软件安装

安装必要的库

yum -y install gcc gcc-c++ openssl-devel zlib-deve pcre pcre-devel

将文件拷贝到 Linux ,解压缩

[root@host apache]# tar xf httpd-2.4.29.tar.gz[root@host httpd-2.4.29]# ./configure --prefix=/opt/app/apacheconfigure: configure: Configuring Apache Portable Runtime library...configure: checking for APR... noconfigure: error: APR not found.  Please read the documentation.

安装 apr

到 下载 apr ,文件名为:apr-1.6.3.tar.gz ,解压缩

[root@host apache]# tar xf apr-1.6.3.tar.gz[root@host apr-1.6.3]# ./configure --prefix=/opt/app/apr[root@host apr-1.6.3]# make[root@host apr-1.6.3]# make install

继续编译

configure: error: APR-util not found. Please read the documentation.

安装apr-util

到 下载 apr-util ,文件名为:apr-util-1.6.1.tar.gz ,解压缩

[root@host apache]# tar xf apr-util-1.6.1.tar.gz[root@host apr-util-1.6.1]# ./configure --prefix=/opt/app/apr-util --with-apr=/opt/app/apr/bin/apr-1-config[root@host apr-util-1.6.1]# make xml/apr_xml.c:35:19: error: expat.h: No such file or directory[root@host apr-util-1.6.1]# yum install expat-devel[root@host apr-util-1.6.1]# make [root@host apr-util-1.6.1]# make install

继续…

[root@host httpd-2.4.29]# ./configure --prefix=/opt/app/apache --with-apr=/opt/app/apr/bin/apr-1-config --with-apr-util=/opt/app/apr-util/bin/apu-1-config --enable-so[root@host httpd-2.4.29]# make[root@host httpd-2.4.29]# make install

测试

[root@host apache]# /opt/app/apache/bin/apachectl -k startAH00557: httpd: apr_sockaddr_info_get() failed for host.localdomainAH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message

配置

打开 httpd.conf ,对比源文件,修改为以下内容:

#LoadModule watchdog_module modules/mod_watchdog.so#LoadModule xml2enc_module modules/mod_xml2enc.so## DirectoryIndex: sets the file that Apache will serve if a directory# is requested.#
DirectoryIndex index.php index.html
## DocumentRoot: The directory out of which you will serve your# documents. By default, all requests are taken from this directory, but# symbolic links and aliases may be used to point to other locations.#DocumentRoot "/home/sy/XGManager/home"

PHP

软件下载

进入 ,点击 Downloads ,找到标题:php-7.2.0.tar.gz (sig) [17,849Kb] 下载的文件名:

php-7.2.0.tar.gz

编译

安装编译环境

[root@host php-7.2.0]# yum groupinstall "Development tools"[root@host php-7.2.0]# yum install libxml2-devel gd-devel libmcrypt-devel libcurl-devel openssl-devel

配置

[root@host php-7.2.0]# ./configure --prefix=/opt/app/php/php-7.2.0 --with-apxs2=/opt/app/apache/bin/apxs --disable-cli --enable-shared --with-libxml-dir --with-gd --with-openssl --enable-mbstring --with-mysqli --enable-opcache --enable-zip --with-zlib-dir --with-pdo-mysql --with-jpeg-dir --with-freetype-dir --with-curl --without-pdo-sqlite --without-sqlite3[root@host php-7.2.0]# makecc: Internal error: Killed (program cc1)Please submit a full bug report.See 
for instructions.make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1原因是内存不足,需要使用交换分区,增加交换分区:[root@host php-7.2.0]# sudo dd if=/dev/zero of=/swapfile bs=64M count=16[root@host php-7.2.0]# sudo mkswap /swapfile[root@host php-7.2.0]# sudo swapon /swapfile[root@host php-7.2.0]# make install编译完成,删除交换分区:[root@host php-7.2.0]# sudo swapoff /swapfile[root@host php-7.2.0]# sudo rm /swapfile

拷贝配置文件:

[root@host php-7.2.0]# cp php.ini-development /opt/app/php/php-7.2.0/php.ini

关联 apache

打开 httpd.conf ,对比源文件,修改为以下内容:

#LoadModule rewrite_module modules/mod_rewrite.soLoadModule php7_module        modules/libphp7.soPHPIniDir "/opt/app/php/php-7.2.0/"AddType application/x-httpd-php .php .html .htm

配置 php

修改 php.ini 为以下内容:

; Directory in which the loadable extensions (modules) reside.; http://php.net/extension-dir; extension_dir = "./"; On windows:; extension_dir = "ext"extension_dir = "/opt/app/php/php-7.2.0/ext"extension=curlextension=gd2extension=mbstringextension=mysqliextension=pdo_mysqlextension=xmlrpc[Date]; Defines the default timezone used by the date functions; http://php.net/date.timezone;date.timezone =date.timezone = Asia/Shanghai; where MODE is the octal representation of the mode. Note that this; does not overwrite the process's umask.; http://php.net/session.save-path;session.save_path = "/tmp"session.save_path = "/opt/app/php/PHPSessionTmp"; Temporary directory for HTTP uploaded files (will use system default if not; specified).; http://php.net/upload-tmp-dir;upload_tmp_dir =upload_tmp_dir = "/opt/app/php/PHPFileUploadTmp"

重启 Apache

[root@host apache]# /opt/app/apache/bin/apachectl -k restart

测试

首先 ,在目录/home/sy/XGManager/home 放置一个文件 index.php ,输入内容:

刷新网页,如果能够看到以下画面,说明 Apache 已经关联了 PHP

这里写图片描述

MySQL

软件安装

[root@host home]# yum install mysql[root@host home]# yum install mysql-server[root@host home]# yum install mysql-devel[root@host home]# service mysqld restart/usr/bin/mysqladmin -u root password 'new-password'/usr/bin/mysqladmin -u root -h host.localdomain password 'new-password'Alternatively you can run:/usr/bin/mysql_secure_installationPlease report any problems with the /usr/bin/mysqlbug script!                                                           [  OK  ]Starting mysqld:                                           [  OK  ][root@host home]# mysql -uroot -pWelcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 8Server version: 5.1.73 Source distributionCopyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

插入用户:

mysql> insert into mysql.user(Host,User,Password) values('@','sy',password('********'));

重启 Mysql

[root@host home]# service mysqld restart

登录新用户

[root@host home]# mysql -u sy -p

PHPMyAdmin

软件下载

进入 ,点击 download ,下载的文件名为:phpMyAdmin-4.7.5-all-languages.zip

软件安装

将解压后的文件夹重命名为 phpMyAdmin ,放到目录:C:\Users\SY\Desktop\GIT\Software\PHP\Apache_Workspace\PHP\HOME ,在浏览器输入: 即可访问。

测试

修改 index.php 内容:

看到打印:MySQL OK! ,说明连接数据库成功!注意 PHP7 以后使用 mysqli 代替 mysql

搭建应用程序

apache 默认配置的用户为 daemon ,我们打开文件:/opt/app/apache/conf/httpd.conf

## If you wish httpd to run as a different user or group, you must run# httpd as root initially and it will switch.  ## User/Group: The name (or #number) of the user/group to run httpd as.# It is usually good practice to create a dedicated user and group for# running httpd, as with most system services.#User daemonGroup daemon

我们修改为:sy ,重启 apache

[root@host /]# /opt/app/apache/bin/apachectl -k restart [root@host /]# ps -ef | grep apache  root     23485     1  0 03:03 ?        00:00:00 /opt/app/apache/bin/httpd -k start  sy       25653 23485  0 04:02 ?        00:00:00 /opt/app/apache/bin/httpd -k start  sy       25654 23485  0 04:02 ?        00:00:00 /opt/app/apache/bin/httpd -k start  sy       25655 23485  0 04:02 ?        00:00:00 /opt/app/apache/bin/httpd -k start  root     25746 20184  0 04:03 pts/0    00:00:00 grep apache

可以看到我们的 uid 变为了 sy

当我们向网站上传文件时,弹出:unknow:file created in the system's temporatory in Unknown on line 0 警告。

查看网站目录的所有者:

[root@host /]# ls -al /home/sy/XGManager/total 32drwxr-xr-x 5 root root 4096 Dec 30 08:35 .drwxr-xr-x 6 root root 4096 Jan  1 09:17 ..-rwxr-xr-x 1 root root  169 Dec 30 08:35 .buildpathdrwxr-xr-x 8 root root 4096 Dec 30 08:35 .gitdrwxr-xr-x 9 root   root   4096 Jan  2 03:54 home-rwxr-xr-x 1 root root  697 Dec 30 08:35 .project-rwxr-xr-x 1 root root   49 Dec 30 08:35 README.mddrwxr-xr-x 2 root root 4096 Dec 30 08:35 .settings

可以看到所有者为 root ,而我们创建的 apache worker 进程的所有者为 sy ,权限不足,因此报错。

需要修改为以下内容:

[root@host app]# chown -R sy:sy /home/sy/XGManager/home/

再次上传,遇到问题:Unknown: file created in the system's temporary directory in Unknown on line 0

由于我们配置 [root@host /]# vim /opt/app/php/php-7.2.0/php.ini

Temporary directory for HTTP uploaded files (will use system default if notspecified).http://php.net/upload-tmp-dirupload_tmp_dir =upload_tmp_dir = "opt/app/php/PHPFileUploadTmp"

文件上传时,会临时存储到 upload_tmp_dir 指定的目录,因此,该目录的所有者也应该是 sy

[root@host app]# chown -R sy:sy /opt/app/php/PHPFileUploadTmp/

再次测试,上传成功!

遇到问题:

Warning: session_start(): open(/opt/app/php/PHPSessionTmp/sess_qt1lthvdd2buesvglt0piji5l5, O_RDWR) failed: Permission denied (13) in /home/sy/XGManager/home/utils/head.php on line 39

修改用户权限:

[root@host home]# chown sy:sy -R /opt/app/php/PHPSessionTmp/

参考教程

你可能感兴趣的文章
realsense-ros里里程计相关代码
查看>>
似乎写个ROS功能包并不难,你会订阅话题发布话题,加点逻辑处理,就可以写一些基础的ROS功能包了。
查看>>
if __name__ == ‘__main__‘:就是Python里的main函数,脚本从这里开始执行,如果没有main函数则从上到下顺序执行。
查看>>
PX4官方用户和开发手册的首页面是会给你选择英文和中文的
查看>>
网络协议栈我是不是可以这么理解,就是把你要发送的数据自动处理成TCPIP格式的消息发出去,这种底层的转换不需要你弄了。
查看>>
除了LwIP还有uIP
查看>>
《跟工程师学嵌入式开发》这本书最后的终极项目我反而觉得有说头
查看>>
博士的申请考核制
查看>>
那些硬件的初始化函数主要是在做些上什么?
查看>>
MAVLink学习之路05_MAVLink应用编程接口分析(也有讲STM32下的收发函数)
查看>>
找到了中文版的mavlink手册
查看>>
浅谈飞控开发的仿真功能
查看>>
我觉得在室内弄无人机开发装个防撞机架还是很有必要的,TBUS就做得很好。
查看>>
serial也是见到很多次了,似乎它就是一种串行通信协议
查看>>
TBUS的一些信息
查看>>
PX4+激光雷达在gazebo中仿真实现(古月居)
查看>>
专业和业余的区别就在于你在基础在基本功打磨练习花的时间
查看>>
通过mavlink实现自主航线的过程笔记
查看>>
Ardupilot飞控Mavlink代码学习
查看>>
这些网站有一些嵌入式面试题合集
查看>>