❶ 在php在linux系統下如何發郵件,如果能給出PHP代碼就更好了
PHP發郵件可以使用本身自帶函數mail(),但這需要你設置好伺服器的郵件伺服器。
還可以使用一些已經封裝好的類,我最近一直在使用 PHPMailer 這個類,很好用,發送方式比較多,在Linux下可以使用SMTP,Sendmail等方式發送,你可以下載學習一下。挺簡單的。
❷ linux,php 文件屬性設置原則是什麼什麼情況下設文件屬性可讀、可寫、可執行等。
原則?
能不給運行許可權就不給運行許可權,能不給寫許可權就不給寫許可權,能不給讀許可權就不給讀許可權(當然這不可能)。
注意一點是,目錄沒有運行許可權就不能進入。目錄沒法運行,所以運行許可權對於目錄來說是另一個意思。
這純看你的源代碼怎麼設計的了。
❸ PHP定時備份WEB文件並發送到郵箱
這個其實很簡單,WIN上面一樣可以用定時程序,而且是PHP自帶的,LINUX下用CRONTAB就可以了
在WIN下面用函數-ignore_user_abort,這個函數可以幫助我們實現像linux中的cron一樣實現計劃任務,下面一起來看下該如何來實現。
首先看下php手冊對這個函數的解釋
Description
int ignore_user_abort ([ bool $setting ] )
Sets whether a client disconnect should cause a script to be aborted.
也就是說無論客戶端是否關閉瀏覽器,下面的程序都會執行.
再看下其參數
Parameters
setting
If not set, the function will only return the current setting.
這個函數接受一個參數,來決定是否啟用ignore_user_abort的功能。
再看其返回值:
Return Values
Returns the previous setting, as a boolean.
這里說返回前一次的設置,並且是bool值得,經過我的測試,這個說法是不對的,返回的明明是int型的,不相信的話大家可以寫一個php文件來測試下。
說了這么多了,到底該如何用php的這個函數實現計劃任務呢?還跌藉助另外一個函數,這個函數是set_time_limit,通過set_time_limit0)可以設置程序的執行時間為無限制,php默認的執行時間是30秒,通過set_time_limit(0)可以讓程序無限制的執行下去。在程序執行之前加上ignore_user_abort(1)和set_time_limit(0)即可以了,最終程序該如何寫呢?給大家一個例子。
QUOTE:
ignore_user_abort(); // run script in background
set_time_limit(0); // run script forever
$interval=60*15; // do every 15 minutes...
do{
// add the script that has to be ran every 15 minutes here
// ...
sleep($interval); // wait 15 minutes
}while(true);
?>
❹ linux怎麼搭建php開發環境
一、安裝Apache2.2.22
1、到官網下載 http://httpd.apache.org/download.cgi
2、解壓
tar -zxvf httpd-2.2.22.tar.gz
3、建立目標文件夾(注意以下所有操作都時在root用戶下執行的)
mkdir /usr/local/apache2
也就是說等下安裝的apache2要安裝到這個文件夾裡面
4、配置
回到原來解壓之後產生的文件夾
./configure --prefix=/usr/local/apache2 --enable-mole=shared
要加上後面的參數,否則無法使用php,-enable-mole=shared表示Apache可以動態的載入模塊
這一步,出現了很多問題:
第一個錯誤為:
checking for APR... no
configure: error: APR not found. Please read the documentation.
解決方法:
download the latest versions of both APR and APR-Util from Apache APR, unpack them into ./srclib/apr and ./srclib/apr-util (be sure the domain names do not have version numbers; for example, the APR distribution must be under ./srclib/apr/)
then do
./configure --with-included-apr
原文章地址:http://stackoverflow.com/questions/9436860/apache-httpd-setup-and-installatio
另外一種解決方法為:
分別安裝APR和APR-util,安裝方法為:首先下載這兩個文件,然後解壓,進入解壓後目錄,然後把APR和APR-util分別安裝到/usr/local/文件夾的apr和apr-util文件夾下。APR的具體安裝方法為:
[root@localhost 52lamp]# tar -zxvf apr-1.4.2.tar.gz //unzip -o apr-1.4.2.zip
[root@localhost 52lamp]# cd apr-1.4.2
[root@localhost apr-1.4.2]# ./configure --prefix=/usr/local/apr
[root@localhost apr-1.4.2]# make
[root@localhost apr-1.4.2]# make install
安裝Apr-util 在./confiure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
其他步驟類似。
第二個錯誤為:no acceptable C compiler found in $Path
直接運行 yum install gcc,安裝Gcc即可
第三個問題為:pcre-config for libpcre not found
解決方法就是 下載prce安裝包,和APR類似,安裝到/usr/local/pcre文件夾下面即可。PS:fedora下安裝c++編譯器g++的命令為:yum install gcc-c++ 。
5、編譯
make
6、安裝
make install
7、啟動,重啟和停止 ,先切換到安裝完成後的目錄/usr/local/apache2/bin
./apachectl -k start
./apachectl -k restart
./apachectl -k stop
8、配置文件(滿足最基本的配置)
編輯 /usr/local/apache2/conf/httpd.conf 文件
找到:
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
在後面添加:
AddType application/x-httpd-php .php(使Apcche支持PHP)
AddType application/x-httpd-php-source .php5
找到:
<IfMole dir_mole>
DirectoryIndex index.html
</IfMole>
添加:
<IfMole dir_mole>
DirectoryIndex index.html index.php
</IfMole>
找到:
#ServerName www.example.com:80
修改為:
ServerName 127.0.0.1:80或者ServerName localhost:80
記得要去掉前面的「#」
9、測試
在瀏覽器里輸入http://127.0.0.1
如果出現It Works!說明成功。這是我的測試結果:O(∩_∩)O哈哈~
10、修改默認的Web站點目錄
默認的目錄為 "/usr/local/apache2/htdocs",修改apache的配置文件httpd.conf,比如在新建一個 /home/gyw/WebSite的目錄作為apache的站點目錄
找到DocumentRoot這一行修改為:DocumentRoot "/home/gyw/WebSite"
找到 <Directory> 這一行修改為:<Directory "/home/gyw/WebSite">
測試:修改到文件夾出現錯誤:
「You don't have permission to access /index.html on this server.」
解決方法:
更改文件許可權;chmod 755 index.html
打開apache配置文件httpd.conf,找到這么一段:
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
deny from all
Satisfy all
</Directory>
測試結果如下:
二、安裝PHP
1、 下載
http://www.php.net/downloads.php
2、解壓
tar -zxvf php-5.3.16.tar.gz
3、建立目標文件夾
mkdir /usr/local/php
也就是說等下安裝的php要安裝到這個文件夾裡面
4、配置
回到原來解壓後的文件夾
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs
注意這里有一個-with-apxs2=/usr/local/apache/bin/apxs選項,其中apxs是在安裝Apache時產生的,apxs是一個為Apache HTTP伺服器編譯和安裝擴展模塊的工具,使之可以用由mod_so提供的LoadMole指令在運行時載入到Apache伺服器中。我的理解是通過這個工具把PHP模塊動態載入到Apache中
出現錯誤:configure: error: xml2-config not found. Please check your libxml2 installation.
運行yum install libxml2,然後再運行yum install libxml2-devel安裝完畢後,重新運行上面的./configure命令。
5、編譯
make
6、測試編譯
make test
7、安裝
make install
8、配置文件
cp /usr/local/src/php-5.3.16/php.ini-development /usr/local/php/lib/php.ini
把原來位於源代碼裡面的php.ini-development拷貝到/usr/local/php/lib/php.ini下,並且重命名為php.ini
9.重啟apache
10、測試
在apache的htdocs下建立一個php文件test.php,裡面的內容如下:
<?php
phpinfo();
?>
然後在瀏覽器里輸入http://127.0.0.1/test.php
如果出現php的相關配置,成功,如果什麼都沒有輸入,說明失敗,重新以上步驟或者查找原因
如果決定在安裝後改變配置選項,只需重復最後的三步configure, make, 以及 make install,然後需要重新啟動 Apache 使新模塊生效。Apache不需要重新編譯。
測試結果如下圖:
三、安裝MySql
1、下載
到官網下載mysql-5.1.65.tar.gz(注意是源碼包)
2、解壓
tar -zxvf mysql-5.1.65.tar.gz
3、建立目標文件夾
mkdir /usr/local/mysql
也就是說等下安裝的mysql要安裝到這個文件夾裡面
4、配置
./configure --prefix=/usr/local/mysql/
在./configure時出現錯誤:error: No curses/termcap library found
下載安裝相應軟體包
yum list|grep ncurses
yum -y install ncurses-devel
yum install ncurses-devel
5、編譯
make
6、安裝
make install
7、啟動
MySQL服務並不會自動啟動,還需要先初始化MySQL資料庫,操作如下:
cd /usr/local/mysql/bin
sudo ./mysql_install_db --user=root
注意,這里最後的root是指可以操作資料庫的用戶,可以是當前用戶,也可以新建用戶,與linux上的root用戶是兩回事,可以自己取一個名字
./mysqld_safe --user=root & 這條命令負責啟動mysql服務的守護進程,此外最後的&時必須的,因為希望守護進程在後台運行
這里的root就是剛才的那個
8、為根用戶創建密碼
./mysqladmin -u root password 『123456』
如果root已經設置過密碼,採用如下方法
./mysqladmin -u root password oldpass 『123456』
9、測試
mysql -u root -p
會提示輸入密碼,就用剛才設置的密碼
123456
如果出現mysql>,說明連接成功了,下面通過命令 創建一個資料庫、建一個表,增加一條記錄,為後面的測試准備
mysql> create database gywtest;
mysql> use gywtest;
mysql> create table student(id int(4) not null primary key auto_increment,stuname char(20));
mysql> insert into student(stuname) values('Tom');
注意每條命令後面有個分號,如果上面的都成功,後面就可以用這個測試。
四、將PHP與MySql結合起來
1、重新配置PHP,改變配置選項,只需重復PHP安裝時的最後的三步configure, make, 以及 make install,然後需要重新啟動 Apache 使新模塊生效,Apache不需要重新編譯。
2、配置
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-mysqli=/usr/local/mysql/bin/mysql_config 注意mysql_config 的路徑
3、編譯 make
4、安裝 make installe
5、測試 寫一個頁面test.php,放在apache的web目錄下,測試上面用命令創建的資料庫
<?php
$mysqli=new mysqli();
$mysqli->connect('localhost','root','123456','gywtest');
// 創建查詢
$sqlstr='select * from student';
//發送查詢給MySql
$result=$mysqli->query($sqlstr);
while($row=$result->fetch_object())
{
$name=$row->stuname;
echo $name;
}
?>
Fatal error: Class 'mysqli' not found in /home/lufangtao/Project/DB.php on line 3
解決方法:
/usr/local/php/bin/phpize 這里回車運行
出錯:
Cannot find config.m4.
Make sure that you run './phpize' in the top level source directory of the mole
解決方法:
PHP源碼包文件夾下的EXT文件夾就是放置著目前版本的可用擴展,CD進去看看都有哪些你需要的?應該看到mysqli文件夾了吧~~~
在當前目錄下執行phpize
[root@localhost mysqli]#/usr/local/php/bin/phpize
Configuring for:
PHP Api Version: 20090626
Zend Modeule Api No: 20090626
Zend Extension Api No: 220090626
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.
解決方法:
yum install autoconf再次運行上面的命令即可。
[root@localhost mysqli]#./configure –prefix=/opt/mysqli –with-php-config=/opt/php/bin/php-config –with-mysqli=/opt/mysql/bin/mysql_config
[root@localhost mysqli]#make
[root@localhost mysqli]#make install
安裝完成後會有提示擴展所在目錄路徑,如:
/opt/php/lib/php/extensions/no-debug-zts-20090626php
所需的mysqli.so便會在此目錄下,接下來修改/opt/php/etc/下的php.ini文件,加入mysqli擴展,即加入如下一行:
extension=/opt/php/lib/php/extensions/no-debug-zts-20090626/mysqli.so
這里還是回出現錯誤:
參考博客http://www.cnblogs.com/wangtao_20/archive/2011/03/07/1973621.html
解決不用擴展連接MySQL的方法。
最終還是沒有解決MySQLi連接的問題,但是可以使用MySQL資料庫了,下面是測試程序
<?php
$link=mysql_connect('localhost','root','123456');
if(!$link) echo "F!";
else echo "S!";
mysql_select_db("students") or die("Could not select database");
$query="SELECT * FROM student;";
$result=mysql_query($query) or die("Query failed");
print "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
print "\t<tr>\n";
foreach ($line as $col_value) {
print "\t\t<td>$col_value</td>\n";
}
print "\t</tr>\n"; }
print "</table>\n";
/* 釋放資源 */
mysql_free_result($result);
mysql_close();
?>
~
❺ PHP調動linux底層命令問題 我想用exec代碼得到網路借口IP 掩碼
php許多底層指令在網路服務端會被屏蔽,如果需要使用可先咨詢一下網站服務提供商。 追問: 忘了說明了, win7 系統 虛擬機搭建ubuntu 伺服器搭建在ubuntu下的 我應該沒有禁用任何任何網路服務端 回答: 注意執行文件的路徑 補充: exec (PHP 3, PHP 4 ) exec -- Execute an external program Descriptionstring exec ( string command [, array output [, int return_var]]) exec() executes the given command, however it does not output anything. It simply returns the last line from the result of the command. If you need to execute a command and have all the data from the command passed directly back without any interference, use the passthru() function. If the output argument is present, then the specified array will be filled with every line of output from the command. Line endings, such as \n, are not included in this array. Note that if the array already contains some elements, exec() will append to the end of the array. If you do not want the function to append elements, call unset() on the array before passing it to exec() . If the return_var argument is present along with the output argument, then the return status of the executed command will be written to this variable. 例子1. An exec() example <?php // outputs the username that owns the running php/httpd process // (on a system with the "whoami" executable in the path) echo exec('whoami'); ?> 警告 If you are going to allow data coming from user input to be passed to this function, then you should be using escapeshellarg() or escapeshellcmd() to make sure that users cannot trick the system into executing arbitrary commands. 注: If you start a program using this function and want to leave it running in the background, you have to make sure that the output of that program is redirected to a file or some other output stream or else PHP will hang until the execution of the program ends. 注: When safe mode is enabled, you can only execute executables within the safe_mode_exec_dir. For practical reasons it is currently not allowed to have .. components in the path to the executable. 警告 With safe mode enabled, all words following the initial command string are treated as a single argument. Thus, echo y | echo x becomes echo "y | echo x". See also system() , passthru() , popen() , escapeshellcmd() , and the backtick operator. 追問: EXEC我已經看過無數次了 在手冊上 你說的文件路徑是指什麼? 我想知道 這個命令之所以什麼都沒有返回是不是 許可權問題? 追問: 謝謝 最後絕對路徑解決了問題 /sbin/ifconfig 謝啦
❻ linux php.5.6 http 怎麼連接mysql
第一:linux php.5.6 http 怎麼連接mysql所需要的工具:
64位的Linux Mint操作系統:linuxmint-17.1-cinnamon-64bit。
第二:linux php.5.6 http 怎麼連接mysql具體操作方法:
1、Apache+PHP+MySQL的安裝。
Apache+PHP 的安裝。
2、主要介紹一下,PHP如何連接MySQL。
首先需要下載安裝 php5-mysql這個模塊。
Ctrl+Alt+T,直接打開終端。
3、輸入 sudo apt-get install php5-mysql ,然後輸入當前用戶的密碼後,開始下載並安裝該模塊。
4、安裝完畢後,需要重啟一下Apache服務。
在終端輸入 sudo /etc/init.d/apache2 restart ,回車後開始重啟Apache服務。
5、在 /var/www/html 目錄下,新建一個 mysql.php 文件,並輸入如下的內容:
<?php
header("Content-type:text/html;charset=utf-8");
echo '開始mysql資料庫連接.<br>';
$con = mysql_connect("localhost","root","root");
if($con){
echo '連接mysql資料庫成功.<br>';
}else{
die('連接mysql資料庫失敗:' . mysql_error());
}
mysql_close($con);
echo '關閉mysql資料庫連接.';
?>
6、打開瀏覽器,輸入 http://localhost/mysql.php , 顯示下圖所示則表示連接成功了。
❼ 如何搭linux測試環境+php
您好,這樣的:
Apache 安裝
1、下載 httpd-2.2.11.tar.gz
2、解壓
tar zxvf httpd-2.2.11.tar.gz
在執行tar指令的路徑下,會產生一個httpd-2.2.11目錄
3、查看一下編譯的配置信息
切換到解壓之後的httpd-2.2.11目錄
./configure --help
通過本步驟可以了解有那些可以安裝的模塊,以及安裝配置信息需要設置
進一步查看手冊,也可以了解相關信息
4、進行編譯配置
$ ./configure --prefix=/usr/local/apache2 \ 指定安裝目錄
--enable-so \ 允許使用外部so模塊
--with-mpm=prefork url請求跳轉策略
5、編譯:
$ make
6、安裝:(使用sudo是因為要安裝的路徑/usr/local/apache2不屬於個人路徑)
$ sudo make install
《安裝完畢》
7、測試
修改httpd.conf。
將 #ServerName www.example.com:80 修改為 ServerName 127.0.0.1:80(localhost:80)
啟動 sudo ./apachectl -k start
停止 sudo ./apachectl -k stop
重新起動 sudo ./apachectl -k restart (該命令有時無效,用stop+start代替)
****************************************
PHP安裝
1、下載php-5.2.8.tar.gz
2、解壓tar zxvf php-5.2.8.tar.gz
3、查看一下編譯的配置信息
切換到解壓之後的httpd-2.2.11目錄
./configure --help
通過本步驟可以了解有那些可以安裝的模塊,以及安裝配置信息需要設置
進一步查看手冊,也可以了解相關信息
4、編譯配置
./configure --prefix=/home/guandl/webenv/php528 \
--enable-mbstring \
--with-apxs2=/usr/local/apache2/bin/apxs
5 編譯
make
6、安裝
sudo make install
《安裝完畢》
7、復制php.ini
因為一般安裝後的php目錄$php/lib下沒有php的配置文件,需要把解壓目錄下的php.ini-recommended復制到php的lib目錄
sudo cp php.ini-recommended /home/guandl/webenv/php528/lib/php.ini
8、修改apache 的配置文件 httpd.conf
增加一下內容
LoadMole php5_mole moles/libphp5.so 安裝php時候已經自動生成
AddType application/x-httpd-php .php
9、測試
編寫一個php文件,如any.php
phpinfo();
?>
放到apache的htdocs目錄下
重新啟動apache。
❽ Linux下能看的php手冊哪裡能下
http://www.php.net/download-docs.php
有中文版的