DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
VGSources
Blog

LAMP Application Ownership and Permissions Explained

A practical guide to LAMP ownership and permissions: separate deployment, web-service, and MySQL identities; make code read-only; grant narrow runtime writes; and troubleshoot PHP denials safely.
Length10 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use three separate roles: a deployment or login account owns your application code, Apache and PHP run as the operating system’s web-service account, and MySQL owns its database files. Give Apache/PHP read and directory-traverse access to code, then grant write access only to specific directories for uploads, caches, sessions, or generated files. On Debian-family systems that service account is commonly www-data; on Amazon Linux it is commonly apache. Verify the active service configuration instead of assuming either name.

Do not solve a PHP permission error with chmod -R 777. That mode lets every local user and any compromised process write throughout the tree. Least privilege, narrow writable paths, and clear ownership make a LAMP installation easier to audit and limit the damage from a compromised web process.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What ownership means in a LAMP stack

LAMP combines Linux, Apache HTTP Server, MySQL, and PHP. Linux evaluates every file operation using the identity of the process making the request. In a normal web request, PHP code executes inside an Apache worker, so the effective identity is Apache’s service account rather than the account you use to log in or deploy a release.

The deployment identity

A human administrator or an automated deployment account should own application source code and perform releases. That account can check out a new version, run migrations, set configuration, and roll back a release without giving the web server ownership of the entire project. Ownership gives accountability: a release can be tied to a specific user or deployment process instead of being silently changed by a running request.

#1 Best Overall
Sale
Gaoye Blue Light Blocking Glasses
  • BLUE LIGHT BLOCKING GLASSES: Our blue light glasses for women boast UV400 protection, blocking harmful blue rays from computer screens. With these bluelight glasses women, you can enjoy gaming, reading, or watching TV with no worries of eye strain.
  • EYE RELIEF: Our blue light glasses are engineered to reduce blurry vision or strain caused by prolonged screen time. These womens blue light glasses aid in better sleep by preventing blue light from disrupting your natural sleep cycle, helping you fall asleep faster and enjoy a more restful night's sleep, making them the perfect christmas present.
  • COMFORTABLE: Crafted from durable material, our trendy blue light glasses for woman or blue light glasses men ensure long-lasting comfort. The high-transmittance lenses accessories, gamer gifts for men, help keep your eyes relaxed. Perfect stocking stuffers, gifts for gamers men, christmas gifts for men, halloween costumes.
  • LIGHTWEIGHT: These clear blue light glasses feature a lightweight frame, meaning they’ll stay comfy for long-term wear. Perfect as blue blockers glasses for women or mens blue light glasses, these non-prescription fake glasses for men can be worn throughout the day. The blue light blocking glasses women feature polycarbonate HD lenses, which are anti-reflective and restore true color.
  • WORRY-FREE PURCHASE: If you experience any issues, our support team is ready to assist you quickly. These are the perfect costume glasses for cosplay dressing up.

The web-service identity

Apache and PHP should run under the distribution’s dedicated, unprivileged service account. Debian-family examples normally use www-data; Amazon Linux documentation commonly uses the apache group and account. These names are conventions, not universal constants. A custom unit, container, or hosting image may use another identity. The account generally needs to read PHP, HTML, CSS, JavaScript, and other assets and to traverse every parent directory leading to them. It should write only where the application must create runtime data.

The database identity

MySQL is a separate service. Its operating-system account, normally mysql, needs access to database files and selected runtime resources. Giving Apache ownership of a MySQL data directory mixes two trust boundaries and can expose or corrupt every database on the host.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How Linux permissions map to web requests

Each path has an owner, a group, and permissions for the owner, group, and everyone else. Linux checks the process identity against the owner first, then its supplementary groups, then the “other” class. A process does not gain access merely because a different account owns a parent directory.

Object Permission What it allows Typical LAMP implication
Regular file Read Read file contents Apache usually needs this for application code and assets
Regular file Write Change file contents Usually unnecessary for PHP, templates, CSS, or uploaded files
Regular file Execute Run the file as a program Not required for ordinary PHP source served through the interpreter
Directory Read List names in the directory Useful for directory listings or application scans, but not always required to open a known path
Directory Write Create, delete, or rename entries Required in upload, cache, session, and generated-output directories
Directory Execute Traverse the directory and access known entries Required on every parent directory in a path Apache must reach

The difference between file and directory write permission explains many confusing errors. To create /var/www/site/storage/log.txt, PHP needs write and execute on storage; write permission on an existing log.txt is irrelevant if the file does not yet exist. Deleting or renaming a file is also controlled by the containing directory, not by the file’s own write bit.

Rank #2
Windex Gaming Cleaning Wipes, Pre-Moistened Wipes to Instantly Clean all Gaming Gear and Electronics, Resealable Packaging for a Freshness Lock, 25 count (Pack of 1)
  • WINDEX GAMING WIPES: effortlessly clean all your gaming gear and gaming electronics in one easy step with our new Windex Gaming Wipes
  • AMMONIA FREE: our ammonia-free formula is safe to use on all of your favorite gaming equipment like consoles, headsets, controllers, screens, keyboards, and more
  • PRE-MOISTENED WIPES: each wipe instantly removes dust, dirt, and stubborn smudges and fingerprints leaving a streak-free shine
  • ANTI-STATIC: great for cleaning and wiping down your gaming gear and electronics leaving behind no visible residue
  • COMPACT RESEALABLE PACKAGE: store your pack of Windex Gaming Wipes anywhere in your home for whenever a quick and easy wipedown is needed

A practical directory layout

Treat code and runtime data as different classes of path. A typical project might look like this:

Path or category Owner and group Apache/PHP access Reason
Application source and templates Deployment account; a controlled deployment group Read and traverse only Releases are deployment-managed, not request-managed
Public document root Deployment account; web-service group Read and traverse; no general write Serves static assets without allowing code replacement
Uploads Deployment account or a dedicated data owner; web-service group Write only in this directory Accepts user-created files; validate names and content in the application too
Cache, sessions, queues, generated assets Deployment account and web-service group, or an ACL for both Write only in the specific runtime directory Allows normal operation without making the project writable
Secrets and private keys Root or the narrowest service that needs them Not web-readable Keeps database credentials and signing keys outside public paths
MySQL data and runtime files mysql:mysql where the MySQL installation requires it Apache/PHP: none Separates database storage from the web tier

Do not place credentials, private keys, or other secrets in a directory that Apache can serve. A file that is not linked by your application can still be requested directly if the web server can reach it.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Identify the real service account before changing anything

First determine which process is failing and which identity it uses. The account name in a tutorial may not match your host.

  1. Check the running processes:
    ps -eo user,group,comm,args | grep -E 'apache2|httpd|php-fpm'
  2. Inspect the service manager’s configured user and group. For a unit named httpd, for example:
    systemctl show httpd -p User -p Group

    Use apache2 or the PHP-FPM unit name when that is what your distribution provides.

  3. Read the distribution configuration for worker directives such as User, Group, user, or group. A PHP-FPM pool can run as a different account from Apache itself.
  4. Record the deployment account, web-service account, PHP-FPM account, and MySQL account before applying ownership changes. They are separate roles even when a small development machine happens to use the same group.

Deployment patterns that avoid world-writable code

Shared group with setgid directories

A deployment user and the web service can collaborate through a dedicated group. On an Amazon Linux-style layout, AWS documentation demonstrates group ownership and mode 2775 on /var/www, allowing the login user and Apache group to add, delete, and edit document-root content. The setgid bit (the leading 2) makes new files inherit the directory’s group.

Rank #3
Sale
LISEN Cell Phone Stand Phone Holder for Desk, Office Decor Gadgets for Men
  • Ergonomic & Adjustable Design: Fight "text neck" and improve your posture. Designed for comfort, it offers an adjustable height (7.1in-8.5in) (1.4in adjustable range) and angle (5°-85°) Please note: cell phone stand is only 9 inches tall—the length of a standard pencil
  • Without blocking subtitles Perfect for office desk Tiktok Face Time Zoom video—this is the ultimate kitchen desk essential for phones! Perfect viewing experience while reducing neck back strain, A must-have for gamers streamers desk, and anyone who values both style and support!
  • Sleek & Stable Design fits Otterbox Case: Say goodbye to bent cables, tangles, and tip-overs! LISEN’s stylish adjustable desk phone holder features a built-in charging hole and smart cable management, keeping your phone secure and your workspace clutter-free cool gadgets for men
  • ANTI-SLIP DESIGN free hands: The under 10.00 items easy gadgets back and the bottom of this kitchen essentials for women are fully covered by anti-skid silicone, which LISEN stand up desk decor can provide maximum protection device from any scratches and slides
  • Your Perfect Viewing Companion:If your product arrives damaged or breaks within 365 days, reach out to LISEN for a quick and hassle-free solution. Struggling with assembly, like tightening the screw? We’ve got your back! Your experience matters to us. (Product including: phone Holder stand*1, screw*1, hexagon screwdriver*1, specification*1)

That is a deployment pattern, not a universal production setting. If Apache only needs to read code, use a read-only group arrangement and give write permission to a small runtime directory instead of the entire document root.

ACLs for two named roles

When one directory must be writable by both a deployment account and the web service, a POSIX ACL can express that requirement without granting access to every member of a broad group. For example:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo setfacl -m u:deploy:rwx,u:www-data:rwx /var/www/site/storage
sudo setfacl -d -m u:deploy:rwx,u:www-data:rwx /var/www/site/storage

Replace deploy and www-data with the identities on your host. The default ACL affects new entries; inspect the result with getfacl. ACLs add an extra layer to audit, so document them and remove stale entries when a deployment account changes.

Read-only code with narrow writable exceptions

This is usually the safest production design: the release tree is owned by the deployment account and readable by the service group, while storage, cache, or public/uploads are the only writable paths. A compromised PHP request can then alter runtime data but cannot replace the application code that processes future requests.

Rank #4
Ledagic IC+RGBW USB Powered Led Light Bar with App & Remote Control, 2 Pack
  • Easy Installation: Our gaming lights have been designed to enhance your entertainment experience. Simply position the led light bar next to your TV or game console to create a game room environment with ease. They come with USB power and a 60 inch cord for direct mounting and mobility
  • Audio Syncing & Extensive Mode: The built-in high-sensitivity music sensor allows you to sync the TV led lights to your favorite music. Lights react and move to the beat of music, film and game audio, creating an incredible immersive sound and light experience – and all without the need for an additional hub. You can choose from 64+ patterns, including strobe, illusion, jump, energy, gradient, running, chasing, fluttering mode etc. Each mode can be applied to different scenes
  • 64+ Chasing IC+RGB & W Effect: The independent control design of IC+RGB and white all-in-one multifunctional rgbw led bar lights monitor backlight allows you to easily switch the led lights for desk between IC+RGB and white to enjoy a variety of lighting effects, you can choose white lighting mode with high brightness for better illumination when working, etc. Choose IC+RGB lighting mode when you need to create an entertaining atmosphere for the light show, 16 million colours of Color changing rgb light bar let you dance to the beat and create a dynamic party atmosphere
  • Dynamic and Dimmable Lights: 1%-full brightness free brightness adjustment gives you the flexibility to adjust dimmable led light bar for room decorations or a variety of occasions
  • USB Powered: USB light bars for room can be powered by powernank, usb charger, TV, Monitor, laptop PC mainframe, making behind TV led lighting bar easy to install in any location.TV led lights are powered by the TV usb interface / PC mainframe, can be turned on/off synchronously with TV / PC

Set ownership and modes step by step

Run these commands only after substituting your real project path and service group. Review each result; recursive changes are powerful and can affect unrelated files.

  1. Assign the release tree to the deployment identity and a controlled group:
    sudo chown -R deploy:webgroup /var/www/site
  2. Set conservative directory and file modes for code. The setgid bit shown here keeps the group on newly created entries; omit it if your workflow does not require group inheritance:
    sudo find /var/www/site -type d -exec chmod 2750 {} ;
    sudo find /var/www/site -type f -exec chmod 0640 {} ;
  3. Make the web-service account a member of the intended group, if that is your chosen design, then start a new service process so group membership is refreshed:
    sudo usermod -aG webgroup www-data
    sudo systemctl restart apache2

    Use the actual account and unit names on your distribution.

  4. Create only the runtime directories that need writes and assign their group explicitly:
    sudo install -d -o deploy -g webgroup -m 2770 /var/www/site/storage
    sudo install -d -o deploy -g webgroup -m 2770 /var/www/site/public/uploads
  5. Verify that files created by a test request inherit the expected owner, group, and mode. If the application creates files with excessive permissions, inspect its umask rather than compensating with a world-writable parent.

Some applications require the service account to own a runtime directory because they rename temporary files or maintain lock files there. Grant that ownership only to the specific directory, not to the entire application tree.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Diagnose a PHP “permission denied” error

Use a fixed sequence so you do not broaden permissions blindly.

  1. Identify the exact path. Copy the complete path from the PHP or web-server log. “Uploads failed” is not enough; the missing permission may be on a parent directory.
  2. Confirm the process identity. Check Apache and PHP-FPM separately. PHP-FPM pools can run under a different user from the HTTP worker.
  3. Walk every parent directory. On Linux, namei -l /var/www/site/storage/file.dat displays each component’s owner, group, and mode. The service account needs execute permission on every directory in the chain.
  4. Classify the operation. Reading an existing file needs file read plus directory traversal. Creating, deleting, or renaming needs write and execute on the containing directory. Modifying an existing file needs file write as well.
  5. Test as the service identity. A harmless read test such as
    sudo -u www-data test -r /var/www/site/config/app.php

    checks the real account. For a write test, use a temporary file in the intended runtime directory and remove it immediately.

  6. Inspect logs and mandatory access controls. Apache, PHP-FPM, and the kernel may report a denial even when Unix mode bits look correct. SELinux or AppArmor can block access independently of owner and group.
  7. Grant the narrowest fix. Correct the parent directory, group, ACL, or security policy that actually blocks the operation. Re-test, then remove any temporary broad permission.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

MySQL files have their own ownership rules

Oracle’s MySQL Secure Deployment Guide says most installation files can remain root-owned. Exceptions include the data directory, error log, mysql-files directory, PID file, and socket; these resources need access by the operating-system mysql user. MySQL also needs read access to its configuration files and binaries.

Best Value
Sale
HUANUO FlowLift™ Dual Monitor Stand, Fully Adjustable Gaming Monitor Desk Mount for 13–32″ Computer Screens, Full Motion VESA 75x75/100x100 with C-Clamp & Grommet Base, Each Arm Holds 4.4 to 19.8 lbs
  • Compatible with Wide Screens - To ensure compatibility with the dual monitor mount, your each monitor must meet three conditions at the same time: First, computer screens size range: 13 to 32 inches. Second, screen weight range: 4.4 to 19.8 lbs. Third, the back of the monitor screen must have VESA mounting holes with a pitch of 75x75mm or 100x100mm.
  • Regarding the compatibility with desks - Your desk must meet three conditions at the same time: First, desk material: Only wooden desks are recommended, plastic or glass desks cannot be used. Second, desk thickness range: 0.59" - 3.54". Third, the bottom of the desk should not have any cross beams or panels, as this will interfere with installation. We recommend carefully checking that your desk and monitors meets all above conditions before purchasing.
  • Dual C-Clamp Hold - Worried your dual monitors might wobble or slip? Our upgraded base uses a larger platform plus a dual C-clamp structure to lock the dual monitor arm firmly to your desk. Each arm safely keeps your screens steady while you type, click and game—no shaking, no sliding, just a clean and secure setup you can trust every day. It also provides Grommet Mounting installation choice, both options ensure stable and secure fixation for your 0.59" - 3.54" desk.
  • Full-Motion Adjustment For Comfortable View - Pull the screen closer when you’re deep in a spreadsheet, push it back to watch videos, or rotate to portrait for coding — moving everything smoothly with just one hand. The monitor stand offers +85°/-50° tilt, ±90° swivel and 360° rotation. Raise your monitor up to 15.75″ to support a healthy sitting posture. Whether you’re working from home, gaming through the night, or switching between video calls and documents, getting the screens to your natural line of sight helps relieve neck, shoulder and back strain so you can stay focused longer with less fatigue.
  • Keep Your Desk Organized: By lifting both screens off the desktop, this dual monitor stand opens up valuable space for your keyboard, notebook, docking station or a simple, clutter-free work area. Built-in cable management guides wires along the arms, keeping cords out of sight and out of the way. Enjoy a tidy, modern workstation that looks as good as it feels to use.

The MySQL Reference Manual documents default UMASK=0640 and UMASK_DIR=0750; database directories are created with 0750 by default. These defaults limit access to the MySQL account and its group. If a table or file operation reports an operating-system permission error, inspect the effective umask, the directory’s traversal bits, ownership, the systemd unit, and any SELinux or AppArmor rule before changing modes.

Never run a blanket command such as chown -R www-data /var/lib/mysql. It can prevent MySQL from starting, expose database contents to the web process, and destroy the separation between application and database roles. Use the package’s documented paths and service account, and stop MySQL before any maintenance that genuinely requires changing its data files.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

SELinux and AppArmor can override mode bits

Mandatory access-control systems add policy labels or profiles on top of Unix ownership. On an SELinux-enabled host, a directory can be mode-readable yet denied because its context is not permitted for web content. AppArmor can similarly restrict which paths a profile may read or write. Look for denial records in the system journal or security logs and use the distribution’s policy tools to assign the correct context or profile rule. Disabling SELinux or AppArmor, or switching to an unrestricted profile, hides the problem rather than fixing it.

Common mistakes and safe recovery

chmod -R 777

This grants read, write, and execute to owner, group, and everyone else. Any local account or compromised service can alter code, inject files, or delete data. Replace it with explicit directory and file modes and a narrowly writable runtime path.

Making Apache the owner of the whole project

It may make uploads work, but it also allows a web request to overwrite templates, configuration, and executable code. Restore deployment ownership, then grant the service account only the access required for runtime directories.

Fixing the file instead of its parent directory

If PHP creates or deletes entries, changing the target file’s mode cannot help when the containing directory lacks write and execute. Inspect the full path with namei -l.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leaving temporary permissions behind

Record the original owner, group, mode, and ACL before troubleshooting. After the test, remove temporary grants, restart the affected service if its groups changed, and confirm that secrets and database paths remain unreachable from the web account.

Compare common ownership layouts

Layout Release owner Apache/PHP writes Collaboration mechanism Best fit
Read-only release tree Deployment account Only uploads, cache, sessions, and generated output Service group or ACL on runtime directories Most production applications
Shared web-root group Deployment account and group Broad document-root write access Group ownership with setgid, such as mode 2775 Controlled hosting or deployment workflows that require edits in the document root
Web account owns project Apache/PHP account Nearly everything Ownership itself Generally avoid; weak separation and poor release accountability
ACL-based runtime access Deployment account Named runtime directories Access and default ACL entries for deployment and web identities Systems where a shared group would be too broad

Operational checklist

  • Confirm the actual Apache and PHP-FPM identities on this distribution.
  • Keep application code and configuration deployment-owned and read-only to the web process.
  • Grant write and execute on only the directories that create, delete, rename, or generate files.
  • Keep secrets outside web-readable paths.
  • Keep MySQL data and runtime resources under the documented mysql identity.
  • Use namei -l, service logs, and a service-identity test before changing modes.
  • Check SELinux or AppArmor when Unix permissions appear correct.
  • Remove temporary broad permissions immediately after troubleshooting.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.