腾讯云里安装php的方法:1、注册腾讯云并租用一台服务器;2、使用putty.exe进行远程登录;3、在服务器中安装aphache及php等软件;4、修改好配置文件即可。
本文操作环境:centos 7.2系统、php7.1.2版、dell g3电脑
腾讯云里如何安装php?
腾讯云从零搭建php运行环境
一、首先我们得注册腾讯云,租用一台服务器,我选择的是centos 7.2 64位,这时候会给你这台主机的公网ip和内网ip,以及这台主机的用户名及密码。
二、我们可以使用腾讯云网页上自带的登录按钮进行登录,也可以使用putty进行登录,下面我们使用putty进行远程操作。
1、百度putty,可以下载最新的putty,下载下来是一个压缩包:
psftp.exe用于文件传输,我们使用putty.exe进行远程登录:
2、我们使用ssh方式连接比较安全,默认端口是22。点击载入,这时候会提示我们输入用户名和密码,正确输入后,登录成功!
三、我们要在服务器中安装aphache、php等软件,就避免不了忘服务器中上传文件,我推荐大家使用winscp这款软件,方便直观。
1、百度winscp,可以下载最新的版本,安装成功后,输入服务器的公网ip,用户名,密码之后就可以成功登陆了,如图:
四、工具都准备好之后,我们就可以开始搭建我们的环境了,具体可以参考 http://www.cnblogs.com/lufangtao/archive/2012/12/30/2839679.html 这篇文章,写的很透彻。
1、首先安装apache,到官网下载linux安装包:http://httpd.apache.org/download.cgi
安装apache前,需要安装apr和apr-util、prce
apr和apr-util下载地址:http://apr.apache.org/download.cgi?preferred=http%3a%2f%2fmirrors.hust.edu.cn%2fapache%2f
prce下载地址:http://jaist.dl.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
我们将这四个压缩文件全部下载下来:
2、用winscp将这四个文件全部上传到服务器之后,解压:
tar -zxvf httpd-2.4.25.tar.gz
tar -zxvf apr-1.5.2.tar.gz
tar -zxvf apr-util-1.5.4.tar.gz
tar -zxvf pcre-8.35.tar.gz
3、安装gcc:yum install gcc
安装c++编译器:yum install gcc-c++
4、安装apr:
进入解压后apr文件夹:cd apr-1.5.2
安装前校验:./configure --prefix=/usr/local/apr
编译:make
安装:make install
5、安装apr-util:
进入解压后的apr-util文件夹:cd apr-util-1.5.4
安装前校验:./confiure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
编译:make
安装:make install
6、安装pcre:
进入解压后的pcre文件夹:cd pcre-8.35
安装前校验:./configure --prefix=/usr/local/pcre
编译:make
安装:make instal
7、安装apache:
进入解压后的apache文件夹:cd httpd-2.4.25
安装前校验:./configure --prefix=/usr/local/apache2 --enable-module=shared --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre
编译:make
安装:make install
8、启动,重启和停止 ,先切换到安装完成后的目录/usr/local/apache2/bin
./apachectl -k start
./apachectl -k restart
./apachectl -k stop
9、配置文件:(满足最基本的配置)
## this is the main apache http server configuration file. it contains the# configuration directives that give the server its instructions.# see <url:http://httpd.apache.org/docs/2.4/> for detailed information.# in particular, see # <url:http://httpd.apache.org/docs/2.4/mod/directives.html># for a discussion of each configuration directive.## do not simply read the instructions in here without understanding# what they do. they're here only as hints or reminders. if you are unsure# consult the online docs. you have been warned. ## configuration and logfile names: if the filenames you specify for many# of the server's control files begin with / (or drive:/ for win32), the# server will use that explicit path. if the filenames do *not* begin# with /, the value of serverroot is prepended -- so logs/access_log# with serverroot set to /usr/local/apache2 will be interpreted by the# server as /usr/local/apache2/logs/access_log, whereas /logs/access_log # will be interpreted as '/logs/access_log'.## serverroot: the top of the directory tree under which the server's# configuration, error, and log files are kept.## do not add a slash at the end of the directory path. if you point# serverroot at a non-local disk, be sure to specify a local disk on the# mutex directive, if file-based mutexes are used. if you wish to share the# same serverroot for multiple httpd daemons, you will need to change at# least pidfile.#serverroot /usr/local/apache2## mutex: allows you to set the mutex mechanism and mutex file directory# for inpidual mutexes, or change the global defaults## uncomment and change the directory if mutexes are file-based and the default# mutex file directory is not on a local disk or is not appropriate for some# other reason.## mutex default:logs## listen: allows you to bind apache to specific ip addresses and/or# ports, instead of the default. see also the <virtualhost># directive.## change this to listen on specific ip addresses as shown below to # prevent apache from glomming onto all bound ip addresses.##listen 12.34.56.78:80listen 80## dynamic shared object (dso) support## to be able to use the functionality of a module which was built as a dso you# have to place corresponding `loadmodule' lines at this location so the# directives contained in it are actually available _before_ they are used.# statically compiled modules (those listed by `httpd -l') do not need# to be loaded here.## example:# loadmodule foo_module modules/mod_foo.so#loadmodule authn_file_module modules/mod_authn_file.so#loadmodule authn_dbm_module modules/mod_authn_dbm.so#loadmodule authn_anon_module modules/mod_authn_anon.so#loadmodule authn_dbd_module modules/mod_authn_dbd.so#loadmodule authn_socache_module modules/mod_authn_socache.soloadmodule authn_core_module modules/mod_authn_core.soloadmodule authz_host_module modules/mod_authz_host.soloadmodule authz_groupfile_module modules/mod_authz_groupfile.soloadmodule authz_user_module modules/mod_authz_user.so#loadmodule authz_dbm_module modules/mod_authz_dbm.so#loadmodule authz_owner_module modules/mod_authz_owner.so#loadmodule authz_dbd_module modules/mod_authz_dbd.soloadmodule authz_core_module modules/mod_authz_core.soloadmodule access_compat_module modules/mod_access_compat.soloadmodule auth_basic_module modules/mod_auth_basic.so#loadmodule auth_form_module modules/mod_auth_form.so#loadmodule auth_digest_module modules/mod_auth_digest.so#loadmodule allowmethods_module modules/mod_allowmethods.so#loadmodule file_cache_module modules/mod_file_cache.so#loadmodule cache_module modules/mod_cache.so#loadmodule cache_disk_module modules/mod_cache_disk.so#loadmodule cache_socache_module modules/mod_cache_socache.so#loadmodule socache_shmcb_module modules/mod_socache_shmcb.so#loadmodule socache_dbm_module modules/mod_socache_dbm.so#loadmodule socache_memcache_module modules/mod_socache_memcache.so#loadmodule watchdog_module modules/mod_watchdog.so#loadmodule macro_module modules/mod_macro.so#loadmodule dbd_module modules/mod_dbd.so#loadmodule dumpio_module modules/mod_dumpio.so#loadmodule buffer_module modules/mod_buffer.so#loadmodule ratelimit_module modules/mod_ratelimit.soloadmodule reqtimeout_module modules/mod_reqtimeout.so#loadmodule ext_filter_module modules/mod_ext_filter.so#loadmodule request_module modules/mod_request.so#loadmodule include_module modules/mod_include.soloadmodule filter_module modules/mod_filter.so#loadmodule substitute_module modules/mod_substitute.so#loadmodule sed_module modules/mod_sed.soloadmodule mime_module modules/mod_mime.soloadmodule log_config_module modules/mod_log_config.so#loadmodule log_debug_module modules/mod_log_debug.so#loadmodule logio_module modules/mod_logio.soloadmodule env_module modules/mod_env.so#loadmodule expires_module modules/mod_expires.soloadmodule headers_module modules/mod_headers.so#loadmodule unique_id_module modules/mod_unique_id.soloadmodule setenvif_module modules/mod_setenvif.soloadmodule version_module modules/mod_version.so#loadmodule remoteip_module modules/mod_remoteip.so#loadmodule proxy_module modules/mod_proxy.so#loadmodule proxy_connect_module modules/mod_proxy_connect.so#loadmodule proxy_ftp_module modules/mod_proxy_ftp.so#loadmodule proxy_http_module modules/mod_proxy_http.so#loadmodule proxy_fcgi_module modules/mod_proxy_fcgi.so#loadmodule proxy_scgi_module modules/mod_proxy_scgi.so#loadmodule proxy_fdpass_module modules/mod_proxy_fdpass.so#loadmodule proxy_wstunnel_module modules/mod_proxy_wstunnel.so#loadmodule proxy_ajp_module modules/mod_proxy_ajp.so#loadmodule proxy_balancer_module modules/mod_proxy_balancer.so#loadmodule proxy_express_module modules/mod_proxy_express.so#loadmodule proxy_hcheck_module modules/mod_proxy_hcheck.so#loadmodule session_module modules/mod_session.so#loadmodule session_cookie_module modules/mod_session_cookie.so#loadmodule session_dbd_module modules/mod_session_dbd.so#loadmodule slotmem_shm_module modules/mod_slotmem_shm.so#loadmodule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so#loadmodule lbmethod_bytraffic_module modules/mod_lbmethod_bytraffic.so#loadmodule lbmethod_bybusyness_module modules/mod_lbmethod_bybusyness.so#loadmodule lbmethod_heartbeat_module modules/mod_lbmethod_heartbeat.soloadmodule unixd_module modules/mod_unixd.so#loadmodule dav_module modules/mod_dav.soloadmodule status_module modules/mod_status.soloadmodule autoindex_module modules/mod_autoindex.so#loadmodule info_module modules/mod_info.so#loadmodule cgid_module modules/mod_cgid.so#loadmodule dav_fs_module modules/mod_dav_fs.so#loadmodule vhost_alias_module modules/mod_vhost_alias.so#loadmodule negotiation_module modules/mod_negotiation.soloadmodule dir_module modules/mod_dir.so#loadmodule actions_module modules/mod_actions.so#loadmodule speling_module modules/mod_speling.so#loadmodule userdir_module modules/mod_userdir.soloadmodule alias_module modules/mod_alias.so#loadmodule rewrite_module modules/mod_rewrite.so<ifmodule unixd_module>## 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</ifmodule># 'main' server configuration## the directives in this section set up the values used by the 'main'# server, which responds to any requests that aren't handled by a# <virtualhost> definition. these values also provide defaults for# any <virtualhost> containers you may define later in the file.## all of these directives may appear inside <virtualhost> containers,# in which case these default settings will be overridden for the# virtual host being defined.### serveradmin: your address, where problems with the server should be# e-mailed. this address appears on some server-generated pages, such# as error documents. e.g. admin@your-domain.com#serveradmin you@example.com## servername gives the name and port that the server uses to identify itself.# this can often be determined automatically, but we recommend you specify# it explicitly to prevent problems during startup.## if your host doesn't have a registered dns name, enter its ip address here.#servername localhost:80## deny access to the entirety of your server's filesystem. you must# explicitly permit access to web content directories in other # <directory> blocks below.#<directory /> allowoverride none require all denied</directory>## note that from this point forward you must specifically allow# particular features to be enabled - so if something's not working as# you might expect, make sure that you have specifically enabled it# below.### 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 /usr/local/apache2/htdocs<directory "/usr/local/apache2/htdocs"> # # possible values for the options directive are none, all, # or any combination of: # indexes includes followsymlinks symlinksifownermatch execcgi multiviews # # note that multiviews must be named *explicitly* --- options all # doesn't give it to you. # # the options directive is both complicated and important. please see # http://httpd.apache.org/docs/2.4/mod/core.html#options # for more information. # options indexes followsymlinks # # allowoverride controls what directives may be placed in .htaccess files. # it can be all, none, or any combination of the keywords: # allowoverride fileinfo authconfig limit # allowoverride none # # controls who can get stuff from this server. # require all granted</directory>## directoryindex: sets the file that apache will serve if a directory# is requested.#<ifmodule dir_module> directoryindex index.html directoryindex index.html index.php</ifmodule>## the following lines prevent .htaccess and .htpasswd files from being # viewed by web clients. #<files ".ht*"> require all denied</files>## errorlog: the location of the error log file.# if you do not specify an errorlog directive within a <virtualhost># container, error messages relating to that virtual host will be# logged here. if you *do* define an error logfile for a <virtualhost># container, that host's errors will be logged there and not here.#errorlog logs/error_log## loglevel: control the number of messages logged to the error_log.# possible values include: debug, info, notice, warn, error, crit,# alert, emerg.#loglevel warn<ifmodule log_config_module> # # the following directives define some format nicknames for use with # a customlog directive (see below). # logformat %h %l %u %t \%r\ %>s %b \%{referer}i\ \%{user-agent}i\ combined logformat %h %l %u %t \%r\ %>s %b common <ifmodule logio_module> # you need to enable mod_logio.c to use %i and %o logformat %h %l %u %t \%r\ %>s %b \%{referer}i\ \%{user-agent}i\ %i %o combinedio </ifmodule> # # the location and format of the access logfile (common logfile format). # if you do not define any access logfiles within a <virtualhost> # container, they will be logged here. contrariwise, if you *do* # define per-<virtualhost> access logfiles, transactions will be # logged therein and *not* in this file. # customlog logs/access_log common # # if you prefer a logfile with access, agent, and referer information # (combined logfile format) you can use the following directive. # #customlog logs/access_log combined</ifmodule><ifmodule alias_module> # # redirect: allows you to tell clients about documents that used to # exist in your server's namespace, but do not anymore. the client # will make a new request for the document at its new location. # example: # redirect permanent /foo http://www.example.com/bar # # alias: maps web paths into filesystem paths and is used to # access content that does not live under the documentroot. # example: # alias /webpath /full/filesystem/path # # if you include a trailing / on /webpath then the server will # require it to be present in the url. you will also likely # need to provide a <directory> section to allow access to # the filesystem path. # # scriptalias: this controls which directories contain server scripts. # scriptaliases are essentially the same as aliases, except that # documents in the target directory are treated as applications and # run by the server when requested rather than as documents sent to the # client. the same rules about trailing / apply to scriptalias # directives as to alias. # scriptalias /cgi-bin/ /usr/local/apache2/cgi-bin/</ifmodule><ifmodule cgid_module> # # scriptsock: on threaded servers, designate the path to the unix # socket used to communicate with the cgi daemon of mod_cgid. # #scriptsock cgisock</ifmodule>## /usr/local/apache2/cgi-bin should be changed to whatever your scriptaliased# cgi directory exists, if you have that configured.#<directory "/usr/local/apache2/cgi-bin"> allowoverride none options none require all granted</directory><ifmodule headers_module> # # avoid passing http_proxy environment to cgi's on this or any proxied # backend servers which have lingering httpoxy defects. # 'proxy' request header is undefined by the ietf, not listed by iana # requestheader unset proxy early</ifmodule><ifmodule mime_module> # # typesconfig points to the file containing the list of mappings from # filename extension to mime-type. # typesconfig conf/mime.types # # addtype allows you to add to or override the mime configuration # file specified in typesconfig for specific file types. # #addtype application/x-gzip .tgz # # addencoding allows you to have certain browsers uncompress # information on the fly. note: not all browsers support this. # #addencoding x-compress .z #addencoding x-gzip .gz .tgz # # if the addencoding directives above are commented-out, then you # probably should define those extensions to indicate media types: # addtype application/x-compress .z addtype application/x-gzip .gz .tgz addtype application/x-httpd-php .php addtype application/x-httpd-php-source .php5 # # addhandler allows you to map certain file extensions to handlers: # actions unrelated to filetype. these can be either built into the server # or added with the action directive (see below) # # to use cgi scripts outside of scriptaliased directories: # (you will also need to add execcgi to the options directive.) # #addhandler cgi-script .cgi # for type maps (negotiated resources): #addhandler type-map var # # filters allow you to process content before it is sent to the client. # # to parse .shtml files for server-side includes (ssi): # (you will also need to add includes to the options directive.) # #addtype text/html .shtml #addoutputfilter includes .shtml</ifmodule>## the mod_mime_magic module allows the server to use various hints from the# contents of the file itself to determine its type. the mimemagicfile# directive tells the module where the hint definitions are located.##mimemagicfile conf/magic## customizable error responses come in three flavors:# 1) plain text 2) local redirects 3) external redirects## some examples:#errordocument 500 the server made a boo boo.#errordocument 404 /missing.html#errordocument 404 /cgi-bin/missing_handler.pl#errordocument 402 http://www.example.com/subscription_info.html### maxranges: maximum number of ranges in a request before# returning the entire resource, or one of the special# values 'default', 'none' or 'unlimited'.# default setting is to accept 200 ranges.#maxranges unlimited## enablemmap and enablesendfile: on systems that support it, # memory-mapping or the sendfile syscall may be used to deliver# files. this usually improves server performance, but must# be turned off when serving from networked-mounted # filesystems or if support for these functions is otherwise# broken on your system.# defaults: enablemmap on, enablesendfile off##enablemmap off#enablesendfile on# supplemental configuration## the configuration files in the conf/extra/ directory can be # included to add extra features or to modify the default configuration of # the server, or you may simply copy their contents here and change as # necessary.# server-pool management (mpm specific)#include conf/extra/httpd-mpm.conf# multi-language error messages#include conf/extra/httpd-multilang-errordoc.conf# fancy directory listings#include conf/extra/httpd-autoindex.conf# language settings#include conf/extra/httpd-languages.conf# user home directories#include conf/extra/httpd-userdir.conf# real-time info on requests and configuration#include conf/extra/httpd-info.conf# virtual hosts#include conf/extra/httpd-vhosts.conf# local access to the apache http server manual#include conf/extra/httpd-manual.conf# distributed authoring and versioning (webdav)#include conf/extra/httpd-dav.conf# various default settings#include conf/extra/httpd-default.conf# configure mod_proxy_html to understand html4/xhtml1<ifmodule proxy_html_module>include conf/extra/proxy-html.conf</ifmodule># secure (ssl/tls) connections#include conf/extra/httpd-ssl.conf## note: the following must must be present to support# starting without ssl on platforms with no /dev/random equivalent# but a statically compiled-in mod_ssl.#<ifmodule ssl_module>sslrandomseed startup builtinsslrandomseed connect builtin</ifmodule>
10 、测试:
在浏览器里输入http://公网ip,显示如下,配置成功。
五、安装php
1、官网上下载php压缩包,并上传到服务器解压:http://www.php.net/downloads.php
2、建立目标文件夹mkdir /usr/local/php,等下php安装到该目录下。
3、安装前校验: ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs
可能会提示出现错误:configure: error: xml2-config not found. please check your libxml2 installation。运行yum install libxml2,然后再运行yum install libxml2-devel安装完毕后,重新运行上面的./configure命令。
4、编译:make
5、编译测试:make test
6、编译安装:make install
7、在apache的htdocs下建立一个php文件test.php,里面的内容如下:
<?php phpinfo(); ?>
重启apache服务器,在浏览器中输入:http://公网ip/test.php,结果如下:
php配置成功!
推荐学习:《php视频教程》
以上就是腾讯云里如何安装php的详细内容。