


Specific steps for installation and configuration of nginx+php+mysql based on ubuntu_PHP tutorial
1、更新
1
|
sudo apt-get update
|
2、安装nginx
1
|
sudo apt-get intsall nginx
|
Ubuntu安装之后的文件结构大致为:
* 所有的配置文件都在/etc/nginx下,并且每个虚拟主机已经安排在了/etc/nginx/sites-available下
*程序文件在/usr/sbin/nginx * 日志放在了/var/log/nginx中
*并已经在/etc/init.d/下创建了启动脚本nginx
* 默认的虚拟主机的目录设置在了/var/www/nginx-default
下面可以启动nginx来看看效果(请确保80端口没有其他服务在使用):
1
|
sudo /etc/init.d/nginx start
|
#或者简单的
1
|
service nginx start
|
然后打开浏览器,查看http://localhost/ 看看是否看到了”Welcome to nginx!” 如果看到了,说明安装成功.
当然,基本上,这块儿都不会出问题. 如果运行不成功,可以先
1
|
sudo killall apache2
|
杀掉apache进程
3、安装php
sudo apt-get install php5 php5-cgi php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-pspell php5-recode php5-snmp php5-tidy php5-xmlrpc php5-sqlite php5-xsl
4、安装spawn-fcgi
为什么要安装spawn-fcgi呢,它用来控制php-cgi进程,以防止进程崩溃或是单进程的效率太低.
网上很多人都说要使用spawn-fcgi必须得安装lighttpd,实际上不必要,可以直接安装spawn-fcgi
运行:
1
|
sudo apt-get install spawn-fcgi
|
5、配置
接下来就是最让人头疼的配置.
配置Nginx和spawn-fcgi配合运行
(1).在/etc/nginx/fastcgi_params 文件最后,加入一行,可以用
1
|
sudo vi /etc/nginx/fastcgi_params
|
加入此行:
1
|
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
(2).另外需要在PHP-CGI的配置文件(Ubuntu 上此配置文件位于/etc/php5/cgi/php.ini)中,找到cgi.fix_pathinfo选项,修改为:
1
|
cgi.fix_pathinfo=1;
|
这样php-cgi方能正常使用SCRIPT_FILENAME这个变量.
(3).打开/etc/nginx/sites-available/default文件在
1
2
3
|
server {
listen 80;
server_name localhost;
|
下面添加web根目录的绝对地址,这里是使用的是nginx的默认地址
1
|
root /var/www/nginx-default
|
即root和server_name同级这段即相当于apache的默认目录
如果没有这个的话,容易在执行php 文件的时候,会提示”No input file specified”.
我就曾在此绕了好大个圈子才发现问题.然后修改
1
2
3
4
5
6
|
#location ~ .php$ {
#fastcgi_pass 127.0.0.1:9000;
#fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
#includefastcgi_params;
#}
|
修改成
1
2
3
4
|
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/nginx-default$fastcgi_script_name;
|
include /etc/nginx/fastcgi_params; #包含fastcgi的参数文件地址
6、开始fast_cgi进程
1、sudo /usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid
7、设置开机启动fastcgi进程并启动
1
|
sudo vi /etc/rc.local
|
添加下一行
1
|
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid
|
如果打开php文件出现:No input file specified请检查php.ini的配置中
1
|
cgi.fix_pathinfo=1
|
1
|
doc_root=
|
还有,每个虚机要根据自己不同的虚机设置不同的目录,要保证这个路径正确.
检查/etc/nginx/sites-available下的配置文件中,server内包含 root 及地址 而非location内的root
启动
1
|
fast-cgisudo /usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid
|
The meaning of the parameters is as follows
* -f Specify the execution program location of the process that calls FastCGI,according to Specific settings for PHP installed on the system
* -a is bound to the address addr
* -p bind to portport
* -s bind to path of unix socketpath
* -C Specifies the number of processes generated by FastCGI, Defaults to 5 ( only for PHP)
* -PSpecifies the of the spawned process PIDFile path
* -u and -g FastCGIWhat identity to use(-u User -g User Group)Run, Ubuntu You can use www-data, and other configurations according to the situation , such as nobody, apache, etc. Now you can put a probe in the root directory of web or phpTested the file
8, installedmysql
|
sudo apt-get install mysql-server mysql-client |
in order to start .
1
|
sudo /etc/init.d/mysql start
|
1
sudo /etc/init.d/mysql start
1
|
mysql -uroot -p
|
:Run
1
|
mysql -uroot -p |
Entermysqlpassword
1 | show databases; |
, the installation of
http://www.bkjia.com/PHPjc/326928.html
PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.

In PHP, use the clone keyword to create a copy of the object and customize the cloning behavior through the \_\_clone magic method. 1. Use the clone keyword to make a shallow copy, cloning the object's properties but not the object's properties. 2. The \_\_clone method can deeply copy nested objects to avoid shallow copying problems. 3. Pay attention to avoid circular references and performance problems in cloning, and optimize cloning operations to improve efficiency.

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.

Key players in HTTP cache headers include Cache-Control, ETag, and Last-Modified. 1.Cache-Control is used to control caching policies. Example: Cache-Control:max-age=3600,public. 2. ETag verifies resource changes through unique identifiers, example: ETag: "686897696a7c876b7e". 3.Last-Modified indicates the resource's last modification time, example: Last-Modified:Wed,21Oct201507:28:00GMT.

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP is a server-side scripting language used for dynamic web development and server-side applications. 1.PHP is an interpreted language that does not require compilation and is suitable for rapid development. 2. PHP code is embedded in HTML, making it easy to develop web pages. 3. PHP processes server-side logic, generates HTML output, and supports user interaction and data processing. 4. PHP can interact with the database, process form submission, and execute server-side tasks.

PHP has shaped the network over the past few decades and will continue to play an important role in web development. 1) PHP originated in 1994 and has become the first choice for developers due to its ease of use and seamless integration with MySQL. 2) Its core functions include generating dynamic content and integrating with the database, allowing the website to be updated in real time and displayed in personalized manner. 3) The wide application and ecosystem of PHP have driven its long-term impact, but it also faces version updates and security challenges. 4) Performance improvements in recent years, such as the release of PHP7, enable it to compete with modern languages. 5) In the future, PHP needs to deal with new challenges such as containerization and microservices, but its flexibility and active community make it adaptable.

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function