基于Plesk的PHP版本迁移、Laravel部署及SSH访问问题咨询
Hey there, let's break down each of your issues one by one and get you sorted out:
1. PHP 5 → PHP 7+ 迁移报错修复
Migrating from PHP 5 to 7+ often hits compatibility issues due to deprecated functions, stricter type checks, and changed behaviors. Here are the most common fixes to tackle your errors:
- Replace deprecated functions:
- Ditch
mysql_*functions (removed in PHP7) and switch tomysqli_*or PDO for database connections. - Replace
ereg()/eregi()withpreg_match()(PCRE regex functions are now standard). - If you used
$HTTP_RAW_POST_DATA, replace it withfile_get_contents('php://input')(the former was removed in PHP7.0).
- Ditch
- Adjust for stricter type handling:
- PHP7+ enforces stricter type declarations for function parameters and return values. If you see "TypeError" messages, either update your code to match the expected types, or add
declare(strict_types=0)at the top of your scripts to loosen type checks (not recommended long-term, but useful for quick fixes).
- PHP7+ enforces stricter type declarations for function parameters and return values. If you see "TypeError" messages, either update your code to match the expected types, or add
- Fix variable and loop behavior changes:
foreachno longer modifies the original array when using value iteration (unless you explicitly use references).isset()now returnsfalsefor uninitialized array elements withnullvalues, which might break old conditional checks.
- Update error handling:
- PHP7+ uses the
Throwableinterface to catch both exceptions and fatal errors. Wrap risky code intry-catchblocks that catchThrowableinstead of justExceptionto handle more cases.
- PHP7+ uses the
For your specific errors, check the web server logs in Plesk (under Logs > Web Server Logs) — they'll give you exact line numbers and error messages to target. The screenshots you shared:
:Confirm that the subdomain is configured to use your target PHP 7+ version here (look for the PHP settings section in this dashboard).
:This generic error usually points to a PHP fatal error or misconfigured document root. The server logs will reveal the root cause.
2. Deploying Laravel on Plesk (Yes, It's Possible!)
Plesk's "no official support" note just means there's no one-click installer — you can absolutely deploy Laravel manually, and it's a common setup. Here's how:
- Check server requirements: Ensure your Plesk server has PHP 7.4+ (Laravel 9+ requires 8.0+), plus these extensions: BCMath, Ctype, JSON, Mbstring, OpenSSL, PDO, Tokenizer, XML. Enable them via Plesk's PHP settings.
- Configure your domain/subdomain:
- Create the domain in Plesk, then set the Document Root to the
publicfolder of your Laravel project (critical to protect sensitive files like.env).
- Create the domain in Plesk, then set the Document Root to the
- Upload your code:
- Use FTP, or (once SSH is fixed) git clone your Laravel repo directly to the server.
- Set permissions:
- Make sure the
storageandbootstrap/cachedirectories have write permissions (usually755or777, depending on your server's user/group setup). You can adjust this via Plesk's File Manager or command line.
- Make sure the
- Configure environment:
- Copy
.env.exampleto.env, fill in your database credentials, APP_URL, and other settings. - Generate an app key with
php artisan key:generate(run this via Plesk's built-in Terminal or SSH).
- Copy
- Set up rewrite rules:
- Go to Apache & nginx Settings for your domain, add this to the "Additional nginx directives" section:
location / { try_files $uri $uri/ /index.php?$query_string; }
- Go to Apache & nginx Settings for your domain, add this to the "Additional nginx directives" section:
3. Fixing PuTTY SSH Timeouts & Hidden Input
Let's troubleshoot the SSH access issue step by step:
- Check network and firewall rules:
- Verify your server's firewall (and cloud provider's security group, if applicable) allows inbound traffic on port 22 (default SSH port). Test connectivity with
telnet your-server-ip 22from your local machine — if it fails, the port is blocked.
- Verify your server's firewall (and cloud provider's security group, if applicable) allows inbound traffic on port 22 (default SSH port). Test connectivity with
- Adjust PuTTY settings:
- In the PuTTY Session window, go to Terminal > Local Echo and select "Force on" — this will make your input visible.
- Go to Connection > Seconds between keepalives and set it to 30 — this sends periodic packets to prevent the connection from timing out.
- Check server SSH configuration:
- If you can access the server via Plesk's built-in Terminal (under Tools & Settings > Terminal), edit
/etc/ssh/sshd_config:- Ensure
PermitRootLoginis set toyes(orprohibit-passwordif you use key-based auth). - Make sure
PasswordAuthenticationis set toyesif you're logging in with a password. - Restart the SSH service with
systemctl restart sshd.
- Ensure
- If you can access the server via Plesk's built-in Terminal (under Tools & Settings > Terminal), edit
- Update PuTTY: If you're using an old version, download the latest release — outdated clients can cause compatibility issues.
内容的提问来源于stack exchange,提问作者imrab19

