php programming

HTTP 301 Redirect using PHP

You can use PHP header() function to do redirect.

To do 301 redirect, use

For 302 redirect, use

If you need to redirect a site to new site keeping same URL structure, you can use

CloudLinux PHP Selector on Cpanel Server

CloudLinux come with PHP Selector, this allow you to select differnt PHP versions. When you enable PHP selector, you should do the following.

Related Posts

Enable CloudLinux PHP lsapi
CloudLinux

CentOS 7 VestaCP Upgrade PHP to 7.x

On CentOS 7 VestaCP install PHP 5.6 by default. This is very old version of PHP. To upgrade PHP to latest version 7.x, you can install remi repo.

Install EPEL repo

Install yum-utils

Install remi repo

Select PHP version you need

Here i selected PHP 7.3. You can select differnt PHP versions with commands like.

Make sure you only enable one PHP version. If you enabled a PHP version from remi repo, disable it with

Once you have desired version enabled, run yum upgrade

Or only for PHP, run

PHP Script to monitor Apache/php-fpm

I moved a web site to new dedicated server. But for some reason, php-fpm crashed. I increased the max_children settings, but it happend again. I do not want down time while i am investigating the problem. So i created a PHP script, that will check if site is working or not.

Script have 2 part.

health-check.php

It is simple PHP script, that get a param and print it.

This file is placed on root of your web site, so it can be accessed using URL http://yoursite/health-check.php

monitor-server.php

Create

Add following content

On the script, replace YOUR_DOMAIN_HERE with your actual domain name.

systemctl restart apache2 is for restart apache web server. If you use nginx, replace it. systemctl restart php7.2-fpm restart php-fpm, if you have differnt version of php, you need to change it.

The script is generate a random number, pass it to health-check.php script. Compared the value returned with generated random number to make sure the value is correct. If web server or php-fpm fail, this check will fail.

Now set a cronjob

Add

Related Posts

Server Monitoring

Install PHP 7.3 in CentOS 8

CentOS 8 comes with PHP 7.2. To install PHP 7.3, you need to enable remi repo. You can download remi-release rpm file from

http://rpms.remirepo.net

Download and install remi-release rpm

if you have older php version and don’t want to keep it, uninstall it with

Install PHP 7.3

Set it as default PHP version

Install PHP modules

Install php-fpm package

set php-fpm to start on boot

Start php-fpm

Restart Apache

PHP 7.3 php.ini located at

Module directory for PHP 7.3 at

Related Posts

CentOS 8

PHP

Redirect a site to HTTPS using PHP

This PHP script will redirect web site visitor to HTTPS (SSL) url. You can add this in your index.php of the web site

Move a site to new URL using PHP

You can also use Apache mod_rewrite .htacess to do the redirection.

Large file upload in PHP

To allow large file upload in PHP, you need to edit php.ini file and change fllowing settings

If you have Dedicated or VPS, you can edit php.ini file using ssh. To find location of this file, upload a phpinfo page to your server, that will display location of php.ini used by your web site.

Some control panel like CPanel have option to edit php.ini settings.