搭建Linux平臺PHP、MySQL、Apache環境
Apache
簡述
本文主要講述在 vps
主機上部署 apache
伺服器,首先需要購買 vps
主機,其次需要購買域名,再將域名解析到 vps
主機的 ip
地址上,以後就可以使用該域名訪問我們的伺服器了。
軟體下載
進入 官網 ,點選 Download
– 2.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
,解壓縮
[[email protected] apache]# tar xf httpd-2.4.29.tar.gz
[[email protected] httpd-2.4.29]# ./configure --prefix=/opt/app/apache
configure:
configure: Configuring Apache Portable Runtime library...
configure:
checking for APR... no
configure: error: APR not found. Please read the documentation.
安裝 apr
到官網 下載 apr
,檔名為:apr-1.6.3.tar.gz
,解壓縮
[[email protected] apache]# tar xf apr-1.6.3.tar.gz
[[email protected] apr-1.6.3]# ./configure --prefix=/opt/app/apr
[[email protected] apr-1.6.3]# make
[[email protected] 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
,解壓縮
[[email protected] apache]# tar xf apr-util-1.6.1.tar.gz
[[email protected] apr-util-1.6.1]# ./configure --prefix=/opt/app/apr-util --with-apr=/opt/app/apr/bin/apr-1-config
[[email protected] apr-util-1.6.1]# make
xml/apr_xml.c:35:19: error: expat.h: No such file or directory
[[email protected] apr-util-1.6.1]# yum install expat-devel
[[email protected] apr-util-1.6.1]# make
[[email protected] apr-util-1.6.1]# make install
繼續…
[[email protected] 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
[[email protected] httpd-2.4.29]# make
[[email protected] httpd-2.4.29]# make install
測試
[[email protected] apache]# /opt/app/apache/bin/apachectl -k start
AH00557: httpd: apr_sockaddr_info_get() failed for host.localdomain
AH00558: 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.
#
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
#
# 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"
<Directory "/home/sy/XGManager/home">
PHP
軟體下載
進入 官網 ,點選 Downloads
,找到標題:php-7.2.0.tar.gz (sig) [17,849Kb]
下載的檔名:
php-7.2.0.tar.gz
編譯
安裝編譯環境
[[email protected] php-7.2.0]# yum groupinstall "Development tools"
[[email protected] php-7.2.0]# yum install libxml2-devel gd-devel libmcrypt-devel libcurl-devel openssl-devel
配置
[[email protected] 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
[[email protected] php-7.2.0]# make
cc: Internal error: Killed (program cc1)
Please submit a full bug report.
See <http://bugzilla.redhat.com/bugzilla> for instructions.
make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1
原因是記憶體不足,需要使用交換分割槽,增加交換分割槽:
[[email protected] php-7.2.0]# sudo dd if=/dev/zero of=/swapfile bs=64M count=16
[[email protected] php-7.2.0]# sudo mkswap /swapfile
[[email protected] php-7.2.0]# sudo swapon /swapfile
[[email protected] php-7.2.0]# make install
編譯完成,刪除交換分割槽:
[[email protected] php-7.2.0]# sudo swapoff /swapfile
[[email protected] php-7.2.0]# sudo rm /swapfile
拷貝配置檔案:
[[email protected] 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.so
LoadModule php7_module modules/libphp7.so
PHPIniDir "/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=curl
extension=gd2
extension=mbstring
extension=mysqli
extension=pdo_mysql
extension=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
[[email protected] apache]# /opt/app/apache/bin/apachectl -k restart
測試
首先 ,在目錄/home/sy/XGManager/home
放置一個檔案 index.php
,輸入內容:
<?php
phpinfo();
?>
重新整理網頁,如果能夠看到以下畫面,說明 Apache
已經關聯了 PHP
。
MySQL
軟體安裝
[[email protected] home]# yum install mysql
[[email protected] home]# yum install mysql-server
[[email protected] home]# yum install mysql-devel
[[email protected] 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_installation
Please report any problems with the /usr/bin/mysqlbug script!
[ OK ]
Starting mysqld: [ OK ]
[[email protected] home]# mysql -uroot -p
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.1.73 Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
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
[[email protected] home]# service mysqld restart
登入新使用者
[[email protected] 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
內容:
<?php
$connect=mysqli_connect("127.0.0.1","root","10929131");
if (!$connect)
echo "Mysql Connect Error!";
else
echo "MySQL OK!";
mysqli_close($connect);
?>
看到列印: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 daemon
Group daemon
我們修改為:sy
,重啟 apache
,
[[email protected] /]# /opt/app/apache/bin/apachectl -k restart
[[email protected] /]# 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
警告。
檢視網站目錄的所有者:
[[email protected] /]# ls -al /home/sy/XGManager/
total 32
drwxr-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 .buildpath
drwxr-xr-x 8 root root 4096 Dec 30 08:35 .git
drwxr-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.md
drwxr-xr-x 2 root root 4096 Dec 30 08:35 .settings
可以看到所有者為 root
,而我們建立的 apache
worker
程序的所有者為 sy
,許可權不足,因此報錯。
需要修改為以下內容:
[[email protected] app]# chown -R sy:sy /home/sy/XGManager/home/
再次上傳,遇到問題:Unknown: file created in the system's temporary directory in Unknown on line 0
由於我們配置 [[email protected] /]# vim /opt/app/php/php-7.2.0/php.ini
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"
檔案上傳時,會臨時儲存到 upload_tmp_dir
指定的目錄,因此,該目錄的所有者也應該是 sy
[[email protected] 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
修改使用者許可權:
[[email protected] home]# chown sy:sy -R /opt/app/php/PHPSessionTmp/
參考教程
相關推薦
搭建Linux平臺PHP、MySQL、Apache環境
Apache 簡述 本文主要講述在 vps 主機上部署 apache 伺服器,首先需要購買 vps 主機,其次需要購買域名,再將域名解析到 vps 主機的 ip 地址上,以後就可以使用該域名訪問我們的伺服器了。 軟體下載 進入 官網 ,點選 D
Centos6.8下搭建LAMP(Linux、Apache、MySQL、PHP)環境
Centos6.8下搭建LAMP(Linux、Apache、MySQL、PHP)環境 一.安裝Apache服務 1. 命令如下:sudo yum install httpd –y 注:採用該方法安裝Apac
Ubuntu搭建 Apache、MySQL、PHP環境
分享 管理員 mysq ima 表示 ubunt ets .cn image 以Ubuntu 16.04為例: 1、安裝MysSQL 打開命令行輸入 :sudo apt-get install mysql-server 輸入管理員密碼 選擇Y 在安裝的中間會出現輸
阿里雲CentOS 7.3 裸機搭建 Apache、MySql、PHP、Node環境、並繫結域名
阿里雲CentOS 7.3 裸機搭建 Apache、MySql、PHP、Node境、並繫結域名 最近一直想在阿里雲申請一個伺服器,可以在上面跑一些服務,輸入域名訪問,那種感覺肯定很不一樣。所以就花學生價買了一年,還是挺划算的。 域名備案花了挺長時間,又上傳照片又打電話核實的挺麻煩的,不過
lamp平臺構建(Apache、MySQL、PHP)
環境說明: 系統平臺 IP 需要安裝的服務 redhat 192.168.102.128 httpd-2.4mysql-5.7phpphp-mysql
Linux下的Nginx、php、mysql、apache部署
待補充,先搞幾個部落格連結: https://www.cnblogs.com/Candies/p/8282934.html http://sujianjob.com/2017/12/18/yum%E5%AE%89%E8%A3%85apahce%E3%80%81php%E3%80%81MySQL-%E5%A
CentOS7搭建apache/nginx、mysql、php、phpmyadmin環境
最近在看鳥哥的私房菜Linux,所以就在買了一個國外的伺服器來折騰,首先就搭建了一下基本的web伺服器。過程中遇到了各種坑,總結了一下,寫出來,避免大家踩坑。 1.安裝apache或nginx伺服器 /***************apache***
Windows/Linux 下檢視Apache、Mysql、PHP版本
做程式開發,我們免不了要知道開發環境下的Apache、Mysql、PHP版本,下面就三項在Windows和Linux下如何進行版本檢視進行展開。 1、Apache (1) Windows檢視Apache版本: 使用命令:httpd -v (2) Linux
wampServer(windows、apache、mysql、php)
list mysql 配置 allow error del 默認 virtual listen wampServer(windows/apche/mysql/php)集成環境 在線狀態:區域網內可以訪問 離線狀態:本地設備可以訪問 自擬定網站根目錄: Apache -- h
centos7重啟apache、nginx、mysql、php-fpm命令
httpd stop 啟動 sta fpm start res gin SQ apache 啟動 systemctl start httpd 停止 systemctl stop httpd 重啟 systemctl restart httpd mysql 啟動 system
查看Linux 、Nginx、 MySQL 、 PHP 版本的方法
style tps HR version light gda targe true pac 參考:查看Linux 、Apache 、 MySQL 、 PHP 版本的方法 1.查看Linux版本: uname -a; more /etc/issue; cat /proc/ve
Nginx系列-2.配置LNMP(Linux、Nginx、MySQL、PHP)架構
Linux Nginx Nginx系列-2.配置LNMP(Linux、Nginx、MySQL、PHP)架構 目錄 - Nginx系列 Nginx系列-1.Linux下安裝Nginx Nginx系列-2.配置LNMP(Linux、Nginx、MySQL、PHP)架構 Nginx系列-3.配置Ngi
Linux下啟動,停止,重啟Nginx、Mysql、PHP
LINUX啟動Nginx的命令: 一、查詢是否啟動 [[email protected] php-fpm.d]# ps -ef | grep nginx root 25225 1 0 19:26 ? 00:00:00 nginx: master process
檢視Linux系統、Apche、Nginx、 MySQL 、 PHP 版本
1.檢視Linux版本: 1、uname -a; 2、more /etc/issue; 3、cat /proc/version; 2.檢視Mysql版本: 1、 在終端下執行 mysql -V
Centos 7.2 安裝Apache、PHP、Mysql、連線Mysql資料庫的包、安裝VSFTP、並配置
一、安裝Apache、PHP、Mysql、連線Mysql資料庫的包: yum install httpd yum -y install php yum -y install php-fpm yum -y install php-mysql yum -y inst
在Ubuntu上安裝LAMP(Apache、Mysql、Php)
原文地址:https://howtoubuntu.org/how-to-install-lamp-on-ubuntu Ubuntu有很多工具可以幫助我們一鍵配置LAMP環境,比如tasksel,但這些工具在安裝軟體的過程中經常會修改你的某些配置,比如防火牆配置。日後你的某些埠打不開,應用連不上,往往就是這些
CentOS 7 firewalld新增開放埠及重啟apache、nginx、mysql、php-fpm命令 & CentOS 6.5開放埠方法
How to resolve the error message belowFailed to issue method call: Unit firewalld.service is masked. The main reason a service is masked is to prevent acc
PHP:WampServer下如何安裝多個版本的PHP、mysql、apache
作為Web開發人員,在機器上安裝不同版本的php,apache和mysql有時是很有必要的。 今天,我在除錯一套PHP程式的時候,該程式中使用的某些函式在低版本中無法使用,所以只能在搞個高版本的php。 以下是我成功配置後的截圖 不同版本的PHP: 不同版本的Apache: 這裡我以
Linux安裝java jdk、mysql、tomcat
ref app 1.0 重置密碼 esc 啟動mysql TP mar des 安裝javajdk 1.8 檢查是否安裝 rpm -qa | grep jdk rpm方式安裝 下載java1.8 jdk http://download.oracle.com/otn-pub/
linux下zookeeper、redis、activemq、solr、mysql、nginx啟動、停止、檢視狀態命令
一、zookeeper 首先進入zookeeper/bin目錄下 *啟動 ./zkServer.sh start *停止 ./zkServer.sh stop *檢視狀態 ./zkServer.sh status 二、redis 1、 redis簡潔安裝 re