


Create a deploy user on the target machine (take deploy user as an example)
Add a user and create a password
/usr/sbin/groupadd deploy /usr/sbin/useradd -g deploy -s /bin/bash deploy passwd deploy
Enter the password twice and press Enter to confirm
Additional: Switch user command su - deploy
Use new user without password and use sudo command
Add the user deploy just now to sudoers for password-free operation Use the sudo command with password
visudo //修改/etc/sudoers的内容,或vim or vi 命令 vim /etc/sudoers ## Allow root to run any commands anywhere # 设置xxxx组下面的用户使用sudo不需要输入密码 root ALL=(ALL) ALL deploy ALL=(ALL) ALL # 新添加这一行 %deploy ALL=(ALL) NOPASSWD: ALL # 新添加这一行
Now you can use sudo here is command in exec to execute the command normally without entering the password
The target machine modifies the php-fpm process to run as the deploy user
Take centos7.5 as an example
vim /etc/php-fpm.d/www.conf # 修改用户和用户组为deploy user = deploy group = deploy # 如果存在listen用户和用户组,同样修改,不存在可以忽略 ;listen.owner = deploy ;listen.group = deploy
Restart the php-fpm service
service php-fpm restart
The target machine modifies nginx as a process to run as the deploy user
Take centos7.5 as an example
vim /etc/nginx/nginx.conf
Add a new header (modify if it exists)
user deploy;
Restart nginx
nginx -t service nginx restart
At this point, you can use the php script to execute the command and pull the git code. At the same time, pay attention to the user of the PHP script and you can repair the file user ownership:
# 批量修改 filedir 目录所属用户为deploy sudo chown -R deploy:deploy filedir
PHP pull git Code update example
$output = shell_exec('cd ~/www/test && git pull origin master'); var_dump(output);
For more PHP related knowledge, please visit PHP tutorial!
The above is the detailed content of php+nginx implements automated deployment script (simple version). For more information, please follow other related articles on the PHP Chinese website!

Load balancing affects session management, but can be resolved with session replication, session stickiness, and centralized session storage. 1. Session Replication Copy session data between servers. 2. Session stickiness directs user requests to the same server. 3. Centralized session storage uses independent servers such as Redis to store session data to ensure data sharing.

Sessionlockingisatechniqueusedtoensureauser'ssessionremainsexclusivetooneuseratatime.Itiscrucialforpreventingdatacorruptionandsecuritybreachesinmulti-userapplications.Sessionlockingisimplementedusingserver-sidelockingmechanisms,suchasReentrantLockinJ

Alternatives to PHP sessions include Cookies, Token-based Authentication, Database-based Sessions, and Redis/Memcached. 1.Cookies manage sessions by storing data on the client, which is simple but low in security. 2.Token-based Authentication uses tokens to verify users, which is highly secure but requires additional logic. 3.Database-basedSessions stores data in the database, which has good scalability but may affect performance. 4. Redis/Memcached uses distributed cache to improve performance and scalability, but requires additional matching

Sessionhijacking refers to an attacker impersonating a user by obtaining the user's sessionID. Prevention methods include: 1) encrypting communication using HTTPS; 2) verifying the source of the sessionID; 3) using a secure sessionID generation algorithm; 4) regularly updating the sessionID.

The article discusses PHP, detailing its full form, main uses in web development, comparison with Python and Java, and its ease of learning for beginners.

PHP handles form data using $\_POST and $\_GET superglobals, with security ensured through validation, sanitization, and secure database interactions.

The article compares PHP and ASP.NET, focusing on their suitability for large-scale web applications, performance differences, and security features. Both are viable for large projects, but PHP is open-source and platform-independent, while ASP.NET,

PHP's case sensitivity varies: functions are insensitive, while variables and classes are sensitive. Best practices include consistent naming and using case-insensitive functions for comparisons.


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

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.

WebStorm Mac version
Useful JavaScript development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Dreamweaver Mac version
Visual web development tools

Atom editor mac version download
The most popular open source editor
