linux下安裝php環境
最簡單的方法就是給伺服器裝一個寶塔,在寶塔上安裝自己需要的環境
B. linuxphp網站怎麼安裝
配置php服務
[[email protected]]cd/usr/local/src
[root@linuxprobesrc]tarzxvfyasm-1.2.0.tar.gz
[root@linuxprobesrc]cdyasm-1.2.0
[[email protected]]./configure
[[email protected]]make
[[email protected]]makeinstall
安裝libmcrypt加密演算法擴展庫(解爛銀圓壓與編譯過程已省略):
[[email protected]]cd/usr/local/src
[root@linuxprobesrc]tarzxvflibmcrypt-2.5.8.tar.gz
[root@linuxprobesrc]cdlibmcrypt-2.5.8
[[email protected]]./configure
[[email protected]]make
[[email protected]]makeinstall
安裝libvpx視頻編碼器(解壓與編譯過程搏旦已省略):
[[email protected]]cd/usr/local/src
[root@linuxprobesrc]tarxjvflibvpx-v1.3.0.tar.bz2
[root@linuxprobesrc]cdlibvpx-v1.3.0
[[email protected]]./configure--prefix=/usr/local/libvpx--enable-shared--enable-vp9
[[email protected]]make
[[email protected]]makeinstall
安裝Tiff標簽圖像文件格式(解壓與編譯過程已省略):
[[email protected]]cd/usr/local/src
[root@linuxprobesrc]tarzxvftiff-4.0.3.tar.gz
[root@linuxprobesrc]cdtiff-4.0.3
[[email protected]]./configure--prefix=/usr/local/tiff--enable-shared
[[email protected]]make
[[email protected]]makeinstall
安裝libpng圖片(png格式)函數庫(解壓與編譯過程已省略):
[[email protected]]cd/usr/local/src
[root@linuxprobesrc]tarzxvflibpng-1.6.12.tar.gz
[root@linuxprobesrc]cdlibpng-1.6.12
[[email protected]]./configure--prefix=/usr/local/libpng--enable-shared
[[email protected]]make
[[email protected]]makeinstall
安裝freetype字體引擎(解壓與編譯過程已省略):
[[email protected]]cd/usr/local/src
[root@linuxprobesrc]tarzxvffreetype-2.5.3.tar.gz
[root@linuxprobesrc]cdfreetype-2.5.3
[[email protected]]./configure--prefix=/usr/local/freetype--enable-shared
[[email protected]]make
[[email protected]]makeinstall
安裝jpeg圖片(jpeg格式)函數庫(解壓與編譯過程已省略):
[[email protected]]cd/usr/local/src
[root@linuxprobesrc]tarzxvfjpegsrc.v9a.tar.gz
[root@linuxprobesrc]cdjpeg-9a
[root@linuxprobejpeg-9a]./configure--prefix=/usr/local/jpeg--enable-shared
[root@linuxprobejpeg-9a]make
[root@linuxprobejpeg-9a]makeinstall
安裝libgd圖像處理程序(解壓與編譯過程已省略):
[root@linuxprobejpeg-9a]cd/usr/local/src
[root@linuxprobesrc]tarzxvflibgd-2.1.0.tar.gz
[root@linuxprobesrc]cdlibgd-2.1.0
[[email protected]]./configure--prefix=/usr/local/libgd--enable-shared--with-jpeg=/usr/local/jpeg--with-png=/usr/local/libpng--with-freetype=/usr/local/freetype--with-fontconfig=/usr/local/freetype--with-xpm=/usr/--with-tiff=/usr/local/tiff--with-vpx=/usr/local/libvpx
[[email protected]]make
[[email protected]]makeinstall
安裝t1lib圖片生成函數庫(解壓與編譯過程已省略):
[[email protected]]cd/usr/local/src
[root@linuxprobesrc]tarzxvft1lib-5.1.2.tar.gz
[root@linuxprobesrc]cdt1lib-5.1.2
[[email protected]]./configure--prefix=/usr/local/t1lib--enable-shared
[[email protected]]make
[[email protected]]makeinstall
將函數庫文件放至合適的位置:
[[email protected]]cd/usr/local/src
[root@linuxprobesrc]ln-s/usr/lib64/libltdl.so/usr/lib/libltdl.so
[root@linuxprobesrc]cp-frp/usr/lib64/libXpm.so*/usr/lib/
安裝php服務程序(命令比較長,請一定要復制完整!!!):
[root@linuxprobesrc]tar-zvxfphp-5.5.14.tar.gz
[root@linuxprobesrc]cdphp-5.5.14
[[email protected]]exportLD_LIBRARY_PATH=/usr/local/libgd/lib
[[email protected]]./configure--prefix=/usr/local/php--with-config-file-path=/usr/local/php/etc--with-mysql=/usr/local/mysql--with-mysqli=/usr/local/mysql/bin/mysql_config--with-mysql-sock=/tmp/mysql.sock--with-pdo-mysql=/usr/local/mysql--with-gd--with-png-dir=/usr/local/libpng--with-jpeg-dir=/usr/local/jpeg--with-freetype-dir=/usr/local/freetype--with-xpm-dir=/usr/--with-vpx-dir=/usr/local/libvpx/--with-zlib-dir=/usr/local/zlib--with-t1lib=/usr/local/t1lib--with-iconv--enable-libxml--enable-xml--enable-bcmath--enable-shmop--enable-sysvsem--enable-inline-optimization--enable-opcache--enable-mbregex--enable-fpm--enable-mbstring--enable-ftp--enable-gd-native-ttf--with-openssl--enable-pcntl--enable-sockets--with-xmlrpc--enable-zip--enable-soap--without-pear--with-gettext--enable-session--with-mcrypt--with-curl--enable-ctype
[[email protected]]make
[[email protected]]makeinstall
復制php服務程序的配置文件到安裝目錄:
[[email protected]]cpphp.ini-proction/usr/local/php/etc/php.ini
刪除默認的php配置文件:
[[email protected]]rm-rf/etc/php.ini
創建php配置文件的軟連接到/etc/目錄中:
[[email protected]]cp/usr/local/php/etc/php-fpm.conf.default/usr/local/php/etc/php-fpm.conf
[[email protected]]ln-s/usr/local/php/etc/php-fpm.conf/etc/php-fpm.conf
[[email protected]]ln-s/usr/local/php/etc/php.ini/etc/php.ini
編輯php服務程序的配置文件:
[[email protected]]vim/usr/local/php/etc/php-fpm.conf
//將第25行參數前面的分號去掉。
pid=run/php-fpm.pid
//修改第148和149行,將user與group修改為www。
user=www
group=www
添加php-fpm服務程序到開機啟動項:
[[email protected]]cpsapi/fpm/init.d.php-fpm/etc/rc.d/init.d/php-fpm
[[email protected]]chmod+x/etc/rc.d/init.d/php-fpm
[[email protected]]chkconfigphp-fpmon
為了保障網站的安全性,禁用掉不安全的功能:
[[email protected]]vim/usr/local/php/etc/php.ini
//修改第305行的disable_functions參數,追加參數為:
disable_functions=passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname
配置nginx服務程序支持php:
[[email protected]]vim/usr/local/nginx/conf/nginx.conf
//將第2行前面的號去掉並修改為userwwwwww;
//將第45行參數修改為indexindex.htmlindex.htmindex.php;
//將第65-71行前面的號去掉,修改為:
location~.php${
roothtml;
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.php;
fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;
includefastcgi_params;
}
重啟nginx與php-fpm服務程序:
[[email protected]]systemctlrestartnginx
[[email protected]]systemctlrestartphp-fpm
C. 怎麼在linux伺服器上配置php環境
建議多使用網路搜索,網上這樣的帖子特別多。
Linux的分支比較大,不過常使用的也就Centos和Ubuntu。下面我貼出來在Centos上面搭建php環境的方法,命令有所不同,不過差異不大。
安裝apache:
yum install httpd httpd-devel
啟動apache:
/etc/init.d/httpd start
此時輸入伺服器的IP地址,應該看到apache的服務頁面,埠不用輸,apache默認就是使用80埠
安裝mysql:
yum install mysql mysql-server
啟動mysql:
/etc/init.d/mysqld start
安裝php
yum install php php-devel
重啟apache使php生效
/etc/init.d/httpd restart
此時可以在目錄:/var/www/html/下建立一個PHP文件
代碼:
<?php phpinfo(); ?>
然後訪問這個文件,就能看到PHP的一些信息,php.ini配置文件的路徑可以在這個頁面上看到
安裝php的擴展
yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc
安裝完擴展之後需要再次重啟apache
/etc/init.d/httpd restart
測試mysql是否鏈接成功的php代碼
<?php
$con = mysql_connect("10.0.@.@@","@@","@@");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("mydb", $con);
$result = mysql_query("SELECT * FROM sys_user");
while($row = mysql_fetch_array($result))
{
echo $row['UserName'] . " " . $row['PassWord'] . " " . $row['id'];
echo "<br />";
}
mysql_close($con);
?>
可以把上面的代碼傳入目錄/var/www/html/
就可以看到執行情況
D. linux環境安裝PHP環境的步驟和前期准備的注意事項有哪些
一.架構。確認你安裝 的架構是什麼 lamp ,還是 lnmp。首先需要能搭建出環境
1。兩者都要安裝 php ,其中 php 安裝的過程有很多
可以參考一下:php 源碼安裝
這個安裝是 php5的,如果安裝的 是 php7,編譯會有一點不同:
安裝 php -
2。都需要安裝 mysql
mysql 源碼安裝
3。如果需要安裝apache:
apache 安裝
apache 都其他配置,請在本頁面搜索:apache -
如果需要安裝 nginx:
nginx 訪問 php -
二.依賴模塊編譯。這種安裝環境主要看你程序當中用到了那些 依賴模塊,編譯的時候需要注意
包括 nginx /apache ,php
三.配置。上面已經有相關配置介紹,需要自己去熟悉相關都配置是什麼意思,需要哪些配置。
四.此處遷移還涉及到資料庫到遷移,可以參考一下相關命令
E. linux涓嬪畨瑁卲hp緙栬瘧鍙傛暟
鍦↙inux涓嬪畨瑁匬HP錛屾簮浠g爜鏂瑰紡瀹夎咃紝鎬婚渶瑕侀厤緗寰堝氬弬鏁般傝繖閲屽垪鍑哄父鐢ㄩ厤緗鍙傛暟錛屽苟璇︾粏鐢ㄤ腑鏂囪В閲婅存槑浜嗐傜粰澶у朵竴浜涘弬鑰./configure
--prefix=/usr/local/php php 瀹夎呯洰褰
--with-apxs2=/usr/local/apache/bin/apxs
--with-config-file-path=/usr/local/php/etc 鎸囧畾php.ini浣嶇疆
--with-MySQL=/usr/local/mysql mysql瀹夎呯洰褰曪紝瀵筸ysql鐨勬敮鎸
--with-mysqli=/usr/local/mysql/bin/mysql_config mysqli鏂囦歡鐩褰,浼樺寲鏀鎸
--enable-safe-mode 鎵撳紑瀹夊叏妯″紡
--enable-ftp 鎵撳紑ftp鐨勬敮鎸
--enable-zip 鎵撳紑瀵箊ip鐨勬敮鎸
--with-bz2 鎵撳紑瀵筨z2鏂囦歡鐨勬敮鎸
--with-jpeg-dir 鎵撳紑瀵筳peg鍥劇墖鐨勬敮鎸
--with-png-dir 鎵撳紑瀵筽ng鍥劇墖鐨勬敮鎸
--with-freetype-dir 鎵撳紑瀵筬reetype瀛椾綋搴撶殑鏀鎸
--without-iconv 鍏抽棴iconv鍑芥暟錛岀嶅瓧絎﹂泦闂寸殑杞鎹
--with-libXML-dir 鎵撳紑libxml2搴撶殑鏀鎸
--with-xmlrpc 鎵撳紑xml-rpc鐨刢璇璦
--with-zlib-dir 鎵撳紑zlib搴撶殑鏀鎸
--with-gd 鎵撳紑gd搴撶殑鏀鎸
--enable-gd-native-ttf 鏀鎸乀rueType瀛楃︿覆鍑芥暟搴
--with-curl 鎵撳紑curl嫻忚堝伐鍏風殑鏀鎸
--with-curlwrappers 榪愮敤curl宸ュ叿鎵撳紑url嫻
--with-ttf 鎵撳紑freetype1.*鐨勬敮鎸侊紝鍙浠ヤ笉鍔犱簡
--with-xsl 鎵撳紑XSLT 鏂囦歡鏀鎸侊紝鎵╁睍浜唋ibxml2搴 錛岄渶瑕乴ibxslt杞浠
--with-gettext 鎵撳紑gnu 鐨刧ettext 鏀鎸侊紝緙栫爜搴撶敤鍒
--with-pear 鎵撳紑pear鍛戒護鐨勬敮鎸侊紝php鎵╁睍鐢ㄧ殑
--enable-calendar 鎵撳紑鏃ュ巻鎵╁睍鍔熻兘
--enable-mbstring 澶氬瓧鑺傦紝瀛楃︿覆鐨勬敮鎸
--enable-bcmath 鎵撳紑鍥劇墖澶у皬璋冩暣,鐢ㄥ埌zabbix鐩戞帶鐨勬椂鍊欑敤鍒頒簡榪欎釜妯″潡
--enable-sockets 鎵撳紑 sockets 鏀鎸
--enable-exif 鍥劇墖鐨勫厓鏁版嵁鏀鎸
--enable-magic-quotes 欖旀湳寮曠敤鐨勬敮鎸
--disable-rpath 鍏抽棴棰濆栫殑榪愯屽簱鏂囦歡
--disable-debug 鍏抽棴璋冭瘯妯″紡
--with-mime-magic=/usr/share/file/magic.mime 欖旀湳澶存枃浠朵綅緗
CGI鏂瑰紡瀹夎呮墠鐢ㄧ殑鍙傛暟
--enable-fpm 鎵撲笂php-fpm 琛ヤ竵鍚庢墠鏈夎繖涓鍙傛暟錛宑gi鏂瑰紡瀹夎呯殑鍚鍔ㄧ▼搴
--enable-fastcgi 鏀鎸乫astcgi鏂瑰紡鍚鍔╬hp
--enable-force-cgi-redirect 鍚屼笂 ,甯鍔╅噷娌℃湁瑙i噴
--with-ncurses 鏀鎸乶curses 灞忓箷緇樺埗浠ュ強鍩轟簬鏂囨湰緇堢鐨勫浘褰浜掑姩鍔熻兘鐨勫姩鎬佸簱
--enable-pcntl freeTDS闇瑕佺敤鍒扮殑錛屽彲鑳芥槸閾炬帴mssql 鎵嶇敤鍒
mhash鍜宮crypt綆楁硶鐨勬墿灞
--with-mcrypt 綆楁硶
--with-mhash 綆楁硶
--with-gmp
--enable-inline-optimization
--with-openssl openssl鐨勬敮鎸侊紝鍔犲瘑浼犺緭鏃剁敤鍒扮殑
--enable-dbase
--with-pcre-dir=/usr/local/bin/pcre-config perl鐨勬e垯搴撴堝畨瑁呬綅緗
--disable-dmalloc
--with-gdbm dba鐨刧dbm鏀鎸
--enable-sigchild
--enable-sysvsem
--enable-sysvshm
--enable-zend-multibyte 鏀鎸亃end鐨勫氬瓧鑺
--enable-mbregex
--enable-wddx
--enable-shmop
--enable-soap