php环境安装(apache2安装)
1、安装Apache,安装命令:sudo apt-get install apache2
2、环境配置:
1)配置文件:路径为/etc/apache2,配置文件是apache2.conf,而没有http.conf。
2)默认网站根目录:/var/www/html,使用浏览器访问http://localhost 即可打开;
3)修改网站根目录:
A、“sudo vim /etc/apache2/apache2.conf"-->找到""的位置-->更改"/var/www/"为新的根目录“/home/www”即可
B、"sudo vi/etc/apache2/sites-available/000-default.conf"-->找到"DocumentRoot /var/www/html"的位置-->更改"/var/www/html"为新的根目录“/home/www”即可。
4)重启Apache服务器: sudo /etc/init.d/apache2 restart
php配置
1、更新源列表,否则安装php会失败:
命令行输入: vim /etc/apt/source.list
在最前面添加以下内容:
deb http://mirrors.aliyun.com/ubuntu/ precise main restricteduniverse multiverse
deb http://mirrors.aliyun.com/ubuntu/ precise-security mainrestricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ precise-updates mainrestricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ precise-proposed mainrestricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ precise-backports mainrestricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ precise mainrestricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ precise-securitymain restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ precise-updatesmain restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ precise-proposedmain restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ precise-backportsmain restricted universe multiverse
apt-get update //更新一下列表
2、安装PHP,安装命令:sudoapt-get install php5
3、让Apache支持php,安装命令:sudo apt-get install libapache2-mod-php5
4、安装php5-gd模块,安装命令:sudoapt-get install php5-gd
5、让PHP支持curl
1)首先查看php5-curl是否已安装:dpkg -l | grep 'php5-curl'
2)如果没有安装,则:apt-get install php5-curl
3)确保 extension_dir存在,并且包含curl.so,
查找extension_dir:php -i | grep extension_dir
4)确保 /etc/php5/mods-available/curl.ini存在,文件内容如下:
; configuration for php CURL module
; priority=20
extension=curl.so
3。 mysql安装
sudo apt-get install mysql-client-5.5
sudo apt-get install mysql-server-5.5
sudo apt-get install php5-mysql (将apache2 与 mysql联系起来)
/etc/init.d/mysql start 启动mysql服务
/etc/init.d/mysql stop 关闭mysql服务
/etc/init.d/mysql restart 重启mysql服务