想学习使用ubuntu,准备搭建一个php运行环境,操作了很久没有入门,最后在查询到两篇文章解决了我的问题:
在此感谢提供文章的大佬,
文章地址:https://blog.csdn.net/sunrise_2013/article/details/45922003;
https://blog.csdn.net/coslay/article/details/22669553;
一。安装php
1、更新源列表,否则安装php会失败:
命令行输入: vim /etc/apt/source.list
在最前面添加以下内容:
deb http://mirrors.aliyun.com/ubuntu/ precise main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ precise-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ precise-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ precise-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ precise-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ precise main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ precise-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ precise-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ precise-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ precise-backports main 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
二。安装apache
1、安装Apache,安装命令:sudo apt-get install apache2
2、环境配置:
1)配置文件:路径为/etc/apache2,配置文件是apache2.conf,而没有http.conf。
2)默认网站根目录:/var/www/html,使用浏览器访问http://localhost 即可打开;
若出现“It works!”那就说明安装成功了。
安装PHP,并让Apache支持PHP
sudo apt-get install php5 libapache2-mod-php5
安装完成后重启Apache服务器
sudo /etc/init.d/apache2 restart
然后进入Apache的www文件夹下(默认在/var里面),创建phpinfo.php文件
cd /var/www
ls
vi phpinfo.php
然后在phpinfo.php文件里写入
<?php
phpinfo();
?>
但我们写完后很可能无法保存,因为我们这时对www目录下的文件没有写的权限,因此我们首先对www文件夹下的所有文件授权,然后我们再写入代码。
chmod 777 /var/www/
最后在浏览器里输入http://localhost/phpinfo.php,就可以看到php的信息了
三。安装mysql
1、安装Mysql,安装命令:sudoapt-get install mysql-server,安装过程中设置密码
下图为提示输入数据库密码,然后回车,之后还有提示,再重复输入一次,再回车
最后安装完后进数据库测试一下是否安装成功,看到欢迎信息就ok了
mysql -uroot -p
***