In this article, we’ll show you how to disable the PHP error reporting.
PHP errors are generated by your websites and logged in error_log files in the directory where your PHP files are located. If you do not need the error_log file you can disable PHP error logging.
To turn off PHP error reporting, you need to add the following line to your .htaccess file to suppress any PHP error messages.
php_flag display_errors off
Quick Steps:
Go to your cPanel account and select File Manager.
Click on Settings, check the box Show hidden files and click Save.
Open the .htaccess file and add the code “php_flag display_errors off”.
Click on Save Changes to save and close the file.
Login into your cPanel account and open File Manager from the Files section.
cPanel home page.
Click on Settings in File Manager.
Settings in File Manager.
Tick the check box “Show hidden files” and click Save.
Settings in File Manager
Select your .htaccess file and click on the Edit option from the dashboard above.
Editing the .htaccess file.
Add the code “php_flag display_errors off” and click Save Changes.
Conclusion
Congrats! Now, you’ve successfully turned off the PHP error reporting using the .htaccess file.
LEMP stack is a group of open source software that is installed on a server so that we can host dynamic web applications and sites. LEMP stack is an another variation of the LAMP stack. LEMP is an acronym which consists of Linux as the operating system, NGINX as the web server, MySQL/MariaDB as the relational database management system and PHP as the server-side scripting language.
Log in as a sudo user and then update your system using the following command,
yum update -y
Step 2: Installing NGINX
Nginx is not available on the default CentOS 7 repositories, so add the Extra Packages for Enterprise Linux (EPEL) repository by executing the command below.
yum install epel-release -y
Now that the (EPEL) repository repository is installed on your server, let’s install the NGINX Web Server using the command below.
yum install nginx -y
After the installation, start and enable NGINX.
systemctl start nginxsystemctl enable nginx
Configure the system firewall for NGINX to allow 80 and 443 inbound to the server.
To verify if NGINX is running, visit your IP address via the browser.
http://server_domain_name_or_IP/
You should see the default NGINX page as shown below.
Step 3: Installing MariaDB
MariaDB – a drop in replacement of MySQL, is the default database management system in CentOS 7. It is a community-developed fork of the MySQL relational database management system.
MariaDB comes with default CentOS repositories, thus run the following command to install it.
yum install mariadb-server mariadb -y
After the installation is complete, start and enable the service.
systemctl start maridbsystemctl enable mariadb
Run the following command to prevent all unauthorized accesses and remove some dangerous defaults in your database configuration.
mysql_secure_installation
You will be prompted with an option to change the MariaDB root password, remove anonymous user accounts, disable root logins outside of localhost, remove test databases and reload privileges. It is recommended that you answer ‘yes’ to these options to secure the database server.
Step 4: Installing PHP
PHP is a widely used scripting language suited for web development. By default PHP 5.4 is available in the CentOS 7 Yum repositories. It is now outdated and no longer supported. We recommend that you install the latest stable version of PHP 7.x as it has many improvements and new features.
To install the latest PHP version we need to add REMI repository. Lets start by installing the package “yum-utils” for configuring yum repositories and install the REMI repository.
Configure the repository for installing PHP 7.3 (or the latest stable version) using the following command. If there is a later version then simply modify the command by changing the version numbers in the command to match the release you wish to install.
yum-config-manager --enable remi-php73
We can now install PHP 7.3 along with its common dependencies with the command below,
yum install php php-mysql php-fpm -y
Check the PHP version with the command below,
php -v
The output should look similar to what show below,
PHP 7.3.2 (cli) (built: Feb 5 2019 13:10:03) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.2, Copyright (c) 1998-2018 Zend Technologies
By default PHP-FPM is configured to user “apache” on port 9000. W’ll need to change the user to nginx.
To do so edit the PHP-FPM configuration file at “/etc/php-fpm.d/www.conf” to what’s shown below.
...
user = nginx
...
group = nginx
...
listen = /run/php-fpm/www.sock
...
listen.owner = nginx
listen.group = nginx
Save the file and change the ownership of the directory “/var/lib/php” from “apache” to “nginx”.
chown -R root:nginx /var/lib/php
Start and enable PHP-FPM.
systemctl start php-fpm
systemctl enable php-fpm
Step 5: Configuring Nginx to Process PHP Pages
Create a new NGINX configuration file with the following command.
vim /etc/nginx/conf.d/default.conf
Paste the syntax below on to the newly created configuration file.
server {
listen 80;
server_name your_server_ip;
# note that these lines are originally from the "location /" block
root /usr/share/nginx/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Note: Replace “your_server_ip” with your actual server IP.
Save the file and restart NGINX for the changes to take effect.
systemctl restart nginx
Conclusion
Now that you have successfully installed LEMP stack, you are now ready to host any type of dynamic website/software applications.
OpenLiteSpeed is a free, open source and lightweight web server from LiteSpeed. In this guide, we will demonstrate how to install OpenLiteSpeed, and then configure PHP version PHP 7.x.
Prerequisites
A CentOS 7 VPS
Sudo access
System Update
Log in as a sudo user and the update your system,
yum update -y
Add the OpenLiteSpeed Repository
Add the OpenLitespeed Repository to install the latest version of OpenLiteSpeed.
Install the latest version of OpenLiteSpeed using the command below.
yum install openlitespeed
Start OpenLiteSpeed using the command below.
/usr/local/lsws/bin/lswsctrl start
Note: To stop it, run /usr/local/lsws/bin/lswsctrl stop.
Install PHP
OpenLiteSpeed uses LSPHP 5 by default which has reached its end of service life. We recommend that you install the latest stable version of LSPHP 7.x (at least 7.1 currently as 7.0 is EoL) as it has many improvements and new features.
To install the latest PHP version we need to add EPEL repository from which we can install PHP 7 with the following command.
yum install epel-release
Install PHP 7 and its MySQL extension with the command below,
yum install lsphp70 lsphp70-mysqlnd
Configure OpenLiteSpeed
OpenLiteSpeed has a WebAdmin console which is accessed through port 7080. Start by configuring the username and password for the WebAdmin console.
/usr/local/lsws/admin/misc/admpass.sh
Pick a username for the administrative account, or press Enter to accept the default value for the username which is “admin”.
Next, you need to provide and verify a password for the Admin user. When choosing a password, choose a strong password as the WebAdmin console is open to the internet.
Please specify the user name of administrator.
This is the user name required to login the administration Web interface.
User name [admin]:
Please specify the administrator's password.
This is the password required to login the administration Web interface.
Password:
Retype password:
Administrator's username/password is updated successfully!
Update the firewall rules to allow the port 7080 to access the WebAdmin console.
Open your web browser and type the following URL to access WebAdmin console.
http://SERVER_IP:7080
OR
http://localhost:7080
Enter the username and password that you’ve set and login.
OpenLIteSpeed WebAdmin Login Page
Note: OpenLiteSpeed uses LSPHP 5 by default, we need to make few changes to setup LSPHP 70.
Login to the WebAdmin console and go to Server Configuration >> External App . There, you will find an external application named “lsphp5”. Click the Edit icon on the right hand side in order to edit this application as follows:
Click on the Save button to save the configurations.
Setup Script Handlers
Script handlers specifies OpenLiteSpeed which scripts should go to which external application. To setup a script handler we need to set OpenLiteSpeed to serve all .php scripts with the lsphp70 external application.
Click the Script Handler tab, and then use the Edit icon to update the script handler as follows:
The default port of OpenLiteSpeed is 8080, we need to change it to 80.
To do so, Click on Listener > Default, click the Edit icon on the right hand side, and then modify the settings as shown below:
Listener Name: Default
IP Address: ANY
Port: 80
To save these changes, gracefully restart OpenLiteSpeed by clicking the Graceful Restart icon at the top right corner.
OpenLiteSpeed WebAdmin Interface
Click Yes to restart OpenLiteSpeed.
Conclusion
Congrats, OpenLiteSpeed has been successfully installed on your system. For additional information, refer to the OpenLiteSpeed Homepage: https://open.litespeedtech.com/mediawiki/
LAMP is a set of open source software packages that is used to create websites and web applications. LAMP is an acronym. It consists of Linux as the operating system, Apache as the Web server, MySQL/MariaDB as the relational database management system and PHP as the server-side scripting language. In this document, we will go through the steps necessary for installing the LAMP stack on a CentOS 7 server.
All you require for these operations is a VPS with CentOS 7 installed on it and root/root privileged user access to the server.
Check whether Apache is running by calling your IP/hostname in the browser. If Apache is running the default CentOS 7 Apache web page will be displayed.
Apache Test Page on CentOS 7 Server
Step 3: Install MariaDB Database
MariaDB is a drop-in replacement for MySQL. It is a reliable SQL server that comes with a rich set of enhancements and features. For dynamic websites, it is always necessary to store data. We can install MariaDB together with additional packages that are required by running the commands below:
sudo yum install mariadb-server mariadb -y
Now that the MariaDB has installed successfully, run the command below to start and enable the service.
To prevent unauthorized access to your database and remove some dangerous defaults run the following command.
sudo mysql_secure_installation
You will be prompted with an option to change the MariaDB root password, remove anonymous user accounts, disable root logins outside of localhost, remove test databases and reload privileges. It is recommended that you answer ‘yes’ to these options to secure the database server.
Step 4: Install PHP
PHP is a widely used scripting language suited for web development. It works with Apache to display the dynamic content for your website. By default, PHP 5.4 is available in the CentOS 7 Yum repositories. We recommend that you install the latest stable version of PHP 7.x as it has many improvements and new features.
To install the latest PHP version we need to add EPEL and REMI repositories. Let’s start by installing the package “yum-utils” for configuring yum repositories and enabling the EPEL repository.
Configure the repository for installing PHP 7.3 (or the latest stable version) using the following command. If there is a later version then simply modify the command by changing the version numbers in the command to match the release you wish to install.
yum-config-manager --enable remi-php73
We can now install PHP 7.3 along with its SQL dependency using the command below.
yum install php php-mysql -y
After installing PHP, restart the Apache service.
sudo systemctl restart httpd
Conclusion
That’s it. You’ve successfully installed the LAMP platform on your CentOS 7 system which can now run dynamic website and software applications. Depending on your web hosting needs, you might also need to install additional Apache modules and PHP extensions.
We highly recommend checking out OpenLiteSpeed web server as an open-source drop-in replacement for Apache. There can be significant speed increases by running OpenLiteSpeed. We have an article on how to install OpenLiteSpeed to help guide you.