第一步 安装mysql-server mysql-client
sudo apt-get update sudo apt-get install mysql-server mysql-client中间让你输入mysql-server的root的密码两次,两次都输入的同一个。安装完毕后使用以下命令测试一下是不是安装成功
mysql -u root -p
如果出现让你输入密码,就没有问题。没有问题的前提下,配置mysql-server可以试一下以下命令
sudo mysql_secure_installation看看就明白了。
第二步 安装nginx
sudo apt-get install nginx
http://localhost如果出现页面
Welcome to nginx! If you see this page, the nginx web server is successfully installed and working. Further configuration is required. For online documentation and support please refer to nginx.org. Commercial support is available at nginx.com. Thank you for using nginx.那么说明nginx安装成功了,这个地方没有什么问题。
第三步,安装php5-fpm
sudo apt-get install php5-fpmphp5-fpm几乎包括了你开发php5的一切,不用再管其它什么了。然后再安装一些常用的模块,毕竟你程序还要和其它进程通信什么的。
sudo apt-get install php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl
安装完毕后,查看php5运行进程的命令是:
ps -waux | grep php5
以下命令可以控制php5进程
sudo service php5-fpm stop sudo service php5-fpm start sudo service php5-fpm restart sudo service php5-fpm status
配置php5
vi /etc/php5/fpm/php.ini 找到:;cgi.fix_pathinfo=1 改为:cgi.fix_pathinfo=0
第四步 配置整个环境
配置nginx
cd ~ mkdir www chmod 755 www pwd我电脑上显示为:
/home/lihongwei/www我在本机上用户主目录下建了一个www文件夹。
cd /etc/nginx/sites-enabled/ sudo vim default 找到:root /usr/share/nginx/html; 改为:root /home/lihongwei/www;<span style="font-size: 15px;"><code></code></span> 找到:index index.html index.htm; 改为:index index.php index.html index.htm;
然后关键的部分来了,还是在文件default中,把
#location ~ \.php$ { # fastcgi_split_path_info ^(.+\.php)(/.+)$; # # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini # # # With php5-cgi alone: # fastcgi_pass 127.0.0.1:9000; # # With php5-fpm: # fastcgi_pass unix:/var/run/php5-fpm.sock; # fastcgi_index index.php; # include fastcgi_params; #}
location ~ \.php$ {#取消注释 try_files $uri =404; #增加 fastcgi_split_path_info ^(.+\.php)(/.+)$; #取消注释 # # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini # # # With php5-cgi alone: # fastcgi_pass 127.0.0.1:9000; # # With php5-fpm: fastcgi_pass unix:/var/run/php5-fpm.sock;#取消注释 fastcgi_index index.php;#取消注释 include fastcgi_params;#取消注释 }#取消注释
sudo service php5-fpm reload sudo service nginx reload
vim /home/lihongwei/www/index.php 内容: <?php echo phpinfo(); ?>