Linux & Php : server with MySQL database with terminal - php

Hello I'm new in Linux and sorry if this subject already exist,
I know that with php and Linux you can start a local server with the commande
php -S 127.0.0.1:8080
I just wanted to know if we can work with a local database in this way with Linux
PS: I don't want to install Xampp

Sure, you can install an local MySQL Server. If you are running Ubuntu/Debian here we go:
Install MySQL and PHP Modules
sudo apt-get install mysql-server php5-mysql
Finish Setup with:
sudo /usr/bin/mysql_secure_installation
Thats it!

Related

Why does my website loads infinitely after I tried the sleep method?

So I was playing with the sleep method of php. I coded sleep(99999); Now my website won't load lol. Is it because of that? How can I fix it?
I think you can just restart apache, or php-fpm if you are using php-fpm. And why in the world would you try that!
You must restart your server if restarting your web server didn't work. Or, it will just be stuck in a delay until the sleep time ends.
I would advise you not to play with a production server. Use a test server for these tests. Because it is not as easy to reset these issues.
For example, when you are using shared hosting, you cannot restart apache yourself.
How do I setup a test server:
Install some software like XAMPP if you are using Windows in your home PC. Or, if you are using Linux, you can just install apache and php using the following commands on:
Ubuntu/Debian: sudo apt install apache2 php
CentOS/Fedora: sudo yum install epel-release, and sudo yum install httpd php or sudo dnf install httpd php
Arch Linux/Manjaro: sudo pacman -S apache php php-apache

PHP Cron.Hourly needs mysql driver

I want to run an hourly php script that updates my mysql server. I put the scripts into a folder /etc/cron.hourly. But I am getting an error.
#!/usr/bin/php
<?php
$connection=new pdo('mysql:host=HOST;dbname=DATABASE','ROOT','PASS');
$prepare=$connection->prepare('update TABLE set COLUMN=COLUMN+?');
$prepare->execute([1]);
?>
I keep getting this error.
How do I get the mysql part of the php to work as well? Is there a directory to connect mysql driver to the file as well?
You will need to check so that the driver is installed. This can be done by check the output of phpInfo() or using php cli:
phpInfo();
or:
php -m
If not installed then simply install it and restart apache:
sudo apt-get update
sudo apt-get install php5-mysql
sudo service apache2 restart

MySQL ERROR 1045 (28000)

Recently i installed LAMP on Linux Mint. I successfully installed it and now just run this commands on terminal for checking the version :
apache2 -v
php -v
mysql -v
This is the result :
I dont have any problem with localhost because now i'm running phpinfo() function correctly and localhost (apache and php) is ok. but for database is that :
in orther to instal phpmyadmin you need to install mysql before cotinunig
so it said that MySQL is needed. as you see i had installed mySQL before and now i have problem with checking the version.
im trying to config phpmyadmin but here is:
so i think this is the cause of mySQL.
what is the problem ?
As the mysql extension is not part of a default PHP7 installation anymore (http://php.net/manual/de/mysql.php), you need to install it with
sudo apt-get install php-mysql
This should install and activate the mysql drivers. You will have to restart apache afterwards by
sudo service apache2 restart
If you have already the mysql package installed, check the php.ini under /etc/php/7.1/apache2/php.ini for the line
extension=mysql.so
Maybe phpmyadmin works with mysqli (extension=mysqli.so) too.
To install php7 and php5 in parallel, check out this guide:
http://lornajane.net/posts/2016/php-7-0-and-5-6-on-ubuntu
I have already solved this problem by searching for a long time.
Everytime for the first time you use mysql after you turn on the computer,you should execute the following sentence:
net start mysql80
80 is mysql's version.
Remember:you should run the cmd with administrator privileges
Best wishes!

Phpmyadmin-error on nginx VPS with Ubuntu 12.04.3 x32

I am trying to install phpmyadmin on a VPS LEMP-stack.
I created an info.php, which is perfectly reachable when I call my server's IP in my browser, revealing all relevant php-info, i.e. nginx is running.
However, after installing phpmyadmin, which I try to access via http://192.xxx.xxx.x/phpmyadmin/, I get the following error message:
The mysqli extension is missing. Please check your PHP configuration.
I already installed php5-mysql via sudo apt-get install php5-mysql, restarted nginx and cleared my browser-cache, but the situation remains.
Could you please advice me what goes wrong?
mysql and mysqli are two different things.
You have to install the mysqli library:
sudo apt-get install php5-mysqli
Don't forget to also restart the php fpm workers, because that's where the mods get loaded, not in nginx.
/etc/init.d/php5-fpm restart
Update:
I was wrong, the php5-mysql package contains the mysql AND the mysqli library.
It must be enough for you to restart the php workers :-)

How can I run things off Netbeans on Ubuntu? Localhost not working

When I try to run something on Netbeans using Ubuntu, a window opens but nothing actually works. I'm pretty sure it's because my http://localhost/ isn't working. So, how do I get that to work so I run files on Netbeans? Any specific step-by-step instructions would be great. I heard I had to install Apache, but I'm not sure.
If you want to run PHP stuff outside NetBeans, there are several steps you have to take:
Install apache web server - sudo apt-get install apache2
Install PHP and connect it with apache - sudo apt-get install php5 sudo apt-get install libapache2-mod-php5
Restart apache - sudo /etc/init.d/apache2 restart
Now, your Document Root (web root) should be at /var/www.
Place your files there and access them with http://localhost/desired_file.php with some web browser or just execute them with php compiler on the command line.
Depending on your distro/version, there might be some configurations to be done, but that's the basic stuff you need to run PHP outside NetBeans

Categories